lib/R2R/R2R-1.0.6/NotByZasha/infernal-0.7/squid/a2m.c
/* Function: ReadA2M()
 * Date:     SRE, Sun Jun  6 17:11:29 1999 [bus from Madison 1999 worm mtg]
 *
 * Purpose:  Parse an alignment read from an open A2M format
 *           alignment file. A2M is a single alignment format.
 *           Return the alignment, or NULL if we've already
 *           read the alignment.
 *
 * Args:     afp - open alignment file
 *
 * Returns:  MSA *  - an alignment object. 
 *                    Caller responsible for an MSAFree()
 */


Parse an alignment read from an open A2M format
alignment file. A2M is a single alignment format.
Return the alignment, or NULL if we've already
read the alignment.

open alignment file

MSA *  - an alignment object.
Caller responsible for an MSAFree()
Parse an alignment read from an open A2M format alignment file . A2M is a single alignment format . Return the alignment or NULL if we ' ve already read the alignment . open alignment file MSA * - an alignment object . Caller responsible for an MSAFree ()
MSA *
ReadA2M(MSAFILE *afp)
{
  MSA  *msa;
  char *buf;
  char *name;
  char *desc;
  char *seq;
  int   idx;
  int   len1, len2;
  if (feof(afp->f)) return NULL;
  name = NULL;
  msa  = MSAAlloc(10, 0);
  idx  = 0;
  while ((buf = MSAFileGetLine(afp)) != NULL) 
    {
      if (*buf == '>') 
	{
	  buf++;		
	  if ((name = sre_strtok(&buf, WHITESPACE, &len1)) == NULL)
	    Die("Blank name in A2M file %s (line %d)\n", afp->fname, afp->linenumber);
	  desc = sre_strtok(&buf, "\n", &len2);
	  idx = GKIStoreKey(msa->index, name);
	  if (idx >= msa->nseqalloc) MSAExpand(msa);
	  msa->sqname[idx] = sre_strdup(name, len1);
	  if (desc != NULL) MSASetSeqDescription(msa, idx, desc);
	  msa->nseq++;
	} 
      else if (name != NULL) 
	{
	  if ((seq = sre_strtok(&buf, WHITESPACE, &len1)) == NULL) continue; 
	  msa->sqlen[idx] = sre_strcat(&(msa->aseq[idx]), msa->sqlen[idx], seq, len1);
	}
    } 
  if (name == NULL) { MSAFree(msa); return NULL; }
  MSAVerifyParse(msa);
  return msa;
}
MSA * ReadA2M ( MSAFILE * afp ) { MSA * msa ; char * buf ; char * name ; char * desc ; char * seq ; int idx ; int len1 , len2 ; if ( feof ( afp -> f ) ) return NULL ; name = NULL ; msa = MSAAlloc ( 10 , 0 ) ; idx = 0 ; while ( ( buf = MSAFileGetLine ( afp ) ) != NULL ) { if ( * buf == ' ' ) { buf ++ ; if ( ( name = sre_strtok ( & buf , WHITESPACE , & len1 ) ) == NULL ) Die ( " \n " , afp -> fname , afp -> linenumber ) ; desc = sre_strtok ( & buf , " \n " , & len2 ) ; idx = GKIStoreKey ( msa -> index , name ) ; if ( idx >= msa -> nseqalloc ) MSAExpand ( msa ) ; msa -> sqname [ idx ] = sre_strdup ( name , len1 ) ; if ( desc != NULL ) MSASetSeqDescription ( msa , idx , desc ) ; msa -> nseq ++ ; } else if ( name != NULL ) { if ( ( seq = sre_strtok ( & buf , WHITESPACE , & len1 ) ) == NULL ) continue ; msa -> sqlen [ idx ] = sre_strcat ( & ( msa -> aseq [ idx ] ) , msa -> sqlen [ idx ] , seq , len1 ) ; } } if ( name == NULL ) { MSAFree ( msa ) ; return NULL ; } MSAVerifyParse ( msa ) ; return msa ; }
Function: ReadA2M()
 Date:     SRE, Sun Jun  6 17:11:29 1999 [bus from Madison 1999 worm mtg]
Function : ReadA2M () Date : SRE Sun Jun 6 17 : 11 : 29 1999 [ bus from Madison 1999 worm mtg ]
/* skip the '>' */