#include <ncbi.h>
#include "blastapp.h"
#include "gcode.h"

long
nox_coord(seqlen, frame, off, adjust)
	unsigned long	seqlen;
	int		frame;
	unsigned long	off;
	long	adjust;
{
	return (long)(off + 1 + adjust);
}

long
nt_coord(seqlen, frame, off, adjust)
	unsigned long	seqlen;
	int		frame;
	unsigned long	off;
	long	adjust;
{
	if (frame >= 0)
		return (long)(off + 1 + adjust);
	return (long)(seqlen - off);
}


/*
    apo_to_nt1
 
    Convert an amino acid sequence pointer offset to the nucleotide _number_
    (not offset) of the first nucleotide in the codon.
*/
long
apo_to_nt1(seqlen, frame, off, adjust)
	unsigned long	seqlen; /* length of nucleotide sequence */
	int		frame; /* reading frame of translation, +1,+2,+3,-1,-2,-3 */
	unsigned long	off; /* a.a. offset from start of a.a. sequence buffer */
	long	adjust;
{
	if (frame > 0)
		return (long)(off*CODON_LEN + frame + adjust);
 
	return (long)(seqlen - off*CODON_LEN + frame + 1);
}
 
/*
	apo_to_nt3
 
	Convert an amino acid sequence pointer offset to the nucleotide _number_
	(not offset) of the third nucleotide in the codon.
*/
long
apo_to_nt3(seqlen, frame, off, adjust)
	unsigned long	seqlen;	/* length of nucleotide sequence */
	int		frame;	/* reading frame of translation, +1,+2,+3,-1,-2,-3 */
	unsigned long	off; /* a.a. offset from start of a.a. sequence buffer */
	long	adjust;
{
	if (frame > 0)
		return (long)(off*CODON_LEN + frame + 2 + adjust);
	return (long)(seqlen - off*CODON_LEN + frame - 1);
}
