third_party_software/hmmer-3.0-linux-intel-x86_64/easel/esl_sq.c
/* Function:  esl_sq_GuessAlphabet()
 * Synopsis:  Guess alphabet type of a single sequence.
 * Incept:    SRE, Wed May 16 11:03:44 2007 [Janelia]
 *
 * Purpose:   Guess the alphabet type of biosequence <sq>, and store the
 *            guess in <*ret_type>.
 *            
 *            All 26 letters are valid in the amino alphabet (even <O>
 *            and <J> now), so the DNA alphabet is necessarily a subset.
 *            Therefore most protein sequences can be identified
 *            unambiguously (because they use letters that only occur
 *            in amino acid sequence), but DNA sequences cannot be.
 *            
 *            The sequence must contain more than 10 residues, or it
 *            is called <eslUNKNOWN>.
 *            
 *            Specifically, this routine calls the sequence <eslDNA>
 *            if it consists only of the residues <ACGTN> and all four
 *            of <ACGT> occur. (And analogously for <eslRNA>,
 *            <ACGUN>.)  It calls the sequence <eslAMINO> either if it
 *            contains an amino-specific letter (<EFIJLOPQZ>), or if
 *            it contains at least 15 of the 20 canonical amino acids
 *            and consists only of canonical amino acids or <X>.

 *            Thus DNA sequences containing IUPAC degeneracies other
 *            than N are called <eslUNKNOWN>, rather than hazarding a
 *            guess. It may be possible to improve on this in the
 *            future by using residue occurrence frequencies.
 *            
 *            Note that a sequence of <ATATATA...> will be called
 *            <eslUNKNOWN>, whereas a sequence <ACGTACGTACGT...>
 *            (which could conceivably be "ala-cys-gly-thr...") will
 *            be called <eslDNA>. Peptides of simple mono and di-amino
 *            acid compositions do occur, but I have not (yet) seen a
 *            peptide consisting only of all four residues <ACGT>.
 *            
 *            The routine is designed to be conservative, calling
 *            <eslUNKNOWN> rather than making errors. In a test on the
 *            Oct 2006 version of the NCBI nonredundant databases,
 *            this routine called 0 <eslDNA> and 5694 <eslUNKNOWN> on
 *            4.0M protein sequences (99.9\% classification with no
 *            false positives) and 0 <eslAMINO> and 155756
 *            <eslUNKNOWN> in 4.4M DNA sequences (96\% classification
 *            with no false positives). (Well, actually, one DNA call
 *            was made in the protein database, but this was an
 *            exception that proves the rule; that entry was indeed a
 *            DNA contaminant. It has since been removed by NCBI.)
 *
 * Returns:   <eslOK> on success, and <*ret_type> is set to
 *            <eslAMINO>, <eslRNA>, or <eslDNA>.
 *
 *            Returns <eslEAMBIGUOUS> if unable to determine the
 *            alphabet type; in this case, <*ret_type> is set to 
 *            <eslUNKNOWN>.
 *
 * Xref:      J1/62; 2007/0517-easel-guess-alphabet
 */
esl_sq_GuessAlphabet()
Synopsis:  Guess alphabet type of a single sequence.

Guess the alphabet type of biosequence , and store the
guess in <*ret_type>.

All 26 letters are valid in the amino alphabet (even 
and  now), so the DNA alphabet is necessarily a subset.
Therefore most protein sequences can be identified
unambiguously (because they use letters that only occur
in amino acid sequence), but DNA sequences cannot be.

The sequence must contain more than 10 residues, or it
is called .

Specifically, this routine calls the sequence 
if it consists only of the residues  and all four
of  occur. (And analogously for ,
.)  It calls the sequence  either if it
contains an amino-specific letter (), or if
it contains at least 15 of the 20 canonical amino acids
and consists only of canonical amino acids or .

Thus DNA sequences containing IUPAC degeneracies other
than N are called , rather than hazarding a
guess. It may be possible to improve on this in the
future by using residue occurrence frequencies.

Note that a sequence of  will be called
, whereas a sequence 
(which could conceivably be "ala-cys-gly-thr...") will
be called . Peptides of simple mono and di-amino
acid compositions do occur, but I have not (yet) seen a
peptide consisting only of all four residues .

The routine is designed to be conservative, calling
 rather than making errors. In a test on the
Oct 2006 version of the NCBI nonredundant databases,
this routine called 0  and 5694  on
4.0M protein sequences (99.9\% classification with no
false positives) and 0  and 155756
 in 4.4M DNA sequences (96\% classification
with no false positives). (Well, actually, one DNA call
was made in the protein database, but this was an
exception that proves the rule; that entry was indeed a
DNA contaminant. It has since been removed by NCBI.)

 on success, and <*ret_type> is set to
, , or .

Returns  if unable to determine the
alphabet type; in this case, <*ret_type> is set to
.


esl_sq_GuessAlphabet () Synopsis : Guess alphabet type of a single sequence . Guess the alphabet type of biosequence and store the guess in < * ret_type > . All 26 letters are valid in the amino alphabet ( even and now ) so the DNA alphabet is necessarily a subset . Therefore most protein sequences can be identified unambiguously ( because they use letters that only occur in amino acid sequence ) but DNA sequences cannot be . The sequence must contain more than 10 residues or it is called . Specifically this routine calls the sequence if it consists only of the residues and all four of occur . ( And analogously for . ) It calls the sequence either if it contains an amino - specific letter () or if it contains at least 15 of the 20 canonical amino acids and consists only of canonical amino acids or . Thus DNA sequences containing IUPAC degeneracies other than N are called rather than hazarding a guess . It may be possible to improve on this in the future by using residue occurrence frequencies . Note that a sequence of will be called whereas a sequence ( which could conceivably be " ala - cys - gly - thr ... " ) will be called . Peptides of simple mono and di - amino acid compositions do occur but I have not ( yet ) seen a peptide consisting only of all four residues . The routine is designed to be conservative calling rather than making errors . In a test on the Oct 2006 version of the NCBI nonredundant databases this routine called 0 and 5694 on 4 . 0M protein sequences ( 99 . 9 \ % classification with no false positives ) and 0 and 155756 in 4 . 4M DNA sequences ( 96 \ % classification with no false positives ) . ( Well actually one DNA call was made in the protein database but this was an exception that proves the rule ; that entry was indeed a DNA contaminant . It has since been removed by NCBI . ) on success and < * ret_type > is set to or . Returns if unable to determine the alphabet type ; in this case < * ret_type > is set to .
int
esl_sq_GuessAlphabet(ESL_SQ *sq, int *ret_type)
{
  int64_t ct[26];
  int     x;
  int64_t i;
  int64_t n = 0;
  for (x = 0; x < 26; x++) ct[x] = 0;
  for (i = 0; i < sq->n; i++) {
    x = toupper(sq->seq[i]) - 'A';
    if (x < 0 || x > 26) continue;
    ct[x]++;
    n++;
    if (n > 10000) break;	
  }
  return esl_abc_GuessAlphabet(ct, ret_type);
}
int esl_sq_GuessAlphabet ( ESL_SQ * sq , int * ret_type ) { int64_t ct [ 26 ] ; int x ; int64_t i ; int64_t n = 0 ; for ( x = 0 ; x < 26 ; x ++ ) ct [ x ] = 0 ; for ( i = 0 ; i < sq -> n ; i ++ ) { x = toupper ( sq -> seq [ i ] ) - ' ' ; if ( x < 0 || x > 26 ) continue ; ct [ x ] ++ ; n ++ ; if ( n > 10000 ) break ; } return esl_abc_GuessAlphabet ( ct , ret_type ) ; }
Function:  esl_sq_GuessAlphabet()
 Synopsis:  Guess alphabet type of a single sequence.
Function : esl_sq_GuessAlphabet () Synopsis : Guess alphabet type of a single sequence .
/* we oughta know by now! */