// -------------------------------------------------------------------------
// QueryInfo Class :: inRange() - match check having a range
// -------------------------------------------------------------------------
IBase :: Boolean QueryInfo :: inRange(const IString &c1
                                     ,const IString &c2
                                     ,const IString &range)
{

   if (c2.length() == 0)
      return false;

    IString matchItem, compareItem;

    matchItem   = chopOff(c1);
    compareItem = chopOff(c2);

   if ( (c1.isDigits()) && (c2.isDigits()) ) {
      // compare 2 numbers
      long d1=c1.asInt();
      long d2=c2.asInt();
      return compareIt(d1, d2, range);
   }
   else {
      ADate *date1 = new ADate(c1);
      ADate *date2 = new ADate(c2);
      return compareIt(date1, date2, range);
   } /* endif */

};
Ejemplo n.º 2
0
struct hash *makeProbeBed(char *inGff, char *outBed)
/* Convert probe location GFF file to BED. */
{
struct lineFile *lf = lineFileOpen(inGff, TRUE);
char *row[9];
struct hash *hash = newHash(16);
FILE *f = mustOpen(outBed, "w");
while (lineFileNextRowTab(lf, row, ArraySize(row)))
    {
    int chromIx = romanToArabicChrom(row[0], lf);
    int start = lineFileNeedNum(lf, row, 3) - 1;
    int end = lineFileNeedNum(lf, row, 4);
    char *s = row[8];
    char *probe, *orf, *note; 
    char *boundAt = "Bound at ";
    struct tfBinding *tfbList = NULL, *tfb;
    if (!startsWith("Probe ", s))
        errAbort("Expecting 9th column to start with 'Probe ' line %d of %s",
		lf->lineIx, lf->fileName);
    probe = nextWord(&s);
    orf = nextWord(&s);
    chopOff(orf, ';');
    note = nextWord(&s);
    if (!sameWord("Note", note))
        errAbort("Expecting 'note' in 9th column line %d of %s", 
		lf->lineIx, lf->fileName);
    s = skipLeadingSpaces(s);
    if (!parseQuotedString(s, s, NULL))
        errAbort("Expecting quoted string in 9th column line %d of %s",
		lf->lineIx, lf->fileName);
    if (startsWith("Bad Probe", s))
        continue;
    else if (startsWith("Not bound", s))
        {
	/* Ok, we do nothing. */
	}
    else if (startsWith(boundAt, s))
	{
	while (s != NULL && startsWith(boundAt, s))
	    {
	    char *word, *by;
	    double binding;
	    s += strlen(boundAt);
	    word = nextWord(&s);
	    binding = atof(word);
	    by = nextWord(&s);
	    if (!sameString("by:", by))
	        errAbort("Expecting by: line %d of %s", lf->lineIx, lf->fileName);
	    while ((word = nextWord(&s)) != NULL)
		{
		char lastChar = 0, *e;
		e = word + strlen(word) - 1;
		lastChar = *e;
		if (lastChar == ';' || lastChar == ',')
		     *e = 0;
		AllocVar(tfb);
		tfb->binding = binding;
		tfb->tf = cloneString(word);
		slAddHead(&tfbList, tfb);
		if (lastChar == ';')
		     break;
		}
	    s = skipLeadingSpaces(s);
	    }
	slReverse(&tfbList);
	}
    else
        {
	errAbort("Expecting %s in note line %d of %s", boundAt, 
		lf->lineIx, lf->fileName);
	}
    fprintf(f, "chr%d\t%d\t%d\t", chromIx+1, start, end);
    fprintf(f, "%s\t%d\t", orf, slCount(tfbList));
    for (tfb = tfbList; tfb != NULL; tfb = tfb->next)
	fprintf(f, "%s,", tfb->tf);
    fprintf(f, "\t");
    for (tfb = tfbList; tfb != NULL; tfb = tfb->next)
        fprintf(f, "%4.3f,", tfb->binding);
    fprintf(f, "\n");
    hashAdd(hash, orf, NULL);
    }
lineFileClose(&lf);
carefulClose(&f);
return hash;
}