/*  Last edited: Aug 15 17:39 1995 (rmott) */
#define PRIME_NUM 10007
#define MAX_BUF 10000
#define SEQPATH "SEQ_DATA_HOME"

#ifndef _SEQ_UTIL_H_
#define _SEQ_UTIL_H_

#define real float

typedef enum 
{ EMBL, NBRF, FASTA, SINGLE  } 
WHAT_KIND_OF_DATABASE;

#define FASTA_BUFLEN 10000

typedef struct
{
  float key;
  int value;
}
KEYVALUE;

typedef struct hash_list
{
  char *name;
  unsigned long offset, text_offset;
  struct hash_list *next;
}
HASH_LIST;

typedef struct
{
  char *database;
  WHAT_KIND_OF_DATABASE type;
  int sequences;
  unsigned long length;
  FILE *datafile;
  FILE *textfile;
  FILE *indexfile;
  HASH_LIST **index;
}
DATABASE;


typedef struct
{
  char *name;
  DATABASE *database;
  char *desc;
  int len;
  char *s;
}
SEQUENCE;

typedef struct sequence_index {
  int start[256];
  int *offset;
}
SEQUENCE_INDEX;

SEQUENCE *ReadSequence(), *Read_Sq(), *Read_Seq();
SEQUENCE *Read_embl_Sq(), *Read_nbrf_Sq(), *Read_fasta_Sq();
SEQUENCE *nextSeqFrom_list_file(), *NextSeq_from_database_spec();
SEQUENCE *NextSeq();
SEQUENCE *GetSeqFrom_file();
SEQUENCE *SeqDup();
SEQUENCE *GetFastaSeq( FILE *fp );
SEQUENCE ** GetFastaSeqs( FILE *fp, int *nseqs );
SEQUENCE *SkipFastaSeq( FILE *fp, int skip );
SEQUENCE *ShuffleSeq( SEQUENCE *seq, int in_place, int *seed );

char *ShuffleS( char *s, int *seed );

DATABASE *OpenDatabase(), *WhichDatabase(), *IsSequenceSpec();
DATABASE *OpenEmblDatabase(), *OpenNbrfDatabase(), *OpenFastaDatabase();

FILE *WhichFileOfSequences();

unsigned long GetOffset(), SeekTo(), FindNext();
char *DownDase(), *UpCase(), *ComplementSeq(char *s), *CleanLine();
char *SeqComment(), *EmblSeqComment(), *NbrfSeqComment(), *fasta_SeqComment();
SEQUENCE *ReverseSeq( SEQUENCE *dna );

char *IubToRegexp();
char *Iub2Regexp();
char *IubRegexp( char c);


int WriteFastaSq( SEQUENCE *seq, FILE *fp );


FILE *OpenFileInSeqPath();
FILE *OpenFileInSeqPathArg();

SEQUENCE *IntoSequence( char *name, char *desc, char *s );
SEQUENCE *SubSeq( SEQUENCE *seq, int start, int stop );
void FreeSeq( SEQUENCE *seq );

void MakeEmblIndex( DATABASE *db );
void MakeFastaIndex( DATABASE *db );
void MakeNbrfIndex( DATABASE *db );


double *ReadFreqTable( FILE *fp );
double *ModelResidueFrequencies( char *model );
double *GemResidueFrequencies (void );
double *RobinsonResidueFrequencies (void);
double *AltschulResidueFrequencies (void);
double *DayhoffResidueFrequencies (void);
double * ResidueFrequencies( SEQUENCE *seq );
double * PseudoResidueFrequencies( SEQUENCE *seq, int len );
void FreeSequenceIndex( SEQUENCE_INDEX *seqin );
SEQUENCE_INDEX *createSequenceIndex( SEQUENCE *seq );


int ** ReadBlastMatrix( char *name );
int **CopyMatrix( int **old_matrix );
int **AdjustMatrix( int **matrix, int **new, double lambda, double *freq1, double *freq2, double *freq0, int scale);

double AffineSwScore( SEQUENCE *seq1, SEQUENCE *seq2, int **matrix, double gap_start, double gap_extend );

double AffineSwGreedyCheck( SEQUENCE *seq1, SEQUENCE *seq2, int **matrix, double gap_start, double gap_extend, int align, int *starts, int *gaps, int *len );


SEQUENCE *RandomSeq( SEQUENCE *seq, double *cum, int *seed );

void PrintThisAlignment( char *name1, char *align1, char *name2, char *align2, char *align0, int start1, int start2 );
void InvertS(  char *seq );
int BandedIdentity( SEQUENCE *seq1, SEQUENCE *seq2 );

int IsNucleotide( char c );

void InterlaceInit(void) ;
void Codon( char *Codon, char trans );
void InterlaceDNA( SEQUENCE *dna, char *is );
int NextORF( SEQUENCE *seq, int pos );
void PrintORFs( char *prefix, SEQUENCE *seq, int minlength, double *pvalue );
int CumORFs ( SEQUENCE *seq, double *histogram );

int KvCmp( const void *A, const void *B );

SEQUENCE *NewSeq( int len, char *name );

#endif

