示例#1
0
/* read a fasta file and pass the sequence to an array */
void readseq (char filename[], char seq[]) {

	FILE	*file;                           // hold fasta file
	int		i;                               // index for seq[]
	char	line[ MAXCOL ];                  // store each line
	int		j;                               // index for line[]

	file = fopen( filename, "r" );

	if ( file == NULL ) {

		printf("Error: file %s does not exist!\n", filename);
		exit(1);

	}

	i = 0;
	while ( fgets( line, sizeof line, file ) ) {

		/* if a fasta header line was found */
		if ( line[0] == '>' ) continue;
		
		/* now try to parse the fasta body */
		for ( j = 0; j < strlen(line); j++ ) {
			if ( isnuc( line[j] ) ) seq[i++] = line[j];
		}

	} // end of while
	seq[i] = '\0';

	fclose( file );

} // end readseq
示例#2
0
//// read and filter a line of input sequence from the file stream
void Gene::readline( char linebuff[], int const chars )
{
	// use temporary filter container to avoid constly multiple redimensioning
	std::vector< char > clean( chars );
	int nclean(0);
	// filter as rapidly as possible
	for ( int i(0); i < chars; ++i ) {
		char const thischar = linebuff[i];
		if ( isnuc(thischar) ) clean[nclean++] = thischar;
	}
	sequence_.insert( sequence_.end(), clean.begin(), clean.begin() + nclean );
}