Пример #1
0
bool AceParser::parse(fnLytSeq* seqfn) {
    //read all seqs and their positions from the file
    //also checks for duplicate seqnames (just in case)
    if (f!=stdin)  seek(0);
    ctgIDs.Clear();
    //GHash<int> ctgIDs; //contig IDs, to make them unique!
    //
    off_t ctgpos;
    numContigs=0;
    while ((ctgpos=fskipTo("CO "))>=0) {
        numContigs++;
        LytCtgData* ctgdata=new LytCtgData(ctgpos);
        char* p=ctgdata->readName(linebuf->chars()+3, ctgIDs);
        if (p==NULL) {
            GMessage("AceParser: error parsing contig name!\n");
            return false;
        }
        int ctglen, numseqs;
        //p must be after contig name within linebuf!
        if (sscanf(p, "%d %d", &ctglen, &numseqs)!=2) {
            GMessage("Error parsing contig len and seq count at:\n%s\n",
                     linebuf->chars());
        }
        ctgdata->len=ctglen;
        ctgdata->numseqs = numseqs;
        ctgdata->offs = 1;
        int ctgidx=contigs.Add(ctgdata);
        loadContig(ctgidx, seqfn, false);
    } //while contigs
    if (ctgpos==-2) return false; //parsing failed: line too long ?!?
    contigs.setSorted(true);
    return true;
}
Пример #2
0
bool LayoutParser::parse(fnLytSeq* seqfn) {
  //read all seqs and their positions from the file
  //also checks for duplicate seqnames (just in case)
  if (f!=stdin) seek(0);
  ctgIDs.Clear();
  //GHash<int> ctgIDs; //contig IDs, to make them unique!
  //
  int ctgpos;
  numContigs=0;
  while ((ctgpos=fskipTo(">"))>=0) { //locate the contig line
    numContigs++;
    LytCtgData* ctgdata=new LytCtgData(ctgpos);
    char* p=ctgdata->readName(linebuf->chars()+1, ctgIDs);
    if (p==NULL) {
       GMessage("LayoutParser: error parsing contig name:\n%s\n", linebuf->chars());
       return false;
       }
    int ctg_lpos, ctg_rpos, numseqs;
    //p must be after contig name within linebuf!
    ctg_lpos=0;ctg_rpos=0;
    if (sscanf(p, "%d %d %d", &numseqs, &ctg_lpos, &ctg_rpos)<1) {
      GMessage("Error parsing contig len and seq count at:\n%s\n",
         p);
      return false;
      }
    //ctg_numSeqs=numseqs;
    ctgdata->numseqs=numseqs;
    ctgdata->rpos=ctg_rpos;
    ctgdata->lpos=ctg_lpos;
    ctgdata->len=ctg_rpos-ctg_lpos+1;
    ctgdata->offs=ctg_lpos;
    int ctgidx=contigs.Add(ctgdata);
    //now look and load all the component sequences
    loadContig(ctgidx, seqfn, false);
    } //while lines
  contigs.setSorted(true);
  return true;
  }
Пример #3
0
/*************************************************
 Function:
    loadUpdatedEdges
 Description:
    Loads contig information and masks some contigs according to setting.
 Input:
    1. graphfile:       prefix of graph file
 Output:
    None.
 Return:
    None.
 *************************************************/
void loadUpdatedEdges ( char * graphfile )
{
	char c, name[256], line[1024];
	int bal_ed, cvg;
	FILE * fp, *out_fp;
	Kmer from_kmer, to_kmer;
	unsigned int num_ctgge, length, index = 0, num_kmer;
	unsigned int i = 0, j;
	int newIndex;
	unsigned int * length_array, *flag_array, diff_len;
	char * outfile = graphfile;
	long long cvgSum = 0;
	long long counter = 0;
	unsigned int avg_arc_wt;
	int ctg_short_cutoff;
	float high_cvg_cutoff1, high_cvg_cutoff2, low_cvg_cutoff;
	int cut_len;
	//get overlaplen from *.preGraphBasic
	sprintf ( name, "%s.preGraphBasic", graphfile );
	fp = ckopen ( name, "r" );

	while ( fgets ( line, sizeof ( line ), fp ) != NULL )
	{
		if ( line[0] == 'V' )
		{
			sscanf ( line + 6, "%d %c %d", &num_kmer, &c, &overlaplen );
			fprintf ( stderr, "Kmer size: %d\n", overlaplen );
			break;
		}
	}

	cut_len = COMPATIBLE_MODE == 0 ? overlaplen : 0;

	if ( ctg_short == 0 )
	{
		ctg_short = overlaplen + 2;
	}

	ctg_short_cutoff = 2 * overlaplen + 2 < 100 ? 100 : 0;
	fclose ( fp );
	sprintf ( name, "%s.updated.edge", graphfile );
	fp = ckopen ( name, "r" );
	sprintf ( name, "%s.newContigIndex", outfile );
	out_fp = ckopen ( name, "w" );

	while ( fgets ( line, sizeof ( line ), fp ) != NULL )
	{
		if ( line[0] == 'E' )
		{
			sscanf ( line + 5, "%d", &num_ctgge );
			fprintf ( stderr, "There are %d edge(s) in edge file.\n", num_ctgge );
			break;
		}
	}

	index_array = ( unsigned int * ) ckalloc ( ( num_ctgge + 1 ) * sizeof ( unsigned int ) );
	length_array = ( unsigned int * ) ckalloc ( ( num_ctgge + 1 ) * sizeof ( unsigned int ) );
	flag_array = ( unsigned int * ) ckalloc ( ( num_ctgge + 1 ) * sizeof ( unsigned int ) );

	while ( fgets ( line, sizeof ( line ), fp ) != NULL )
	{
		if ( line[0] == '>' )
		{
			sscanf ( line + 7, "%d", &length );
			index_array[++index] = length;
			length_array[++i] = length;
		}
	}

	num_ctg = index;
	orig2new = 1;
	qsort ( & ( length_array[1] ), num_ctg, sizeof ( length_array[0] ), cmp_int );
	//extract unique length
	diff_len = 0;

	for ( i = 1; i <= num_ctg; i++ )
	{
		for ( j = i + 1; j <= num_ctg; j++ )
			if ( length_array[j] != length_array[i] )
			{
				break;
			}

		length_array[++diff_len] = length_array[i];
		flag_array[diff_len] = i;
		i = j - 1;
	}

	contig_array = ( CONTIG * ) ckalloc ( ( num_ctg + 1 ) * sizeof ( CONTIG ) );
	//load edges
	index = 0;
	rewind ( fp );

	while ( fgets ( line, sizeof ( line ), fp ) != NULL )
	{
		if ( line[0] == '>' )
		{
			sscanf ( line, ">length %u,%d,%d", &length, &bal_ed, &cvg );
			newIndex = uniqueLenSearch ( length_array, flag_array, diff_len, length );
			index_array[++index] = newIndex;

			if ( length != 0 ) { contig_array[newIndex].length = length - cut_len; }
			else  { contig_array[newIndex].length = 0; }

			contig_array[newIndex].bal_edge = bal_ed + 1;
			contig_array[newIndex].downwardConnect = NULL;
			contig_array[newIndex].mask = 0;
			contig_array[newIndex].flag = 0;
			contig_array[newIndex].arcs = NULL;
			contig_array[newIndex].seq = NULL;
			contig_array[newIndex].multi = 0;
			contig_array[newIndex].inSubGraph = 0;
			contig_array[newIndex].bubbleInScaff = 0;
			contig_array[newIndex].cvg = cvg / 10;

			if ( cvg && length > 100 )
			{
				counter += length - cut_len;
				cvgSum += cvg * ( length - cut_len );
			}

			fprintf ( out_fp, "%d %d %d\n", index, newIndex, contig_array[newIndex].bal_edge );
		}
	}

	if ( counter )
	{
		cvgAvg = cvgSum / counter / 10 > 2 ? cvgSum / counter / 10 : 3;
	}

	//mark repeats
	int bal_i;

	if ( maskRep )
	{
		high_cvg_cutoff1 = cvg_high * cvgAvg;
		high_cvg_cutoff2 = cvg_high * cvgAvg * 0.8;
		low_cvg_cutoff = cvg_low * cvgAvg;
		counter = 0;
		fprintf ( stderr, "Mask contigs with coverage lower than %.1f or higher than %.1f, and strict length %d.\n", low_cvg_cutoff, high_cvg_cutoff1, ctg_short_cutoff );

		for ( i = 1; i <= num_ctg; i++ )
		{
			bal_i = getTwinCtg ( i );

			if ( ( contig_array[i].cvg + contig_array[bal_i].cvg ) > 2 * high_cvg_cutoff1 )
			{
				contig_array[i].mask = 1;
				contig_array[bal_i].mask = 1;

				if ( i == bal_i ) { counter += 1; }
				else { counter += 2; }
			}
			else if ( contig_array[i].length < ctg_short_cutoff && ( contig_array[i].cvg > high_cvg_cutoff2 || contig_array[bal_i].cvg > high_cvg_cutoff2 || ( contig_array[i].cvg < low_cvg_cutoff && contig_array[bal_i].cvg < low_cvg_cutoff ) ) )
			{
				contig_array[i].mask = 1;
				contig_array[bal_i].mask = 1;

				if ( i == bal_i ) { counter += 1; }
				else { counter += 2; }
			}
			else if ( cvgAvg < 50 && ( contig_array[i].cvg >= 63 || contig_array[bal_i].cvg >= 63 ) )
			{
				contig_array[i].mask = 1;
				contig_array[bal_i].mask = 1;

				if ( i == bal_i ) { counter += 1; }
				else { counter += 2; }
			}

			if ( isSmallerThanTwin ( i ) )
			{
				i++;
			}
		}

		fprintf ( stderr, "Average contig coverage is %d, %lld contig(s) masked.\n", cvgAvg, counter );
	}

	counter = 0;

	for ( i = 1; i <= num_ctg; i++ )
	{
		if ( contig_array[i].mask )
		{
			continue;
		}

		bal_i = getTwinCtg ( i );

		if ( contig_array[i].length < ctg_short )
		{
			contig_array[i].mask = 1;
			contig_array[bal_i].mask = 1;

			if ( i == bal_i ) { counter += 1; }
			else { counter += 2; }
		}

		if ( isSmallerThanTwin ( i ) )
		{
			i++;
		}
	}

	fprintf ( stderr, "Mask contigs shorter than %d, %lld contig(s) masked.\n", ctg_short, counter );
	avg_arc_wt = loadArcs ( graphfile );
	counter = 0;
	//counter = maskRepeatByArc(avg_arc_wt);
	//printf ("Mask contigs with multi arcs, %d contig masked\n", counter);
	//tipsCount();
	loadContig ( graphfile );
	fprintf ( stderr, "Done loading updated edges.\n" );
	free ( ( void * ) length_array );
	free ( ( void * ) flag_array );
	fclose ( fp );
	fclose ( out_fp );
}