/************************************************* Function: loadContig Description: Loads contigs sequence. Input: 1. graphfile: prefix of graph file Output: None. Return: None. *************************************************/ void loadContig ( char * graphfile ) { char c, name[256], line[1024], *tightSeq = NULL; FILE * fp; int n = 0, length, index = -1, edgeno; unsigned int i; unsigned int newIndex; sprintf ( name, "%s.contig", graphfile ); fp = ckopen ( name, "r" ); while ( fgets ( line, sizeof ( line ), fp ) != NULL ) { if ( line[0] == '>' ) { if ( index >= 0 ) { newIndex = index_array[edgeno]; contig_array[newIndex].seq = tightSeq; } n = 0; index++; sscanf ( line + 1, "%d %s %d", &edgeno, name, &length ); //printf("contig %d, length %d\n",edgeno,length); tightSeq = ( char * ) ckalloc ( ( length / 4 + 1 ) * sizeof ( char ) ); } else { for ( i = 0; i < strlen ( line ); i++ ) { if ( line[i] >= 'a' && line[i] <= 'z' ) { c = base2int ( line[i] - 'a' + 'A' ); writeChar2tightString ( c, tightSeq, n++ ); } else if ( line[i] >= 'A' && line[i] <= 'Z' ) { c = base2int ( line[i] ); writeChar2tightString ( c, tightSeq, n++ ); } } } } if ( index >= 0 ) { newIndex = index_array[edgeno]; contig_array[newIndex].seq = tightSeq; } fprintf ( stderr, "%d contig(s) loaded.\n", index + 1 ); fclose ( fp ); //printf("the %dth contig with index 107\n",index); }
void copySeq (char *targetS, char *sourceS, int pos, int length) { char ch; int i, index; index = pos; for (i = 0; i < length; i++) { ch = getCharInTightString (sourceS, i); writeChar2tightString (ch, targetS, index++); } }