コード例 #1
0
ファイル: indelMapper.c プロジェクト: gersteinlab/vat
int main (int argc, char *argv[])
{
  Array intervals;
  Interval *currInterval;
  SubInterval *currSubInterval;
  int h,i,j;
  Array seqs;
  Seq *currSeq,testSeq;
  int index;
  Stringa buffer;
  Array geneTranscriptEntries;
  Texta geneTranscriptIds;
  Array alterations;
  Alteration *currAlteration,*nextAlteration;
  char *proteinSequenceBeforeIndel;
  char *proteinSequenceAfterIndel;
  int numDisabledTranscripts;
  Stringa disabledTranscripts;
  int seqLength,refLength,altLength;
  char *sequenceBeforeIndel = NULL;
  int overlapMode;
  int numOverlaps;
  int sizeIndel,indelOffset;
  int overlap;
  Array coordinates;
  VcfEntry *currVcfEntry;
  VcfGenotype *currVcfGenotype;
  int position;
  Texta alternateAlleles;
  int flag1,flag2;
  
  if (argc != 3) {
    usage ("%s <annotation.interval> <annotation.fa>",argv[0]);
  }
  intervalFind_addIntervalsToSearchSpace (argv[1],0);
  geneTranscriptEntries = util_getGeneTranscriptEntries (intervalFind_getAllIntervals ());
  seq_init ();
  fasta_initFromFile (argv[2]);
  seqs = fasta_readAllSequences (0);
  fasta_deInit ();
  arraySort (seqs,(ARRAYORDERF)util_sortSequencesByName); 
  buffer = stringCreate (100);
  disabledTranscripts = stringCreate (100);
  alterations = arrayCreate (100,Alteration);
  vcf_init ("-");
  stringPrintf (buffer,"##INFO=<ID=VA,Number=.,Type=String,Description=\"Variant Annotation, %s\">",argv[1]);
  vcf_addComment (string (buffer));
  puts (vcf_writeMetaData ());
  puts (vcf_writeColumnHeaders ());
  while (currVcfEntry = vcf_nextEntry ()) {
    if (vcf_isInvalidEntry (currVcfEntry)) {
      continue;
    }
    flag1 = 0;
    flag2 = 0;
    position = currVcfEntry->position - 1; // make zero-based
    alternateAlleles = vcf_getAlternateAlleles (currVcfEntry);
    for (h = 0; h < arrayMax (alternateAlleles); h++) {
      refLength = strlen (currVcfEntry->referenceAllele);
      altLength = strlen (textItem (alternateAlleles,h));
      sizeIndel = abs (refLength - altLength);
      indelOffset = MAX (refLength,altLength) - 1; 
      util_clearAlterations (alterations);
      intervals = intervalFind_getOverlappingIntervals (currVcfEntry->chromosome,position,position + indelOffset);
      for (i = 0; i < arrayMax (intervals); i++) {
        currInterval = arru (intervals,i,Interval*);
        overlapMode = OVERLAP_NONE;
        numOverlaps = 0;
        for (j = 0; j < arrayMax (currInterval->subIntervals); j++) {
          currSubInterval = arrp (currInterval->subIntervals,j,SubInterval);
          overlap = rangeIntersection (position,position + indelOffset,currSubInterval->start,currSubInterval->end);
          if (currSubInterval->start <= position && (position + indelOffset) < currSubInterval->end) {
            overlapMode = OVERLAP_FULLY_CONTAINED;
            numOverlaps++;
          }
          else if (j == 0 && overlap > 0 && position < currSubInterval->start) {
            overlapMode = OVERLAP_START;
            numOverlaps++;
          }
          else if (j == (arrayMax (currInterval->subIntervals) - 1) && overlap > 0 && (position + indelOffset) >= currSubInterval->end) {
            overlapMode = OVERLAP_END;
            numOverlaps++;
          }
          else if (overlap > 0 && overlap <= indelOffset) {
            overlapMode = OVERLAP_SPLICE;
            numOverlaps++;
          }
        }
        if (overlapMode == OVERLAP_NONE) {
          continue;
        }
        currAlteration = arrayp (alterations,arrayMax (alterations),Alteration);
        if (numOverlaps > 1) {
          util_addAlteration (currAlteration,currInterval->name,"multiExonHit",currInterval,position,0);
          continue;
        }
        else if (numOverlaps == 1 && overlapMode == OVERLAP_SPLICE) {
          util_addAlteration (currAlteration,currInterval->name,"spliceOverlap",currInterval,position,0);
          continue;
        }
        else if (numOverlaps == 1 && overlapMode == OVERLAP_START) {
          util_addAlteration (currAlteration,currInterval->name,"startOverlap",currInterval,position,0);
          continue;
        }
        else if (numOverlaps == 1 && overlapMode == OVERLAP_END) {
          util_addAlteration (currAlteration,currInterval->name,"endOverlap",currInterval,position,0);
          continue;
        }
        else if (numOverlaps == 1 && overlapMode == OVERLAP_FULLY_CONTAINED && altLength > refLength) {
          if ((sizeIndel % 3) == 0) {
            util_addAlteration (currAlteration,currInterval->name,"insertionNFS",currInterval,position,0);
          }
          else {
            util_addAlteration (currAlteration,currInterval->name,"insertionFS",currInterval,position,0);
          }
        }
        else if (numOverlaps == 1 && overlapMode == OVERLAP_FULLY_CONTAINED && altLength < refLength) {
          if ((sizeIndel % 3) == 0) {
            util_addAlteration (currAlteration,currInterval->name,"deletionNFS",currInterval,position,0);
          }
          else {
            util_addAlteration (currAlteration,currInterval->name,"deletionFS",currInterval,position,0);
          }
        }
        else if (numOverlaps == 1 && overlapMode == OVERLAP_FULLY_CONTAINED && altLength == refLength) {
          util_addAlteration (currAlteration,currInterval->name,"substitution",currInterval,position,0);
        }
        else {
          die ("Unexpected type: %d %s %s %s",
               currVcfEntry->position,currVcfEntry->chromosome,
               currVcfEntry->referenceAllele,currVcfEntry->alternateAllele);
        }
        if ((sizeIndel % 3) != 0 && altLength != refLength) { 
          continue;
        }
        // Only run the remaining block of code if the indel is fully contained (insertion or deletion) AND does not cause a frameshift OR
        // if it is a substitution that is fully contained in the coding sequence
        stringPrintf (buffer,"%s|%s|%c|",currInterval->name,currInterval->chromosome,currInterval->strand);
        for (j = 0; j < arrayMax (currInterval->subIntervals); j++) {
          currSubInterval = arrp (currInterval->subIntervals,j,SubInterval);
          stringAppendf (buffer,"%d|%d%s",currSubInterval->start,currSubInterval->end,j < arrayMax (currInterval->subIntervals) - 1 ? "|" : "");
        }
        testSeq.name = hlr_strdup (string (buffer));
        if (!arrayFind (seqs,&testSeq,&index,(ARRAYORDERF)util_sortSequencesByName)) {
          die ("Expected to find %s in seqs",string (buffer));
        }
        hlr_free (testSeq.name);
        currSeq = arrp (seqs,index,Seq);
        strReplace (&sequenceBeforeIndel,currSeq->sequence);
        seqLength = strlen (sequenceBeforeIndel); 
        coordinates = util_getCoordinates (currInterval);
        // arraySort (coordinates,(ARRAYORDERF)util_sortCoordinatesByChromosomeAndTranscriptPosition); Array is already sorted by definition
        j = 0;
        stringClear (buffer);
        while (j < seqLength) {
          if (util_getGenomicCoordinate (coordinates,j,currVcfEntry->chromosome) == position) {
            if (altLength > refLength) {
              stringCat (buffer,textItem (alternateAlleles,h));
              j++;
              continue;
            }
            else if (altLength < refLength) {
              stringCatChar (buffer,sequenceBeforeIndel[j]);
              j = j + refLength - altLength + 1;
              continue;
            }
            else {
              stringCat (buffer,textItem (alternateAlleles,h));
              j = j + altLength;
              continue;
            }
          }
          stringCatChar (buffer,sequenceBeforeIndel[j]);
          j++;
        }
        util_destroyCoordinates (coordinates);
        proteinSequenceBeforeIndel = hlr_strdup (util_translate (currInterval,sequenceBeforeIndel));
        proteinSequenceAfterIndel = hlr_strdup (util_translate (currInterval,string (buffer)));
        addSubstitution (currAlteration,proteinSequenceBeforeIndel,proteinSequenceAfterIndel,indelOffset);
        hlr_free (proteinSequenceBeforeIndel);
        hlr_free (proteinSequenceAfterIndel);
      }
      if (arrayMax (alterations) == 0) {
        continue;
      }
      arraySort (alterations,(ARRAYORDERF)util_sortAlterationsByGeneIdAndType);
      stringClear (buffer);
      i = 0;
      while (i < arrayMax (alterations)) {
        currAlteration = arrp (alterations,i,Alteration);
        stringAppendf (buffer,"%s%d:%s:%s:%c:%s",stringLen (buffer) == 0 ? "" : ",",h + 1,currAlteration->geneName,currAlteration->geneId,currAlteration->strand,currAlteration->type);
         stringClear (disabledTranscripts);
        if (currAlteration->substitution[0] != '\0') {
          stringAppendf (disabledTranscripts,"%s:%s:%d_%d_%s",currAlteration->transcriptName,currAlteration->transcriptId,currAlteration->transcriptLength,currAlteration->relativePosition,currAlteration->substitution);
        }
        else if (strEqual (currAlteration->type,"multiExonHit") || strEqual (currAlteration->type,"spliceOverlap") ||
                 strEqual (currAlteration->type,"startOverlap") || strEqual (currAlteration->type,"endOverlap")) {
          stringAppendf (disabledTranscripts,"%s:%s:%d",currAlteration->transcriptName,currAlteration->transcriptId,currAlteration->transcriptLength);
        }
        else {
          stringAppendf (disabledTranscripts,"%s:%s:%d_%d",currAlteration->transcriptName,currAlteration->transcriptId,currAlteration->transcriptLength,currAlteration->relativePosition);
        }
        numDisabledTranscripts = 1;
        j = i + 1;
        while (j < arrayMax (alterations)) {
          nextAlteration = arrp (alterations,j,Alteration);
          if (strEqual (currAlteration->geneId,nextAlteration->geneId) && 
              strEqual (currAlteration->type,nextAlteration->type)) {
            if (nextAlteration->substitution[0] != '\0') {
              stringAppendf (disabledTranscripts,":%s:%s:%d_%d_%s",nextAlteration->transcriptName,nextAlteration->transcriptId,nextAlteration->transcriptLength,nextAlteration->relativePosition,nextAlteration->substitution);
            }
            else if (strEqual (nextAlteration->type,"multiExonHit") || strEqual (nextAlteration->type,"spliceOverlap") ||
                     strEqual (nextAlteration->type,"startOverlap") || strEqual (nextAlteration->type,"endOverlap")) {
              stringAppendf (disabledTranscripts,":%s:%s:%d",nextAlteration->transcriptName,nextAlteration->transcriptId,nextAlteration->transcriptLength);
            }
            else {
              stringAppendf (disabledTranscripts,":%s:%s:%d_%d",nextAlteration->transcriptName,nextAlteration->transcriptId,nextAlteration->transcriptLength,nextAlteration->relativePosition);
            }
            numDisabledTranscripts++;
          }
          else {
            break;
          }
          j++;
        }
        i = j;
        geneTranscriptIds = util_getTranscriptIdsForGeneId (geneTranscriptEntries,currAlteration->geneId);
        stringAppendf (buffer,":%d/%d:%s",numDisabledTranscripts,arrayMax (geneTranscriptIds),string (disabledTranscripts));
      }
      if (flag1 == 0) {
        printf ("%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s;VA=",
                currVcfEntry->chromosome,currVcfEntry->position,currVcfEntry->id,
                currVcfEntry->referenceAllele,currVcfEntry->alternateAllele,
                currVcfEntry->quality,currVcfEntry->filter,currVcfEntry->info);
        flag1 = 1;
      }
      printf ("%s%s",flag2 == 1 ? "," : "",string (buffer)); 
      flag2 = 1;
    }
    if (flag1 == 1) {
      for (i = 0; i < arrayMax (currVcfEntry->genotypes); i++) {
        currVcfGenotype = arrp (currVcfEntry->genotypes,i,VcfGenotype);
        if (i == 0) {
          printf ("\t%s\t",currVcfEntry->genotypeFormat);
        }
        printf ("%s%s%s%s",currVcfGenotype->genotype,
                currVcfGenotype->details[0] != '\0' ? ":" : "",
                currVcfGenotype->details[0] != '\0' ?  currVcfGenotype->details : "",
                i < arrayMax (currVcfEntry->genotypes) - 1 ? "\t" : ""); 
      }
      puts ("");
    }
  }
  vcf_deInit ();
  return 0;
}
コード例 #2
0
ファイル: operations.c プロジェクト: kimcoop/1550-project1
float gradepointForGrade( char* grade ) {
// expects grade as a string
// returns float value for corresponding grade point
float gpa = 0.00;

 if ( (strEqual(grade, "A+")) ) {  gpa = 4.00; } 
  else if ( (strEqual(grade, "A"))  ) { 	gpa = 4.00; } 
  else if ( (strEqual(grade, "A-")) ) {  gpa = 3.70;  }
  else if ( (strEqual(grade, "B+")) ) {  gpa = 3.33;  }
  else if ( (strEqual(grade, "B"))  ) {  gpa = 3.00;  }
  else if ( (strEqual(grade, "B-")) ) {  gpa = 2.70;  }
  else if ( (strEqual(grade, "C+")) ) {  gpa = 2.30;  }
  else if ( (strEqual(grade, "C"))  ) {  gpa = 2.00;  }
  else if ( (strEqual(grade, "C-")) ) {  gpa = 1.70;  }
  else if ( (strEqual(grade, "D+")) ) {  gpa = 1.30;  }
  else if ( (strEqual(grade, "D"))  ) {  gpa = 1.00;  }
  else if ( (strEqual(grade, "D-")) ) {  gpa = 0.70;  }
  else {  
  	println( "Grade %s not recognized. ", grade );
  	gpa = 0.00;
  }

	return gpa;
}
コード例 #3
0
ファイル: showDetails_cgi.c プロジェクト: arsenijae/fusionseq
int main (int argc, char *argv[]) 
{
  FILE* ftmp = NULL;
  
  if ((Conf = confp_open(getenv("FUSIONSEQ_CONFPATH"))) == NULL)
    return EXIT_FAILURE;
  
  cgiInit();
  cgiHeader("text/html");

  if (argc == 3) {
    GfrEntry *currGE;
    Stringa buffer;
    GfrPairCount *currGEPC;
    GfrInterRead *currGIR;
    int i;

    puts ("<html>");
    puts ("<head>");
    html_printGenericStyleSheet (12);
    puts ("<title>geneFusions Details</title>\n");
    puts ("</head>");
    puts ("<body>");
    buffer = stringCreate (100);
    stringPrintf (buffer, "%s/%s.gfr", confp_get(Conf, "WEB_DATA_DIR"),argv[1]);    
    gfr_init (string (buffer));
    while (currGE = gfr_nextEntry ()){
      fflush( stdout );
      if (!strEqual (currGE->id,argv[2])) {
        continue;
      }
      printf ("<h1>Detailed summary for potential gene fusion candidate</h1><br>");
      puts ("<table border=0 cellpadding=10>");
      puts ("<tr align=left valign=top>");
      puts ("<td width=400>");
      puts ("<h2>Summary information</h2><br>");
      printf ("<b>Identifier</b>: %s<br><br>\n",currGE->id);
      printf ("<b>Number of inter paired-end reads</b>: %d<br><br>\n",currGE->numInter);
      printf ("<b>Type</b>: %s<br><br>\n",currGE->fusionType);     
      
      stringPrintf(buffer, "%s/GFF/%s.gff", confp_get(Conf, "WEB_DATA_DIR"),currGE->id);       
      ftmp = fopen( string(buffer), "r" ); // displaying this only if data are present
      if (ftmp) {
	 printf("<b>Connected Reads</b>: <a href=%s&hgt.customText=%s/GFF/%s.gff target=blank>UCSC connectivity graph</a><br>\n",
              	htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",
			currGE->chromosomeTranscript1,
			currGE->startTranscript1 - atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION")),
			currGE->endTranscript2 + atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"))),
              confp_get(Conf, "WEB_DATA_LINK"),currGE->id); 
	 fclose( ftmp );
      }
   
      puts ("</td>");
      puts ("<td>");
      puts ("<h2>Transcript connectivity graph</h2>");
      printf ("<img src=%s/IMAGES/%s.jpg alt=geneFusionImage>\n", confp_get(Conf, "WEB_DATA_LINK"), currGE->id);
      puts ("</td>");
      puts ("<td>");
      puts ("<h2>Transcript connectivity table</h2><br>");
      puts ("<table border=0>");
      puts ("<tr align=left>");
      puts ("<th width=200>Pair Type</th>");
      puts ("<th width=200>Entry transcript 1</th>");
      puts ("<th width=200>Entry transcript 2</th>");
      puts ("<th width=200>Counts</th>");
      puts ("</tr>");
      fflush( stdout );
      for (i = 0; i < arrayMax (currGE->pairCounts); i++) {
        currGEPC = arrp (currGE->pairCounts,i,GfrPairCount);	
        printf ("<tr><td>%s</td><td>%s</td><td>%s</td><td>%.2f</td></tr>\n", 
		        getPairTypeName(currGEPC->pairType), 
		        getEntryNumber(currGEPC->number1, currGEPC->pairType, 1),
		        getEntryNumber(currGEPC->number2, currGEPC->pairType, 2),
		        currGEPC->count);
      }
      puts ("</table>");
      puts ("</td>");
      puts ("</tr>");
      puts ("</table>");
      puts ("<br>");

      puts ("<h2>Transcript information</h2><br>");
      puts ("<table border=1 cellpadding=10 width=\"80%\">");
      puts ("<tr align=left>");
      puts ("<th width=\"20%\"></th>");
      puts ("<th><font color='blue'>Transcript 1</font></th>");
      puts ("<th><font color='orange'>Transcript 2</font></th>");
      puts ("</tr>");
      puts ("<tr align=left>");
      puts ("<td width=\"20%\"><b>Gene symbol(s)</b></td>");
      printf ("<td width=\"30%%\"><font color='blue'>%s</font></td>\n",processString (currGE->geneSymbolTranscript1));
      printf ("<td width=\"30%%\"><font color='orange'>%s</font></td>\n",processString (currGE->geneSymbolTranscript2));
      puts ("</tr>");
      puts ("<tr align=left>");
      puts ("<td width=\"20%\"><b>Coordinates</b></td>");
      printf ("<td width=\"30%%\">%s:%d-%d</td>\n",currGE->chromosomeTranscript1,currGE->startTranscript1,currGE->endTranscript1);
      printf ("<td width=\"30%%\">%s:%d-%d</td>\n",currGE->chromosomeTranscript2,currGE->startTranscript2,currGE->endTranscript2);
      puts ("</tr>");
      puts ("<tr align=left>");
      puts ("<td width=\"20%\"><b>Strand</b></td>");
      printf ("<td width=\"30%%\">%c</td>\n",currGE->strandTranscript1);
      printf ("<td width=\"30%%\">%c</td>\n",currGE->strandTranscript2);
      puts ("</tr>");
      puts ("<tr align=left>");
      puts ("<td width=\"20%\"><b>Gene description(s)</b></td>");
      printf ("<td width=\"30%%\">%s</td>\n",processString (currGE->descriptionTranscript1));
      printf ("<td width=\"30%%\">%s</td>\n",processString (currGE->descriptionTranscript2));
      puts ("</tr>");
      puts ("<tr align=left>");
      puts ("<td width=\"20%\"><b>Number of exons</b></td>");
      printf ("<td width=\"30%%\">%d</td>\n",currGE->numExonsTranscript1);
      printf ("<td width=\"30%%\">%d</td>\n",currGE->numExonsTranscript2);
      puts ("</tr>");
      puts ("<tr align=left>");
      puts ("<td width=\"20%\"><b>Number of intra paired-end reads</b></td>");
      printf ("<td width=\"30%%\">%d</td>\n",currGE->numIntra1);
      printf ("<td width=\"30%%\">%d</td>\n",currGE->numIntra2);
      puts ("</tr>");
      puts ("<tr align=left>");
      puts ("<td width=\"20%\"><b>Links</b></td>");
      printf ("<td width=\"30%%\">[<a href=%s&hgt.customText=%s/BED/%s_1.bed target=blank>UCSC genome browser</a>]&nbsp;&nbsp;&nbsp;[<a href=%s/FASTA/%s_1.fasta>FASTA file</a>]<br></td>\n",
              htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",
		      currGE->chromosomeTranscript1,
		      currGE->startTranscript1 - atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION")),
		      currGE->endTranscript1 + atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"))),
              confp_get(Conf, "WEB_DATA_LINK"),
	      currGE->id,
	      confp_get(Conf, "WEB_DATA_LINK"),
	      currGE->id); 
      printf ("<td width=\"30%%\">[<a href=%s&hgt.customText=%s/BED/%s_2.bed target=blank>UCSC genome browser</a>]&nbsp;&nbsp;&nbsp;[<a href=%s/FASTA/%s_2.fasta>FASTA file</a>]<br></td></tr>\n",
              htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",
		      currGE->chromosomeTranscript2,
		      currGE->startTranscript2 - atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION")),
		      currGE->endTranscript2 + atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"))),
              confp_get(Conf, "WEB_DATA_LINK"),
	      currGE->id,
	      confp_get(Conf, "WEB_DATA_LINK"),
	      currGE->id); 
      
      puts ("<tr align=left>");
      puts ("<td width=\"20%\"><b>Expression</b></td>"); 

      stringPrintf(buffer, "%s/BGRS/%s_%s.bgr.gz", 
		   confp_get(Conf, "WEB_DATA_DIR"),
		   argv[1],
		   currGE->chromosomeTranscript1);  
      ftmp = fopen( string(buffer), "r" ); // displaying this only if data are present
      puts("<td width=\"30%\">");
      if( ftmp ) {
	printf ("[<a href=%s&hgt.customText=%s/BGRS/%s_%s.bgr.gz target=blank>Expression %s</a>]",
		htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",
			currGE->chromosomeTranscript1,
			currGE->startTranscript1 - atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION")),
			currGE->endTranscript1 + atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"))),
		confp_get(Conf, "WEB_DATA_LINK"),
		argv[1],
		currGE->chromosomeTranscript1,
		currGE->chromosomeTranscript1); 
	fclose(ftmp);
      }
      puts("</td>");

      stringPrintf(buffer, "%s/BGRS/%s_%s.bgr.gz", confp_get(Conf, "WEB_DATA_DIR"),argv[1],currGE->chromosomeTranscript2); 
      ftmp = fopen( string(buffer), "r" ); // displaying this only if data are present
      puts("<td width=\"30%\">");
      if( ftmp ) {
	printf ("[<a href=%s&hgt.customText=%s/BGRS/%s_%s.bgr.gz target=blank>Expression %s</a>]",
		htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",
			currGE->chromosomeTranscript2,
			currGE->startTranscript2 - atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION")),
			currGE->endTranscript2 + atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"))),
		confp_get(Conf, "WEB_DATA_LINK"),
		argv[1],
		currGE->chromosomeTranscript2,
		currGE->chromosomeTranscript2); 
	fclose(ftmp);
      } 
      puts("</td>");
      puts("</tr>");
      puts ("</table><br><br>");
      
      puts ("<h2>Breakpoint analysis</h2><br>");
      puts ("<table border=1 width=\"80%\" cellpadding=10><thead><tr><th>Orientation</th><th>Alignments</th><th colspan=2>Breakpoints</th></tr></thead><tbody>");
      puts ("<tr><td>Orientation AB</td>");
	if (currGE->strandTranscript1=='+') {
	  currGE->strandTranscript2=='+' ? stringPrintf(buffer, "AB_trans1F_trans2F") : stringPrintf(buffer, "AB_trans1F_trans2R");
	} else if( currGE->strandTranscript1 == '-') {
	  currGE->strandTranscript2=='+' ? stringPrintf(buffer, "AB_trans1R_trans2F") : stringPrintf(buffer, "AB_trans1R_trans2R");
	} else {
	  die("Strand informatation is not correct (transcript 1): %c", currGE->strandTranscript1);
	}
	printf ("<td align=center><a href=%s/ALIGNMENTS/%s_AB_breakPointAlignments.txt><img src=%s/IMAGES/%s.png></img>&nbsp;AB</a></td>", 
		confp_get(Conf, "WEB_DATA_LINK"), 
		currGE->id, 
		confp_get(Conf, "WEB_DATA_LINK"), 
		string(buffer)); 
	printf ("<td align=center><a href=%s&hgt.customText=%s/WIGS/%s_AB_breakPointsTranscript1.wig target=blank>Breakpoints transcript 1 UCSC Genome Browser</a></td>", 
		htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",
			currGE->chromosomeTranscript1,
			currGE->startTranscript1 - atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION")),
			currGE->endTranscript1 + atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"))),
		confp_get(Conf, "WEB_DATA_LINK"),
		currGE->id);
	printf ("<td align=center><a href=%s&hgt.customText=%s/WIGS/%s_AB_breakPointsTranscript2.wig target=blank>Breakpoints transcript 2 UCSC Genome Browser</a></td></tr>", 
		htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",
			currGE->chromosomeTranscript2,
			currGE->startTranscript2 - atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION")),
			currGE->endTranscript2 + atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"))),
		confp_get(Conf, "WEB_DATA_LINK"),
		currGE->id);	
      fflush(stdout);
      puts   ("<tr><td>Orientation BA</td>");  
      if (currGE->strandTranscript1 == '+') {
	currGE->strandTranscript2=='+' ? stringPrintf(buffer, "BA_trans1F_trans2F") : stringPrintf(buffer, "BA_trans1F_trans2R");
      } else if( currGE->strandTranscript1 == '-') {
	currGE->strandTranscript2=='+' ? stringPrintf(buffer, "BA_trans1R_trans2F") : stringPrintf(buffer, "BA_trans1R_trans2R");
      } else {
	die("Strand informatation is not correct (transcript2): %c", currGE->strandTranscript2);
	}	
      printf ("<td align=center><a href=%s/ALIGNMENTS/%s_BA_breakPointAlignments.txt><img src=%s/IMAGES/%s.png></img>&nbsp;BA</a></td>",
	      confp_get(Conf, "WEB_DATA_LINK"),
	      currGE->id, 
	      confp_get(Conf, "WEB_DATA_LINK"),
	      string(buffer));
      printf ("<td align=center><a href=%s&hgt.customText=%s/WIGS/%s_BA_breakPointsTranscript2.wig target=blank>Breakpoints transcript 2 UCSC Genome Browser</a></td>",	
	      htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",
		      currGE->chromosomeTranscript2,
		      currGE->startTranscript2 - atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION")),
	      	      currGE->endTranscript2 + atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"))),
	      confp_get(Conf, "WEB_DATA_LINK"),
	      currGE->id);
      printf ("<td align=center><a href=%s&hgt.customText=%s/WIGS/%s_BA_breakPointsTranscript1.wig target=blank>Breakpoints transcript 1 UCSC Genome Browser</a></td></tr>", 
	      htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",
		      currGE->chromosomeTranscript1,
		      currGE->startTranscript1 - atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION")),
		      currGE->endTranscript1 + atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"))),
	      confp_get(Conf, "WEB_DATA_LINK"),
	      currGE->id);       

      puts ("</tbody></table>");
      puts ("<br><br><br>");
      fflush(stdout);
    
    
      puts ("<h2>Read coordinates</h2><br>");
      puts ("<table border=0>");
      puts ("<tr align=left>");
      puts ("<th width=\"10%\">Pair Type</th>");
      puts ("<th width=\"10%\">Entry Transcript 1</th>");
      puts ("<th width=\"10%\">Read start transcript 1</th>");
      puts ("<th width=\"10%\">Read end transcript 1</th>");
      puts ("<th width=\"10%\">Entry Transcript 2</th>");
      puts ("<th width=\"10%\">Read start transcript 2</th>");
      puts ("<th width=\"10%\">Read end transcript 2</th>");
      puts ("</tr>");     
      for (i = 0; i < arrayMax (currGE->interReads); i++) {
	currGIR = arrp (currGE->interReads,i,GfrInterRead);
	printf ("<tr><td>%s</td><td>%s</td><td>%d</td><td>%d</td><td>%s</td><td>%d</td><td>%d</td></tr>\n",
		getPairTypeName(currGIR->pairType), 
		getEntryNumber(currGIR->number1, currGIR->pairType, 1),
		currGIR->readStart1,currGIR->readEnd1,
		getEntryNumber(currGIR->number2,currGIR->pairType, 2),
		currGIR->readStart2,
		currGIR->readEnd2);
      }
      puts ("</table><br><br><br>");
      puts ("</body>");
      puts ("</html>");
    fflush (stdout);
    }
  }
  confp_close(Conf);
  
  return EXIT_SUCCESS;
}
コード例 #4
0
ファイル: pgnscid.cpp プロジェクト: Raimondi/scid
int
main (int argc, char * argv[])
{
    setbuf(stdout, NULL);   // Make stdout unbuffered.

    gameNumberT gNumber;

    bool option_ForceReplace = false;
    bool option_PreGameComments = true;

    uint pgnFileSize = 0;
    char *progname = argv[0];
    fileNameT fname;
    fileNameT baseName;
    uint argsleft = argc - 1;
    char ** nextArg = argv + 1;

    // Parse command-line argments:
    while (argsleft > 0  &&  nextArg[0][0] == '-') {
        if (! strCompare (*nextArg, "-f")) {
            option_ForceReplace = true;
        } else if (! strCompare (*nextArg, "-x")) {
            option_PreGameComments = false;
        } else {
            usage (progname);
        }
        argsleft--;
        nextArg++;
    }
    if (argsleft != 1  &&  argsleft != 2) {
        usage (progname);
    }

    char * pgnName = *nextArg;
    MFile pgnFile;

    pgnFileSize = fileSize (pgnName, "");

    // Ensure positive file size counter to avoid division by zero:
    if (pgnFileSize < 1) {
        pgnFileSize = 1;
    }

    // Make baseName from pgnName if baseName is not provided:
    if (argsleft == 1) {
        strCopy (baseName, pgnName);
        // If a gzip file, remove two suffixes, the first being ".gz":
        const char * lastSuffix = strFileSuffix (baseName);
        if (lastSuffix != NULL  &&  strEqual (lastSuffix, GZIP_SUFFIX)) {
            strTrimFileSuffix (baseName);
        }
        // Trim the ".pgn" suffix:
        strTrimFileSuffix (baseName);
    } else {
        strCopy (baseName, nextArg[1]);
    }

    // Check for existing database, avoid overwriting it:
    if (! option_ForceReplace) {
        if (fileSize (baseName, INDEX_SUFFIX) > 0) {
            // Scid index file already exists:
            fprintf (stderr, "%s: database already exists: %s\n", progname,
                     baseName);
            fprintf (stderr, "You can use:  %s -f %s   to overwrite"
                     " the existing database.\n", progname, pgnName);
            exit(1);
        }
    }

    if (pgnFile.Open (pgnName, FMODE_ReadOnly) != OK) {
        fprintf (stderr, "%s: could not open file %s\n", progname, pgnName);
        exit(1);
    }

    // Try opening the log file:
    strCopy (fname, baseName);
    strAppend (fname, ".err");
    FILE * logFile = fopen (fname, "w");
    if (logFile == NULL) {
        fprintf (stderr, "%s: could not open log file: %s\n", progname, fname);
        exit(1);
    }

    printf ("Converting file %s to Scid database %s:\n", pgnName, baseName);
    printf ("Errors/warnings will be written to %s.\n\n", fname);

    scid_Init();

    GFile * gameFile = new GFile;
    if ((gameFile->Create (baseName, FMODE_WriteOnly)) != OK) {
        fprintf (stderr, "%s: could not create the file %s%s\n",
                 progname, baseName, GFILE_SUFFIX);
        fprintf (stderr, "The file may already exist and be read-only, or\n");
        fprintf (stderr, "you may not have permission to create this file.\n");
        exit(1);
    }

    NameBase * nb = new NameBase;
    Index * idx = new Index;
    IndexEntry * ie = new IndexEntry;
    idx->SetFileName (baseName);
    idx->CreateIndexFile (FMODE_WriteOnly);

    Game * game = new Game;
    ProgBar progBar(stdout);
    progBar.Start();

    ByteBuffer *bbuf = new ByteBuffer;
    bbuf->SetBufferSize (BBUF_SIZE); // 32768

    PgnParser pgnParser (&pgnFile);
    pgnParser.SetErrorFile (logFile);
    pgnParser.SetPreGameText (option_PreGameComments);

    // TODO: Add command line option for ignored tags, rather than
    //       just hardcoding PlyCount as the only ignored tag.
    pgnParser.AddIgnoredTag ("PlyCount");

    // Add each game found to the database:
    while (pgnParser.ParseGame(game) != ERROR_NotFound) {
        ie->Init();

        if (idx->AddGame (&gNumber, ie) != OK) {
            fprintf (stderr, "\nLimit of %d games reached!\n", MAX_GAMES);
            exit(1);
        }

        // Add the names to the namebase:
        idNumberT id = 0;

        if (nb->AddName (NAME_PLAYER, game->GetWhiteStr(), &id) != OK) {
            fatalNameError (NAME_PLAYER);
        }
        nb->IncFrequency (NAME_PLAYER, id, 1);
        ie->SetWhite (id);

        if (nb->AddName (NAME_PLAYER, game->GetBlackStr(), &id) != OK) {
            fatalNameError (NAME_PLAYER);
        }
        nb->IncFrequency (NAME_PLAYER, id, 1);
        ie->SetBlack (id);

        if (nb->AddName (NAME_EVENT, game->GetEventStr(), &id) != OK) {
            fatalNameError (NAME_EVENT);
        }
        nb->IncFrequency (NAME_EVENT, id, 1);
        ie->SetEvent (id);

        if (nb->AddName (NAME_SITE, game->GetSiteStr(), &id) != OK) {
            fatalNameError (NAME_SITE);
        }
        nb->IncFrequency (NAME_SITE, id, 1);
        ie->SetSite (id);

        if (nb->AddName (NAME_ROUND, game->GetRoundStr(), &id) != OK) {
            fatalNameError (NAME_ROUND);
        }
        nb->IncFrequency (NAME_ROUND, id, 1);
        ie->SetRound (id);

        bbuf->Empty();
        if (game->Encode (bbuf, ie) != OK) {
            fprintf (stderr, "Fatal error encoding game!\n");
            abort();
        }
        uint offset = 0;
        if (gameFile->AddGame (bbuf, &offset) != OK) {
            fprintf (stderr, "Fatal error writing game file!\n");
            abort();
        }
        ie->SetOffset (offset);
        ie->SetLength (bbuf->GetByteCount());
        idx->WriteEntries (ie, gNumber, 1);

        // Update the progress bar:
        if (! (gNumber % 100)) {
            int bytesSeen = pgnParser.BytesUsed();
            int percentDone = 1 + ((bytesSeen) * 100 / pgnFileSize);
            progBar.Update (percentDone);
        }

    }

    uint t = 0;   // = time(0);
    nb->SetTimeStamp(t);
    nb->SetFileName (baseName);
    if (nb->WriteNameFile() != OK) {
        fprintf (stderr, "Fatal error writing name file!\n");
        exit(1);
    }
    progBar.Finish();

    printf ("\nDatabase `%s': %d games, %d players, %d events, %d sites.\n",
            baseName, idx->GetNumGames(), nb->GetNumNames (NAME_PLAYER),
            nb->GetNumNames (NAME_EVENT), nb->GetNumNames (NAME_SITE));
    fclose (logFile);
    if (pgnParser.ErrorCount() > 0) {
        printf ("There were %u errors or warnings; ", pgnParser.ErrorCount());
        printf ("examine the file \"%s.err\"\n", baseName);
    } else {
        printf ("There were no warnings or errors.\n");
        removeFile (baseName, ".err");
    }
    gameFile->Close();
    idx->CloseIndexFile();

    // If there is a tree cache file for this database, it is out of date:
    removeFile (baseName, TREEFILE_SUFFIX);
#ifdef ASSERTIONS
    printf("%d asserts were tested\n", numAsserts);
#endif
    return 0;
}
コード例 #5
0
ファイル: geneFusions_cgi.c プロジェクト: arsenijae/fusionseq
int main (int argc, char *argv[]) 
{
  char *queryString;

  if ((Conf = confp_open(getenv("FUSIONSEQ_CONFPATH"))) == NULL)
    return EXIT_FAILURE;

  cgiInit();
  cgiHeader("text/html");
  queryString = cgiGet2Post();
  if (queryString[0] == '\0') {
    puts ("<html>");
    puts ("<head>");
    html_printGenericStyleSheet (12);
    puts ("<title>geneFusions</title>\n");
    puts ("</head>");
    puts ("<body>");
    puts ("<h1>Identification of potential gene fusions using paired-end reads</h1><br><br>");
    printf ("<form action=%s/geneFusions_cgi method=get>", confp_get(Conf, "WEB_URL_CGI"));
    puts ("<b>Data prefix</b>:&nbsp;");
    puts ("<input type=text name=prefix>");
    puts ("<br><br><br>");
    puts ("<b>Minimum number of paired-end reads connecting two genes</b>:&nbsp;");
    puts ("<select name=minNum>");
    puts ("<option value=2>2");
    puts ("<option value=3>3");
    puts ("<option value=5 selected>5");
    puts ("<option value=10>10");
    puts ("</select>");
    puts ("<br><br><br>");
    puts ("<b>Type of gene fusion</b>:&nbsp;");
    puts ("<select name=type>");
    puts ("<option value=read-through>Read-through events");
    puts ("<option value=cis>Cis events");
    puts ("<option value=intra>Intra-chromosomal events");
    puts ("<option value=same>Genes on the same chromosome");
    puts ("<option value=inter>Genes on different chromosomes");
    puts ("<option value=all selected>All potential gene fusions");
    puts ("</select>");
    puts ("<br><br><br>");
    puts ("<input type=submit value=Submit>");
    puts ("<input type=reset value=Reset>");
    puts ("</form>");
    puts ("</body>");
    puts ("</html>");
    fflush (stdout);
  }
  else {
    int first;
    Stringa item = stringCreate (20);
    Stringa value = stringCreate (20);
    char *iPtr,*vPtr,*prefix,*type;
    int minNum;

    first = 1;
    cgiGetInit ();
    while (cgiGetNextPair (&first,item,value)) {
      iPtr = string (item);
      vPtr = string (value);
      if (strEqual (iPtr,"prefix")) {
	prefix = hlr_strdup (vPtr);
      }
      if (strEqual (iPtr,"type")) {
	type = hlr_strdup (vPtr);
      }
      if (strEqual (iPtr,"minNum")) {
	minNum = atoi (vPtr);
      }
    }
    generateOutput (prefix,type,minNum);
  }
  confp_close(Conf);

  return EXIT_SUCCESS;
}
コード例 #6
0
ファイル: geneFusions_cgi.c プロジェクト: arsenijae/fusionseq
static void generateOutput (char* prefix, char* typeSelected, int minNum)
{
  GfrEntry *currGE;
  Stringa buffer;
  char *pos;

  puts ("<html>");
  puts ("<head>");
  puts ("<title>Results - Gene Fusions</title>");
  html_printGenericStyleSheet (12);
  puts ("</head>");
  puts ("<body>");
  if (prefix[0] == '\0') {
    die ("Invalid prefix");
  }
  printf ("<h1>Results - %s</h1><br><br><br>",prefix);

  buffer = stringCreate(50);
  //Chromosome expression, if present
  LineStream ls;
  char* chrSignal=NULL;  
  stringPrintf(buffer, "ls -1 %s/BGRS/%s_chr*.bgr.gz 2> /dev/null", 
	       confp_get(Conf, "WEB_DATA_DIR"), 
	       prefix);
  ls = ls_createFromPipe(string(buffer));
  int countCol = 0;
  puts ("Expression signal: &nbsp;");
  fflush(stdout);
  while( chrSignal = ls_nextLine(ls)) {
	char* chrTmp = stringBetween( prefix, ".bgr.gz", chrSignal );
	chrTmp++;
    int flankingRegion = atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"));
	char* link = htmlLinker_generateLinkToGenomeBrowserAtUCSC(
        "hg18","vertebrate", "human", chrTmp, flankingRegion,
		50000000 + flankingRegion);
	printf ("[<a href=%s&hgt.customText=%s/BGRS/%s_%s.bgr.gz target='blank'>%s</a>]&nbsp;",
            link, confp_get(Conf, "WEB_DATA_LINK"), prefix, chrTmp, chrTmp); 
	if (countCol > 10) {
	  puts( "<BR>" );
	  countCol=0;
	}
	countCol++;
  }
  if( countCol==0) puts( "No data available yet" );
  ls_destroy(ls);
  puts ("<br><br>");
  puts ("For a definition of SPER, DASPER and RESPER see <a href=http://rnaseq.gersteinlab.org/fusionseq/>FusionSeq</a>");
  puts ("<br><br>");
  puts ("<br><table border=0 width=100% align=center cellpadding=10>");
  puts ("<tr align=left>");
  puts ("<th>SPER</th>");
  puts ("<th>DASPER</th>");
  puts ("<th>RESPER</th>");
  puts ("<th>Number of inter paired-end reads</th>");
  puts ("<th>Type</th>");
  puts ("<th>Genomic coordinates</th>");
  puts ("<th>Gene symbol</th>");
  puts ("<th>Description</th>");
  puts ("<th>Genomic coordinates</th>");
  puts ("<th>Gene symbol</th>");
  puts ("<th>Description</th>");
  puts ("<th></th>");
  puts ("</tr>");
  fflush(stdout);

  stringPrintf (buffer,"%s/%s.gfr", confp_get(Conf, "WEB_DATA_DIR"), prefix);
  gfr_init (string (buffer));
  int countElements = 0;
  while (currGE = gfr_nextEntry ()) {
    if (currGE->numInter < minNum) {
      continue;
    }
    if (strEqual (typeSelected,"all") || strEqual (currGE->fusionType,typeSelected) || 
	( strEqual(currGE->fusionType,"cis") && strEqual( typeSelected,"same") ) ||
	( strEqual(currGE->fusionType,"read-through") && strEqual( typeSelected,"same") ) ) {
      if (pos = strchr (currGE->descriptionTranscript1,'|')) {
        *pos = '\0';
      }
      if (pos = strchr (currGE->descriptionTranscript2,'|')) {
        *pos = '\0';
      }
      puts ("<tr>");
      printf ("<td align=left>%1.3f</td>\n",currGE->SPER);
      printf ("<td align=left>%1.3f</td>\n",currGE->DASPER);
      printf ("<td align=left>%1.3f</td>\n",currGE->RESPER);
      printf ("<td align=left>%d</td>\n",currGE->numInter);
      printf ("<td align=left>%s</td>\n",currGE->fusionType);
      printf ("<td align=left><a href=%s target=blank>%s:%d-%d</a></td>\n",
              htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",
			currGE->chromosomeTranscript1,
			currGE->startTranscript1 - atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION")),
			currGE->endTranscript1 + atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"))),
     	      currGE->chromosomeTranscript1,currGE->startTranscript1,currGE->endTranscript1);
      printf ("<td align=left>%s</td>\n",processString (currGE->geneSymbolTranscript1));
      printf ("<td align=left>%s</td>\n",currGE->descriptionTranscript1);
      printf ("<td align=left><a href=%s target=blank>%s:%d-%d</a></td>\n",
              htmlLinker_generateLinkToGenomeBrowserAtUCSC ("hg18","vertebrate","human",
		     	currGE->chromosomeTranscript2,
			currGE->startTranscript2 - atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION")),
			currGE->endTranscript2 + atoi(confp_get(Conf, "UCSC_GENOME_BROWSER_FLANKING_REGION"))),
              currGE->chromosomeTranscript2,currGE->startTranscript2,currGE->endTranscript2);
      printf ("<td align=left>%s</td>\n",processString (currGE->geneSymbolTranscript2));
      printf ("<td align=left>%s</td>\n",currGE->descriptionTranscript2);
      printf ("<td align=left><a href=%s/showDetails_cgi?%s+%s>Details</a></td>\n", confp_get(Conf, "WEB_URL_CGI"), prefix,currGE->id);
      puts ("</tr>");
      countElements++;
    }
  }
  gfr_deInit ();
  stringDestroy (buffer);
  puts ("</table><br><br>");
  if( countElements == 0) puts("No fusion candidates can be found satisfying all specified criteria.");
  puts ("</body>");
  puts ("</html>");
  fflush (stdout);
}
コード例 #7
0
int main (int argc, char *argv[])
{
  GfrEntry *currGE;
  BLEntry *currBLE;
  BLEntry currQuery;
  FILE *fp;
  char *line;
  int count;
  int countRemoved;
  
  int index;
  WordIter w;
  Array blackList = arrayCreate(20, BLEntry);
  config *Conf;

  if ((Conf = confp_open(getenv("FUSIONSEQ_CONFPATH"))) == NULL) {
    die("%s:\tCannot find .fusionseqrc: %s", argv[0], getenv("FUSIONSEQ_CONFPATH"));
    return EXIT_FAILURE;
  }
  if( confp_get( Conf, "ANNOTATION_DIR")==NULL ) {
    die("%s:\tCannot find ANNOTATION_DIR in the configuration file: %s)", argv[0], getenv("FUSIONSEQ_CONFPATH") );
    return EXIT_FAILURE;
  }
  if( confp_get( Conf, "BLACKLIST_FILENAME")==NULL ) {
    die("%s:\tCannot find BLACKLIST_FILENAME in the configuration file: %s)", argv[0], getenv("FUSIONSEQ_CONFPATH") );
    return EXIT_FAILURE;
  }
  Stringa buffer=stringCreate( 100 );
  stringPrintf( buffer, "%s/%s", confp_get( Conf, "ANNOTATION_DIR"), confp_get( Conf, "BLACKLIST_FILENAME") );
  /*  fp = fopen( string( buffer ), "r" );
  if( !fp )  die("Unable to open file: %s", string(buffer));
  stringDestroy( buffer );
  */ 
// reading blacklist file
  LineStream ls = ls_createFromFile( string(buffer) );
  while( line = ls_nextLine(ls) ) {
    w = wordIterCreate( line, "\t", 1);
    currBLE = arrayp( blackList, arrayMax(blackList), BLEntry);
    currBLE->gene1 = hlr_strdup ( wordNext(w) );
    currBLE->gene2 = hlr_strdup ( wordNext(w) );    
    wordIterDestroy(w);
  }
  //fclose(fp);
  ls_destroy( ls );
  stringDestroy( buffer );
  arraySort( blackList, (ARRAYORDERF) sortBlackListByName1);

  // beginFiltering
  count = 0;
  countRemoved = 0;
  gfr_init ("-");
  puts (gfr_writeHeader ());
  while (currGE = gfr_nextEntry ()) { // reading the gfr
    if( currGE->geneSymbolTranscript1 == NULL ) {
      die("Gene symbols are not present in the GFR file. Please run gfrAddInfo before gfrBlackListFilter.");
      return EXIT_FAILURE;
    }
	
    // creating a new query to the black list
    currQuery.gene1 = currGE->geneSymbolTranscript1;
    currQuery.gene2 = currGE->geneSymbolTranscript2;
    if( strEqual( currQuery.gene1 , currQuery.gene2 ) ) {
	countRemoved++;
	continue;
      }
    // searching against read_1/read_2
    int res = arrayFind( blackList, &currQuery, 
			 &index,  (ARRAYORDERF) sortBlackListByName1);  
    
    if( !res ) { // not found, then searching against read_2/read_1
      currQuery.gene1 = currGE->geneSymbolTranscript2;
      currQuery.gene2 = currGE->geneSymbolTranscript1;
      
      res =  arrayFind( blackList, &currQuery, 
			&index, (ARRAYORDERF) sortBlackListByName1 );
      
      if( !res ) { // not found, write the instance to stdout, update the counts
	puts (gfr_writeGfrEntry (currGE));
	count++;	
      } else { // found: read2/read1
	countRemoved++;
      }	
    } else { //found: read1/read2
      countRemoved++;
    }
  }	           
  gfr_deInit ();
  arrayDestroy( blackList );
  warn ("%s_BlackListFilter: %s",argv[0], confp_get( Conf, "BLACKLIST_FILENAME"));
  warn ("%s_numRemoved: %d",argv[0],countRemoved);
  warn ("%s_numGfrEntries: %d",argv[0],count);
  confp_close( Conf);
  return 0;
}
コード例 #8
0
ファイル: cmdline.c プロジェクト: nilqed/aldor
local int
cmdDoOptDeveloper(String arg)
{
	int	rc = 0;
 
	if (!arg[0])
		rc = -1;
 
	if (strAEqual("trap", arg)) {
		cmdTrapFlag = true;
	}
	else if (strAEqual("check", arg)) {
		_dont_assert = false;	   /* Test assertions. */
		stoCtl(StoCtl_Wash, true); /* Initialize of store. */
	}
	else if (strAEqual("no-fatal", arg))
		_fatal_assert = false;	   /* Make assertions non-fatal. */
	else if (strAEqual("runtime", arg))
		genSetRuntime();
	else if (strEqual("debug", arg))
		genSetDebugWanted(true);
	else if (strEqual("debugger", arg))
		genSetDebuggerWanted(true);
	else if (strEqual("depend", arg))
		emitSetDependsWanted(true);
	else if (strEqual("small-hcodes", arg))
		genSetSmallHashCodes(true);
	else if (strEqual("lazy-catch", arg))
		gfSetLazyCatch(true);
	else if (strEqual("dumb-import", arg))
		stabSetDumbImport(true);
	else if (strEqual("trace-cfuns", arg))
		gencSetTraceFuns(true);
	else if (strEqual("no-where", arg))
		NoWhereHack = true;
	else if (strAEqual("runtime-hashcheck", arg))
		genSetHashcheck();
	else if (strAIsPrefix("keyword", arg)) {
		String darg = cmdDGetOptArg(arg, "keyword", NULL);
		cmdDoKeywordStatus(darg, true);
	}
	else if (strAIsPrefix("no-keyword", arg)) {
		String darg = cmdDGetOptArg(arg, "no-keyword", NULL);
		cmdDoKeywordStatus(darg, false);
	}
	else if (strEqual("no-negated-tests", arg))
		jflowSetNegate(false);
	else if (strAEqual("audit", arg))
		foamAuditSetAll();
	else if (strAEqual("nhash", arg))
		genSetAxiomAx(true);
	else if (strAEqual("missing-ok", arg))
		tiSetSoftMissing(true);
	else if (strAEqual("sexpr", arg)) {
		cmdSExprFlag = true;
	}
	else if (strAEqual("seval", arg)) {
		cmdSEvalFlag = true;
	}
	else if (strAEqual("no-gc", arg)) {
		/* Handled already - no action need be taken here */
	}
	else if (strAEqual("gc", arg)) {
		/* Handled already - no action need be taken here */
		cmdGcFlag = true;
	}
	else if (strAEqual("gcfile", arg)) {
		/* Handled already - no action need be taken here */
		cmdGcFileFlag = true;
	}
	else if (strAEqual("loops", arg)) {
		optSetLoopOption();
	}
	else if (strAEqual("emerge-noalias", arg)) {
		emSetNoAlias();
	}
	else if (strAIsPrefix("test", arg)) {
		String darg = cmdDGetOptArg(arg, "test", NULL);
		testSelf(darg);
		exitSuccess();
	}
	else if (strAIsPrefix("rtcache", arg)) {
		String darg = cmdDGetOptArg(arg, "rtcache", NULL);
		long rtsize;
		extern void gen0SetRtCacheSize(AInt);

		sscanf(darg, "%ld", &rtsize);
		gen0SetRtCacheSize((AInt)rtsize);
	}
	else if (strAIsPrefix("D", arg)) {
		char	sep;
		String  darg = cmdDGetOptArg(arg, "D", &sep);
		rc   = cmdDDebug(darg, sep == '+');
	}
	else if (strAIsPrefix("T", arg)) {
		rc = phTraceOption(arg+strlen("T"));
	}
	else if (strAIsPrefix("name", arg)) {
		String darg = cmdDGetOptArg(arg, "name", NULL);
		emitSetFileIdName(darg);
	}
	else if (strAIsPrefix("prefix", arg)) {
		String darg = cmdDGetOptArg(arg, "prefix", NULL);
		emitSetFileIdPrefix(darg);
	}
	else if (strAEqual("floatrep", arg)) {
		cmdFloatRepFlag = true;
	}
	else
		rc = -1;

	return rc;
}
コード例 #9
0
ファイル: test_util.cpp プロジェクト: rusefi/rusefi
TEST(misc, testConsoleLogic) {
	print("******************************************* testConsoleLogic\r\n");
	resetConsoleActions();

	helpCommand();

	char * cmd = "he ha";
	ASSERT_EQ(2, findEndOfToken(cmd));

	cmd = "\"hee\" ha";
	ASSERT_EQ(5, findEndOfToken(cmd));

	cmd = "\"h e\" ha";
	ASSERT_EQ(5, findEndOfToken(cmd));

	strcpy(buffer, "echo");
	ASSERT_TRUE(strEqual("echo", unquote(buffer)));

	strcpy(buffer, "\"echo\"");
	ASSERT_TRUE(strEqual("echo", unquote(buffer))) << "unquote quoted";

	char *ptr = validateSecureLine(UNKNOWN_COMMAND);
	ASSERT_EQ(0, strcmp(UNKNOWN_COMMAND, ptr));
	ASSERT_EQ(10, tokenLength(UNKNOWN_COMMAND));

	// handling invalid token should work
	strcpy(buffer, "sdasdafasd asd");
	handleConsoleLine(buffer);

	print("\r\naddConsoleActionI\r\n");
	addConsoleActionI("echoi", testEchoI);
	strcpy(buffer, "echoi 239");
	handleConsoleLine(buffer);
	ASSERT_EQ(239, lastInteger);

	print("\r\naddConsoleActionI 240 with two spaces\r\n");
	strcpy(buffer, "echoi  240");
	handleConsoleLine(buffer);
	ASSERT_EQ(240, lastInteger);


	print("\r\naddConsoleActionII\r\n");
	addConsoleActionII("echoii", testEchoII);
	strcpy(buffer, "echoii 22 239");
	handleConsoleLine(buffer);
	ASSERT_EQ(22, lastInteger);
	ASSERT_EQ(239, lastInteger2);

	print("\r\naddConsoleActionII three spaces\r\n");
	strcpy(buffer, "echoii   21   220");
	handleConsoleLine(buffer);
	ASSERT_EQ(21, lastInteger);
	ASSERT_EQ(220, lastInteger2);

	print("\r\addConsoleActionSSS\r\n");
	addConsoleActionSSS("echosss", testEchoSSS);
	strcpy(buffer, "echosss 111 222 333");
	handleConsoleLine(buffer);
	ASSERT_EQ(111, atoi(lastFirst));
	ASSERT_EQ(333, atoi(lastThird));

	strcpy(buffer, "echosss \" 1\" 222 333");
	handleConsoleLine(buffer);
	ASSERT_TRUE(strEqual("\" 1\"", lastFirst));

	//addConsoleActionSSS("GPS", testGpsParser);
}
コード例 #10
0
ファイル: executor.c プロジェクト: nighca/lang
int calc(Vnode* expr, VM* vm, Contexts* contexts, Method** methods){
	// Already calculated
	if(expr->obj){
		return 0;
	}

	// Variable
	if(expr->name){
		if(strEqual(expr->name, "assign") || strEqual(expr->name, "$") || strEqual(expr->name, "lamda")){
			expr->isMethod = true;
		}else{
			for(int i = 0; methods[i]; i++){
				if(strEqual(expr->name, methods[i]->name)){
					expr->isMethod = true;
					break;
				}
			}
		}

		if(!expr->isMethod){
			expr->obj = findFromContexts(contexts, expr->name);
			assert(expr->obj, "Error: %s not defined!", expr->name);
		}
	}

	// Calculate
	if(expr->childrenNum){
		calc(expr->children[0], vm, contexts, methods);

		Vnode* firstNode = expr->children[0];
		int argNum = expr->childrenNum - 1;

		printf("====================== Calc =======================\n");
		printf("Calc: %s \n", firstNode->name);
		printContexts(contexts);
		printf("End : %s\n", firstNode->name);

		// Native method
		if(firstNode->isMethod){
			if(strEqual(firstNode->name, "assign") || strEqual(firstNode->name, "$")){
				assert(argNum == 2 && expr->children[1]->name, "Error: Wrong arguments for def!");

				char* key = expr->children[1]->name;
				calc(expr->children[2], vm, contexts, methods);
				Object* value = expr->children[2]->obj;
				Context* curr = getTopContext(contexts);

				defineInContext(curr, key, value);
			}else if(strEqual(firstNode->name, "lamda")){
				expr->obj = pushLamda(vm, expr->node);
				expr->obj->lamdaId = lamdaNum;
				lamdaContexts[lamdaNum] = copyContexts(contexts, NULL);
				lamdaNum++;
			}else{
				for(int i = 0; methods[i]; i++){
					if(strEqual(firstNode->name, methods[i]->name)){
						Object** args = malloc(sizeof(Object*) * argNum);
						for(int i = 0; i < argNum; i++){
							calc(expr->children[i+1], vm, contexts, methods);
							args[i] = cloneObject(vm, expr->children[i+1]->obj);
						}
						expr->obj = methods[i]->callee(argNum, args, vm);
						break;
					}
				}
			}
			return 0;
		}

		Object* firstVal = firstNode->obj;

		// First value
		if(firstVal->type != OBJ_LAMDA){
			expr->obj = cloneObject(vm, firstVal);
			return 0;
		}

		// Lamda call
		// get args
		Contexts* cxts = copyContexts(lamdaContexts[firstVal->lamdaId], NULL);
		Context* runCxt = newContext();
		for(int i = 0; i < argNum; i++){
			calc(expr->children[i+1], vm, contexts, methods);
			defineInContext(runCxt, firstVal->args[i], cloneObject(vm, expr->children[i+1]->obj));
		}
		pushContext(cxts, runCxt);
		Vnode* vn = getVnode(firstVal->grammarTree->root, vm);
		calc(vn, vm, cxts, methods);
		expr->obj = vn->obj;

		return 0;
	}

	return 0;
}
コード例 #11
0
ファイル: cgi.c プロジェクト: Accio/ribios
int myStrEqual(char* a, char* b) {
  return strEqual(a, b);
}