Пример #1
0
AjPPatternSeq ajPatternSeqNewList (AjPPatlistSeq plist,
				   const AjPStr name, const AjPStr pat,
				   ajuint mismatch)
{
    AjPPatternSeq pthis;

    if (!ajStrGetLen(pat))
	return NULL;

    AJNEW0(pthis);

    if(ajStrGetLen(name))
	ajStrAssignS (&pthis->Name,name);
    else
	ajFmtPrintS(&pthis->Name, "pattern%d",
		    1+ajListGetLength(plist->Patlist));

    ajStrAssignS(&pthis->Pattern,pat);
    pthis->Protein  = plist->Protein;
    pthis->Mismatch = mismatch;

    ajPatlistAddSeq(plist,pthis);

    return pthis;
}
Пример #2
0
static void jaspscan_GetFileList(const AjPStr dir, const AjPStr jaspdir,
				 const char *wild, AjPList list)
{
    AjPList tlist = NULL;
    AjPStr jdir = NULL;
    AjPStr wstr = NULL;
    AjPStr str  = NULL;
    
    tlist = ajListNew();
    jdir  = ajStrNew();
    wstr  = ajStrNew();
    

    ajFmtPrintS(&jdir,"%S%S",dir,jaspdir);
    if(!ajDirnameFixExists(&jdir))
	ajFatal("EMBOSS_DATA undefined or 'jaspextract' needs to be run");

    ajFmtPrintS(&wstr,"%s%s",wild,J_EXT);

    ajFilelistAddPathWild(tlist,jdir,wstr);

    if(!ajListGetLength(tlist))
	ajWarn("Matrix file(s) %S not found",wstr);

    while(ajListPop(tlist,(void **)&str))
	ajListPushAppend(list,(void *)str);

    ajStrDel(&wstr);
    ajStrDel(&jdir);

    ajListFree(&tlist);

    return;
}
Пример #3
0
AjPPatternRegex ajPatternRegexNewList(AjPPatlistRegex plist,
				      const AjPStr name,
				      const AjPStr pat)
{
    AjPPatternRegex pthis;

    if (!ajStrGetLen(pat))
	return NULL;

    AJNEW0(pthis);

    if(ajStrGetLen(name))
	ajStrAssignS (&pthis->Name,name);
    else
	ajFmtPrintS(&pthis->Name, "regex%d",
		    1+ajListGetLength(plist->Patlist));

    ajStrAssignS  (&pthis->Pattern,pat);
    pthis->Type = plist->Type;

    pthis->Compiled = ajRegComp(pthis->Pattern);
    ajPatlistAddRegex (plist,pthis);

    return pthis;
}
Пример #4
0
static void remap_RemoveMinMax(AjPList restrictlist,
	AjPTable hittable, ajint mincuts, ajint maxcuts)
{

    AjIList miter;		/* iterator for matches list */
    EmbPMatMatch m = NULL;	/* restriction enzyme match structure */
    PValue value;
    AjPStr key  = NULL;
    AjPStr keyv = NULL;


    key = ajStrNew();

    /* if no hits then ignore much of this routine */
    if(ajListGetLength(restrictlist))
    {
        /* count the enzymes */
	miter = ajListIterNewread(restrictlist);
	while((m = ajListIterGet(miter)) != NULL)
	{
	    ajStrAssignS(&key, m->cod);

	    /* increment the count of key */
	    value = (PValue) ajTableFetchmodS(hittable, key);
	    if(value == NULL)
	    {
		AJNEW0(value);
		value->count = 1;
		value->iso = ajStrNew();
		ajStrAssignS(&(value->iso), m->iso);
		keyv = ajStrNew();
		ajStrAssignS(&keyv,key);
		ajTablePut(hittable, (void *)keyv, (void *)value);
	    }
	    else
		value->count++;
	}
	ajListIterDel(&miter);


	/* now remove enzymes from restrictlist if <mincuts | >maxcuts */
	miter = ajListIterNew(restrictlist);
	while((m = ajListIterGet(miter)) != NULL)
	{
	    value = (PValue) ajTableFetchmodS(hittable, (m->cod));
            if(value->count < mincuts || value->count > maxcuts)
	    {
            	ajListIterRemove(miter);
                embMatMatchDel(&m);
            }
	}
	ajListIterDel(&miter);
    }

    ajStrDel(&key);

    return;
}
Пример #5
0
void ajPatlistAddRegex (AjPPatlistRegex thys, AjPPatternRegex pat)
{
    ajDebug ("ajPatlistAddRegex list size %d '%S' '%S' '%d'\n",
             ajListGetLength (thys->Patlist), pat->Name,
             pat->Pattern, pat->Type);
    ajListPushAppend(thys->Patlist, pat);

    return;
}
Пример #6
0
void ajPatlistAddSeq (AjPPatlistSeq thys, AjPPatternSeq pat)
{
    ajDebug ("ajPatlistAddSeq list size %d '%S' '%S' '%B' '%d'\n",
             ajListGetLength (thys->Patlist), pat->Name,
             pat->Pattern, pat->Protein, pat->Mismatch);
    ajListPushAppend(thys->Patlist, pat);

    return;
}
Пример #7
0
AjBool ensCacheTrace(const EnsPCache cache, ajuint level)
{
    double ratio = 0.0;

    AjPStr indent = NULL;

    if(!cache)
        return ajFalse;

    indent = ajStrNew();

    ajStrAppendCountK(&indent, ' ', level * 2);

    if(cache->Hit || cache->Miss)
        ratio = (double) cache->Hit /
            ((double) cache->Hit + (double) cache->Miss);

    ajDebug("%SensCache trace %p\n"
            "%S  Label '%S'\n"
            "%S  List %p length: %u\n"
            "%S  Table %p length: %u\n"
            "%S  Type %d\n"
            "%S  Synchron %B\n"
            "%S  MaxBytes %u\n"
            "%S  MaxCount %u\n"
            "%S  MaxSize %u\n"
            "%S  Bytes %u\n"
            "%S  Count %u\n"
            "%S  Dropped %u\n"
            "%S  Removed %u\n"
            "%S  Stored %u\n"
            "%S  Hit %u\n"
            "%S  Miss %u\n"
            "%S  Hit/(Hit + Miss) %f\n",
            indent, cache,
            indent, cache->Label,
            indent, cache->List, ajListGetLength(cache->List),
            indent, cache->Table, ajTableGetLength(cache->Table),
            indent, cache->Type,
            indent, cache->Synchron,
            indent, cache->MaxBytes,
            indent, cache->MaxCount,
            indent, cache->MaxSize,
            indent, cache->Bytes,
            indent, cache->Count,
            indent, cache->Dropped,
            indent, cache->Removed,
            indent, cache->Stored,
            indent, cache->Hit,
            indent, cache->Miss,
            indent, ratio);

    ajStrDel(&indent);

    return ajTrue;
}
Пример #8
0
int main(int argc, char **argv)
{
    AjPSeqall seqall;
    AjPSeq seq = NULL;
    AjPFile primerFile;		  /* read the primer pairs from a file */
    AjPFile outf;
    AjPList primerList;

    ajint mmp = 0;

    embInit("primersearch", argc, argv);

    seqall     = ajAcdGetSeqall("seqall");
    outf       = ajAcdGetOutfile("outfile");
    primerFile = ajAcdGetInfile("infile");
    mmp        = ajAcdGetInt("mismatchpercent");

    /* build list of forward/reverse primer pairs as read from primerfile */
    primerList = ajListNew();

    /* read in primers from primerfile, classify and compile them */
    primersearch_read_primers(&primerList,primerFile, mmp);

    /* check there are primers to be searched */
    if(!ajListGetLength(primerList))
    {
	ajErr("No suitable primers found - exiting");
	embExitBad();
	return 0;

    }

    /* query sequences one by one */
    while(ajSeqallNext(seqall,&seq))
	primersearch_primer_search(primerList, seq);

    /* output the results */
    primersearch_print_hits(primerList, outf);

    /* delete all nodes of list, then the list itself */
    ajListMap(primerList, primersearch_free_primer, NULL);
    ajListFree(&primerList);
    ajListFree(&primerList);

    ajFileClose(&outf);

    ajSeqallDel(&seqall);
    ajSeqDel(&seq);

    ajFileClose(&primerFile);

    embExit();

    return 0;
}
Пример #9
0
ajuint ajPatlistRegexDoc (AjPPatlistRegex plist, AjPStr* Pdoc)
{
    AjPPatternRegex pat = NULL;

    ajFmtPrintS(Pdoc, "%-12S %S\n", "Pattern_name", "Pattern");

    while (ajPatlistRegexGetNext(plist, &pat))
	ajFmtPrintAppS(Pdoc, "%-12S %S\n",
		       ajPatternRegexGetName(pat),
		       ajPatternRegexGetPattern(pat));

    return ajListGetLength(plist->Patlist);
}
Пример #10
0
ajuint ajPatlistSeqDoc (AjPPatlistSeq plist, AjPStr* Pdoc)
{
    AjPPatternSeq pat = NULL;

    ajFmtPrintS(Pdoc, "%-12s %8s %s\n",
		   "Pattern_name", "Mismatch", "Pattern");
    while (ajPatlistSeqGetNext(plist, &pat))
    {
	ajFmtPrintAppS(Pdoc, "%-12S %8d %S\n",
		       ajPatternSeqGetName(pat),
		       ajPatternSeqGetMismatch(pat),
		       ajPatternSeqGetPattern(pat));
    }
    return ajListGetLength(plist->Patlist);
}
Пример #11
0
static void dastestSaveMappedFeatures(const AjPFeattable fttable,
                                      const AjPStr ffname,
                                      AjPFile outf, ajint maxfeatures)
{
    AjPFeature feature  = NULL;
    AjIList iterfts     = NULL;
    AjPFeattabOut ftout = NULL;
    AjPFile ffile = NULL;
    AjPStr ffnamee = ajStrNew();

    ajint i=0;

    if (fttable == NULL)
    {
	ajWarn("null feature table, %S", ffname);
	return;
    }

    ajFmtPrintS(&ffnamee, "%S.mapped.dasgff", ffname);
    ffile = ajFileNewOutNameS(ffnamee);

    iterfts = ajListIterNew(fttable->Features);
    ftout= ajFeattabOutNewCSF("gff3",NULL,"",ffile);

    ajFmtPrintF(outf, "Number of features %d\n",
	    ajListGetLength(fttable->Features));

    while(!ajListIterDone(iterfts) && i++ < maxfeatures)
    {
	feature = ajListIterGet(iterfts);
	ajFmtPrintF(outf,
		"feature id:%S orientation:%c start:%d stop:%d\n",
		feature->Label,
		feature->Strand,
		feature->Start, feature->End);
    }

    ajListIterDel(&iterfts);

    ajFeattableWriteDasgff(ftout, fttable);

    ajFeattabOutDel(&ftout);
    ajFileClose(&ffile);
    ajStrDel(&ffnamee);

    return;
}
Пример #12
0
static AjPTable dastestGetTitleCount(const AjPDasServer server)
{
    AjIList iter  = NULL;

    AjPTable titlecount = NULL;
    AjPDasSource source = NULL;

    AjPStr title = NULL;

    ajuint* count = NULL;

    titlecount = ajTablestrNewCaseConst(ajListGetLength(server->sources)+20);


    iter = ajListIterNew(server->sources);

    while(!ajListIterDone(iter))
    {
	source = ajListIterGet(iter);

	title = source->title;

	count = ajTableFetchmodS(titlecount,title);

	if (count != NULL)
        {
	    (*count)++;
        }
	else
	{
	    AJNEW(count);
	    *count = 1;
            ajTablePut(titlecount, title, (void*)count);
	}

    }

    ajListIterDel(&iter);

    return titlecount;
}
Пример #13
0
AjBool ajResquerylistClone(const AjPList src, AjPList dest)
{
    AjIList iter;
    AjPResquery qryout = NULL;
    AjPResquery qryin = NULL;

    if(ajListGetLength(dest))
	return ajFalse;

    iter = ajListIterNewread(src);

    while ((qryin = (AjPResquery) ajListIterGet(iter)))
    {
	qryout = ajResqueryNewResquery(qryin);
	ajListPushAppend(dest, qryout);
    }

    ajListIterDel(&iter);

    return ajTrue;
}
Пример #14
0
AjBool ajRestermlistClone(const AjPList src, AjPList dest)
{
    AjIList iter;
    AjPResterm termout = NULL;
    AjPResterm termin = NULL;

    if(ajListGetLength(dest))
	return ajFalse;

    iter = ajListIterNewread(src);

    while ((termin = (AjPResterm) ajListIterGet(iter)))
    {
	termout = ajRestermNewResterm(termin);
	ajListPushAppend(dest, termout);
    }

    ajListIterDel(&iter);

    return ajTrue;
}
Пример #15
0
void ajPatlistRegexDel (AjPPatlistRegex* pthys)
{
    AjPPatlistRegex thys = NULL;
    AjPPatternRegex patternregex = NULL;

    thys = *pthys;

    while (ajListPop(thys->Patlist, (void **)&patternregex))
    {
	ajDebug("ajPatlistRegexDel list size: %d\n",
		ajListGetLength(thys->Patlist));
	ajPatternRegexDel(&patternregex);
    }

    if (thys->Iter)
	ajListIterDel(&thys->Iter);
    ajListFree(&thys->Patlist);

    AJFREE(*pthys);

    return;
}
Пример #16
0
static AjBool assemoutWriteNextBam(AjPOutfile outfile, const AjPAssem assem)
{
    AjPFile outf = ajOutfileGetFile(outfile);
    AjPSeqBamHeader header = NULL;
    AjPAssemContig c = NULL;
    AjPSeqBam bam;
    AjPAssemRead   r = NULL;
    AjPAssemContig* contigs = NULL;
    AjPAssemTag    t = NULL;
    AjIList j = NULL;
    AjPSeqBamBgzf gzfile = NULL;
    AjPStr headertext=NULL;
    const AjPStr rgheadertext=NULL;
    AjBool ret = ajTrue;
    ajint i=0;
    ajulong ncontigs=0UL;

    if(!outf) return ajFalse;
    if(!assem) return ajFalse;

    if(!assem->Hasdata)
    {
        if(ajListGetLength(assem->ContigsOrder))
            ncontigs = ajListToarray(assem->ContigsOrder, (void***)&contigs);
        else
            ncontigs = ajTableToarrayValues(assem->Contigs, (void***)&contigs);

        ajFmtPrintS(&headertext, "@HD\tVN:1.3\tSO:%s\n",
                    ajAssemGetSortorderC(assem));
        header = ajSeqBamHeaderNewN((ajuint) ncontigs);

        gzfile = ajSeqBamBgzfNew(ajFileGetFileptr(outf), "w");
        outfile->OutData = gzfile;

        while (contigs[i])   /* contigs */
        {
            c = contigs[i];

            if(ajStrMatchC(c->Name, "*"))
            {
                i++;
                continue;
            }

            header->target_name[i] = strdup(ajStrGetPtr(c->Name));
            header->target_len[i++] = c->Length;

            ajFmtPrintAppS(&headertext, "@SQ\tSN:%S\tLN:%d",
                           c->Name, c->Length);

            if(c->URI)
                ajFmtPrintAppS(&headertext, "\tUR:%S", c->URI);

            if(c->MD5)
                ajFmtPrintAppS(&headertext, "\tM5:%S", c->MD5);

            if(c->Species)
                ajFmtPrintAppS(&headertext, "\tSP:%S", c->Species);

            ajFmtPrintAppS(&headertext, "\n");


            j = ajListIterNewread(c->Tags);
            while (!ajListIterDone(j))
            {
                t = ajListIterGet(j);
                ajFmtPrintAppS(&headertext,
                               "@CO\t%S %u %u %S\n", t->Name, t->x1, t->y1,
                               t->Comment);
            }
            ajListIterDel(&j);
        }

        rgheadertext = assemSAMGetReadgroupHeaderlines(assem);
        if(rgheadertext)
            ajStrAppendS(&headertext, rgheadertext);

        ajSeqBamHeaderSetTextC(header, ajStrGetPtr(headertext));
        ajSeqBamHeaderWrite(gzfile, header);

        ajSeqBamHeaderDel(&header);
        ajStrDel(&headertext);

        AJFREE(contigs);

        if(!assem->BamHeader)
            return ajTrue;
    }

    /* data */

    gzfile = outfile->OutData;

    AJNEW0(bam);
    bam->m_data=10;
    AJCNEW0(bam->data, bam->m_data);

    j = ajListIterNewread(assem->Reads);

    while (!ajListIterDone(j))  /* reads */
    {
	r = ajListIterGet(j);
	assemoutWriteBamAlignment(gzfile, r, bam);
    }

    ajListIterDel(&j);

    AJFREE(bam->data);
    AJFREE(bam);

    /* ajSeqBamBgzfClose(gzfile);*/

    return ret;
}
Пример #17
0
int main(int argc, char **argv)
{
    AjPSeqall seqall;
    AjPSeq seq   = NULL;
    AjPReport report = NULL;

    AjPStr jaspdir = NULL;
    AjPStr menu    = NULL;
    AjPStr substr  = NULL;
    AjPStr mats    = NULL;
    AjPStr excl    = NULL;

    float thresh = 0.;
    
    ajuint recurs  = 0;
    
    AjPStr dir    = NULL;
    AjPStr mfname = NULL;
    
    AjPList flist = NULL;
    AjPList hits  = NULL;

    AjPStr head   = NULL;
    
    
    ajint begin;
    ajint end;
    ajuint mno;
    
    char cp;
    ajuint i;
    AjPTable mattab = NULL;
    AjPFeattable TabRpt = NULL;
    AjBool both = ajFalse;
    

    embInit("jaspscan", argc, argv);

    seqall     = ajAcdGetSeqall("sequence");
    menu       = ajAcdGetListSingle("menu");
    mats       = ajAcdGetString("matrices");
    excl       = ajAcdGetString("exclude");
    thresh     = ajAcdGetFloat("threshold");
    report     = ajAcdGetReport("outfile");
    both       = ajAcdGetBoolean("both");
    
    jaspdir = ajStrNew();
    substr  = ajStrNew();
    
    flist = ajListNew();
    hits  = ajListNew();
    dir   = ajStrNew();
    head  = ajStrNew();
    
    cp = ajStrGetCharFirst(menu);

    if(cp=='C')
	ajStrAssignC(&jaspdir,J_COR);
    else if(cp=='F')
	ajStrAssignC(&jaspdir,J_FAM);
    else if(cp=='P')
	ajStrAssignC(&jaspdir,J_PHY);
    else if(cp=='N')
	ajStrAssignC(&jaspdir,J_CNE);
    else if(cp=='O')
	ajStrAssignC(&jaspdir,J_POL);
    else if(cp=='S')
	ajStrAssignC(&jaspdir,J_SPL);
    else
	ajFatal("Invalid JASPAR database selection");


    ajStrAssignS(&dir, ajDatafileValuePath());
    if(!ajStrGetLen(dir))
	ajFatal("EMBOSS DATA directory couldn't be determined");


    jaspscan_ParseInput(dir, jaspdir, mats, excl, &recurs, flist);
    mno = ajListGetLength(flist);


    if(cp == 'C')
	mattab = jaspscan_ReadCoreList(jaspdir);
    if(cp == 'F')
	mattab = jaspscan_ReadFamList(jaspdir);
    if(cp == 'P')
	mattab = jaspscan_ReadCoreList(jaspdir);
    if(cp == 'N')
	mattab = jaspscan_ReadCoreList(jaspdir);
    if(cp == 'O')
	mattab = jaspscan_ReadCoreList(jaspdir);
    if(cp == 'S')
	mattab = jaspscan_ReadCoreList(jaspdir);

    ajFmtPrintS(&head,"Database scanned: %S  Threshold: %.3f",jaspdir,thresh);
    ajReportSetHeaderS(report,head);
    
    while(ajSeqallNext(seqall, &seq))
    {
	begin  = ajSeqallGetseqBegin(seqall);
	end    = ajSeqallGetseqEnd(seqall);

	ajStrAssignSubC(&substr,ajSeqGetSeqC(seq),begin-1,end-1);
	ajStrFmtUpper(&substr);

	TabRpt = ajFeattableNewSeq(seq);


	for(i=0; i < mno; ++i)
	{
	    ajListPop(flist,(void **)&mfname);

	    jaspscan_scan(substr,begin,mfname, cp, thresh, both, hits);

            ajListPushAppend(flist, (void **)mfname);
	}

	jaspscan_ReportHits(TabRpt,mattab,hits);

	ajReportWrite(report, TabRpt, seq);
	ajFeattableDel(&TabRpt);
    }


    while(ajListPop(flist,(void **)&mfname))
        ajStrDel(&mfname);

    
    ajStrDel(&dir);
    ajStrDel(&menu);
    ajStrDel(&excl);
    ajStrDel(&substr);
    ajStrDel(&mats);
    ajStrDel(&head);
    ajStrDel(&jaspdir);

    ajSeqDel(&seq);

    ajTableMapDel(mattab,jaspscan_ClearTable,NULL);
    ajTableFree(&mattab);

    ajListFree(&flist);
    ajListFree(&hits);
    
    ajSeqallDel(&seqall);
    ajReportDel(&report);
    
    embExit();

    return 0;
}
Пример #18
0
void ajResourceClear(AjPResource resource)
{
    AjPReslink lnk = NULL;
    AjPResquery qry = NULL;
    AjPResterm resterm = NULL;
    AjPStr ptr = NULL;

    if(MAJSTRGETLEN(resource->Id))
       ajStrSetClear(&resource->Id);

    if(ajListGetLength(resource->Idalt)) 
        while(ajListstrPop(resource->Idalt,&ptr))
            ajStrDel(&ptr);

    if(MAJSTRGETLEN(resource->Acc))
       ajStrSetClear(&resource->Acc);

    if(MAJSTRGETLEN(resource->Name))
       ajStrSetClear(&resource->Name);

    if(MAJSTRGETLEN(resource->Desc))
       ajStrSetClear(&resource->Desc);

    if(MAJSTRGETLEN(resource->Url))
       ajStrSetClear(&resource->Url);

    if(MAJSTRGETLEN(resource->Urllink))
       ajStrSetClear(&resource->Urllink);

    if(MAJSTRGETLEN(resource->Urlrest))
       ajStrSetClear(&resource->Urlrest);

    if(MAJSTRGETLEN(resource->Urlsoap))
       ajStrSetClear(&resource->Urlsoap);

    if(ajListGetLength(resource->Cat))
        while(ajListstrPop(resource->Cat,&ptr))
            ajStrDel(&ptr);

    if(ajListGetLength(resource->Taxon))
        while(ajListPop(resource->Taxon,(void**)&resterm))
            ajRestermDel(&resterm);

    if(ajListGetLength(resource->Edamdat))
        while(ajListPop(resource->Edamdat,(void**)&resterm))
            ajRestermDel(&resterm);

    if(ajListGetLength(resource->Edamfmt))
        while(ajListPop(resource->Edamfmt,(void**)&resterm))
            ajRestermDel(&resterm);

    if(ajListGetLength(resource->Edamid))
        while(ajListPop(resource->Edamid,(void**)&resterm))
            ajRestermDel(&resterm);

    if(ajListGetLength(resource->Edamtpc))
        while(ajListPop(resource->Edamtpc,(void**)&resterm))
            ajRestermDel(&resterm);

    if(ajListGetLength(resource->Xref))
        while(ajListPop(resource->Xref,(void**)&lnk))
            ajReslinkDel(&lnk);

    if(ajListGetLength(resource->Query))
        while(ajListPop(resource->Query,(void**)&qry))
            ajResqueryDel(&qry);

    if(ajListGetLength(resource->Example))
        while(ajListstrPop(resource->Example,&ptr))
            ajStrDel(&ptr);

    if(MAJSTRGETLEN(resource->Db))
       ajStrSetClear(&resource->Db);

    if(MAJSTRGETLEN(resource->Setdb))
       ajStrSetClear(&resource->Setdb);

    if(MAJSTRGETLEN(resource->Full))
       ajStrSetClear(&resource->Full);

    if(MAJSTRGETLEN(resource->Qry))
       ajStrSetClear(&resource->Qry);

    if(MAJSTRGETLEN(resource->Formatstr))
       ajStrSetClear(&resource->Formatstr);

    if(MAJSTRGETLEN(resource->Filename))
       ajStrSetClear(&resource->Filename);

    ajStrDel(&resource->TextPtr);

    resource->Count = 0;
    resource->Fpos = 0L;
    resource->Format = 0;

    return;
}
Пример #19
0
void ajResourceTrace(const AjPResource thys)
{
    AjIList iter;
    AjPStr tmpstr;
    ajuint i;
    AjPReslink reslink = NULL;
    AjPResquery resqry = NULL;
    AjPResterm resterm = NULL;
    if(!thys)
    {
        ajDebug("ajResourceTrace NULL\n");
        return;
    }

    ajDebug("\najResourceTrace\n");
    ajDebug("        Id: %S\n", thys->Id);
    ajDebug("       Acc: %S\n", thys->Acc);
    ajDebug("      Name: %S\n", thys->Name);
    ajDebug("      Desc: %S\n", thys->Desc);
    ajDebug("       Url: %S\n", thys->Url);

    ajDebug("     Idalt: %Lu\n", ajListGetLength(thys->Idalt));
    if(ajListGetLength(thys->Idalt))
    {
        i=0;
        iter = ajListIterNewread(thys->Idalt);
        while(!ajListIterDone(iter))
        {
            tmpstr = ajListIterGet(iter);
            ajDebug("%15d: %S\n", ++i, tmpstr);
        }
        ajListIterDel(&iter);
    }
    
    ajDebug("       Cat: %Lu\n", ajListGetLength(thys->Cat));
    if(ajListGetLength(thys->Cat))
    {
        i = 0;
        iter = ajListIterNewread(thys->Cat);
        while(!ajListIterDone(iter))
        {
            tmpstr = ajListIterGet(iter);
            ajDebug("%15d: %S\n", ++i, tmpstr);
        }
        ajListIterDel(&iter);
    }
    
    ajDebug("     Taxon: %Lu\n", ajListGetLength(thys->Taxon));
    if(ajListGetLength(thys->Taxon))
    {
        i = 0;
        iter = ajListIterNewread(thys->Taxon);
        while(!ajListIterDone(iter))
        {
            resterm = ajListIterGet(iter);
            ajDebug("%15d: %S | %S\n", ++i,  resterm->Id, resterm->Name);
        }
        ajListIterDel(&iter);
    }
    
    ajDebug("   Edamtpc: %Lu\n", ajListGetLength(thys->Edamtpc));
    if(ajListGetLength(thys->Edamtpc))
    {
        i = 0;
        iter = ajListIterNewread(thys->Edamtpc);
        while(!ajListIterDone(iter))
        {
            resterm = ajListIterGet(iter);
            ajDebug("%15d: %S | %S\n", ++i,  resterm->Id, resterm->Name);
        }
        ajListIterDel(&iter);
    }
    
    ajDebug("   Edamdat: %Lu\n", ajListGetLength(thys->Edamdat));
    if(ajListGetLength(thys->Edamdat))
    {
        i = 0;
        iter = ajListIterNewread(thys->Edamdat);
        while(!ajListIterDone(iter))
        {
            resterm = ajListIterGet(iter);
            ajDebug("%15d: %S | %S\n", ++i, resterm->Id, resterm->Name);
        }
        ajListIterDel(&iter);
    }
    
    ajDebug("    Edamid: %Lu\n", ajListGetLength(thys->Edamid));
    if(ajListGetLength(thys->Edamid))
    {
        i = 0;
        iter = ajListIterNewread(thys->Edamid);
        while(!ajListIterDone(iter))
        {
            resterm = ajListIterGet(iter);
            ajDebug("%15d: %S | %S\n", ++i,  resterm->Id, resterm->Name);
        }
        ajListIterDel(&iter);
    }
    
    ajDebug("   Edamfmt: %Lu\n", ajListGetLength(thys->Edamfmt));
    if(ajListGetLength(thys->Edamfmt))
    {
        i = 0;
        iter = ajListIterNewread(thys->Edamfmt);
        while(!ajListIterDone(iter))
        {
            resterm = ajListIterGet(iter);
            ajDebug("%15d: %S | %S\n", ++i,  resterm->Id, resterm->Name);
        }
        ajListIterDel(&iter);
    }
    
    ajDebug("      Xref: %Lu\n", ajListGetLength(thys->Xref));
    if(ajListGetLength(thys->Xref))
    {
        i = 0;
        iter = ajListIterNewread(thys->Xref);
        while(!ajListIterDone(iter))
        {
            reslink = ajListIterGet(iter);
            ajDebug("%15d: %S | %S\n", ++i, reslink->Source, reslink->Term);
        }
        ajListIterDel(&iter);
    }
    
    ajDebug("     Query: %Lu\n", ajListGetLength(thys->Query));
    if(ajListGetLength(thys->Query))
    {
        i = 0;
        iter = ajListIterNewread(thys->Query);
        while(!ajListIterDone(iter))
        {
            resqry = ajListIterGet(iter);
            ajDebug("%15d: %S | %S | %S | %S\n",
                    ++i, resqry->Datatype, resqry->Format,
                    resqry->Term, resqry->Url);
        }
        ajListIterDel(&iter);
    }
    
    ajDebug("  Example: %Lu\n", ajListGetLength(thys->Example));
    if(ajListGetLength(thys->Example))
    {
        i = 0;
        iter = ajListIterNewread(thys->Example);
        while(!ajListIterDone(iter))
        {
            tmpstr = ajListIterGet(iter);
            ajDebug("%15d: %S\n", ++i, tmpstr);
        }
        ajListIterDel(&iter);
    }
    
    return;
}
Пример #20
0
static EmbPEntry dbiblast_nextblastentry(PBlastDb db, ajint ifile,
					 const AjPStr idformat,
					 AjBool systemsort,
					 AjPStr const * fields,
					 ajint * maxFieldLen,
					 ajuint* maxidlen, ajuint* countfield,
					 AjPFile elistfile,
					 AjPFile * alistfile)
{
    ajint i;
    static ajint lastfile = -1;
    static ajint iparser  = -1;
    static ajint called   = 0;
    static ajuint tabhdr[TABLESIZE];
    static ajint iload  = TABLESIZE-1;
    static ajint irest  = 0;
    static ajint ipos   = 0;

    static ajint jpos = 0;
    ajint ir;
    ajint j;
    static ajint is = 0;
    char* token;
    static ajint nfields;
    ajint ifield;

    if(!called)
    {
	for(i=0; parser[i].Name; i++)
	    if(ajStrMatchC(idformat, parser[i].Name))
	    {
		iparser = i;
		break;
	    }

	if(iparser < 0)
	    ajFatal("idformat '%S' unknown", idformat);
	ajDebug("idformat '%S' Parser %d\n", idformat, iparser);
	ajStrSetRes(&id, HDRSIZE);
	ajStrSetRes(&acc, HDRSIZE);
	ajStrSetRes(&hline, HDRSIZE);
	called = 1;
    }

    if(!fdl)
    {
	nfields=0;
	while(fields[nfields])
	    nfields++;
	if(nfields)
	    AJCNEW(fdl, nfields);
	for(i=0; i < nfields; i++)
	    fdl[i] = ajListNew();
    }

    if(lastfile != ifile)
    {
	lastfile = ifile;
	ipos = 1;
	/*    isize = 0;*/
	irest = 0;
	iload = TABLESIZE-1;
    }

    if(!dbiblastEntry || !systemsort)
	dbiblastEntry = embDbiEntryNew(nfields);

    /* pick up the next entry, parse it and dump it */

    if(ipos > db->Size)
	return NULL;

    if( ipos >= irest)
    {
	ajDebug("ipos: %d iload: %d irest: %d\n", ipos, iload, irest);
	irest = ipos + TABLESIZE - 2;
	if(irest > db->Size)
	{
	    iload = db->Size - ipos + 1;
	    irest = db->Size;
	}

	jpos=0;
	j = dbiblast_loadtable(tabhdr, iload, db, db->TopHdr, ipos-1);
	if(!j)
	    ajDebug("No elements read");
    }

    j = dbiblast_ncblreadhdr(&hline, db, tabhdr[jpos], tabhdr[jpos+1]);

    if(!parser[iparser].Parser(hline, alistfile, systemsort, fields,
			       maxFieldLen, countfield, &id, fdl))
	ajFatal("failed to parse '%S'", hline);

    ir = ipos;

    if(ajStrGetLen(id) > *maxidlen)
	*maxidlen = ajStrGetLen(id);

    if(systemsort)
	ajFmtPrintF(elistfile, "%S %d %d %d\n", id, ir, is, ifile+1);
    else
    {
	dbiblastEntry->entry   = ajCharNewS(id);
	dbiblastEntry->rpos    = ir;
	dbiblastEntry->spos    = is;
	dbiblastEntry->filenum = ifile+1;

	/* field tokens as list, then move to dbiblastEntry->field */
	for(ifield=0; ifield < nfields; ifield++)
	{
	    dbiblastEntry->nfield[ifield] = ajListGetLength(fdl[ifield]);

	    if(dbiblastEntry->nfield[ifield])
	    {
		AJCNEW(dbiblastEntry->field[ifield],
		       dbiblastEntry->nfield[ifield]);

		i = 0;
		while(ajListPop(fdl[ifield], (void**) &token))
		    dbiblastEntry->field[ifield][i++] = token;
	    }
	    else
		dbiblastEntry->field[ifield] = NULL;
	}
    }
    ipos++;
    jpos++;

    return dbiblastEntry;
}
Пример #21
0
static EmbPEntry dbifasta_NextFlatEntry(AjPFile libr, ajint ifile,
					AjPRegexp idexp,
					ajuint type, AjBool systemsort,
					AjPStr const * fields,
					ajint* maxFieldLen,
					ajuint* maxidlen, ajuint* countfield,
					AjPFile elistfile, AjPFile* alistfile)
{
    ajint ir;
    ajint is = 0;
    char* token;
    ajint i;
    static ajint nfields;
    ajint ifield;

    if(!dbifastaGFdl)
    {
	nfields = 0;
	while(fields[nfields])
	    nfields++;
	if(nfields)
	    AJCNEW(dbifastaGFdl, nfields);
	for(i=0; i < nfields; i++)
	{
	    dbifastaGFdl[i] = ajListNew();
	}
    }

    if(!dbifastaGEntry || !systemsort)
	dbifastaGEntry = embDbiEntryNew(nfields);

    if(!dbifasta_ParseFasta(libr, &ir, maxFieldLen,
			    countfield, idexp, type,
			    alistfile, systemsort, fields))
	return NULL;

    /* id to dbifastaGEntry->entry */
    if(ajStrGetLen(dbifastaGTmpId) > *maxidlen)
	*maxidlen = ajStrGetLen(dbifastaGTmpId);

    if(systemsort)
	ajFmtPrintF(elistfile, "%S %d %d %d\n",
                    dbifastaGTmpId, ir, is, ifile+1);
    else
    {
	dbifastaGEntry->entry   = ajCharNewS(dbifastaGTmpId);
	dbifastaGEntry->rpos    = ir;
	dbifastaGEntry->spos    = is;
	dbifastaGEntry->filenum = ifile+1;

	/* field tokens as list, then move to ret->field */
	for(ifield=0; ifield < nfields; ifield++)
	{
	    dbifastaGEntry->nfield[ifield] =
            (ajuint) ajListGetLength(dbifastaGFdl[ifield]);

	    if(dbifastaGEntry->nfield[ifield])
	    {
		AJCNEW(dbifastaGEntry->field[ifield],
		       dbifastaGEntry->nfield[ifield]);

		i = 0;
		while(ajListPop(dbifastaGFdl[ifield], (void**) &token))
		    dbifastaGEntry->field[ifield][i++] = token;
	    }
	    else
		dbifastaGEntry->field[ifield] = NULL;
	}
    }

    return dbifastaGEntry;
}
Пример #22
0
int main(int argc, char **argv)
{
    /* Variable declarations */
    AjPOutfile outfile = NULL;    
    AjPTaxall taxall = NULL;

    AjPTax tax     = NULL;
    AjPTax taxtest     = NULL;

    AjPList taxlist = ajListNew();

    AjPTable foundtable = NULL;
    ajuint ifound = 0;
    ajuint ikeep = 0;

    /* ACD processing */
    embInit("taxgetspecies", argc, argv);

    taxall    = ajAcdGetTaxonall("taxons");
    outfile   = ajAcdGetOuttaxon("outfile");

    foundtable = ajTablestrNew(600);

    while(ajTaxallNext(taxall, &tax))
    {
        ajListPushAppend(taxlist, ajTaxNewTax(tax));
        ajTaxGetTree(tax, taxlist);

        while(ajListGetLength(taxlist))
        {
            ajListPop(taxlist, (void**) &taxtest);

            if(!ajStrMatchC(ajTaxGetRank(taxtest), "species"))
            {
                ajTaxDel(&taxtest);
                continue;
            }

            ifound++;
            if(!ajTableMatchS(foundtable, taxtest->Id))
            {
                ajTaxoutWrite(outfile, taxtest);
                ajTablePut(foundtable, ajStrNewS(taxtest->Id),
                           (void *) 1);
                ikeep++;
            }
            ajTaxDel(&taxtest);
        }
    }
 
    if(!ifound)
        ajErr("No matching terms");

    /* Memory clean-up and exit */

    ajListFree(&taxlist);

    ajTaxallDel(&taxall);
    ajTaxDel(&tax);

    ajOutfileClose(&outfile);
    ajTablestrFreeKey(&foundtable);
   
    embExit();

    return 0;
}
Пример #23
0
int main(int argc, char **argv)
{
    /* Variable declarations */
    AjPOutfile outfile = NULL;    
    AjPOboall oboall = NULL;
    AjBool subclasses = ajFalse;
    AjBool obsolete = ajFalse;

    AjPObo obo     = NULL;
    AjPObo obotest = NULL;

    AjPList obolist = ajListNew();

    AjPTable foundtable = NULL;
    ajuint ifound = 0;
    ajuint ikeep = 0;

    /* ACD processing */
    embInit("ontoget", argc, argv);

    oboall    = ajAcdGetOboall("oboterms");
    outfile   = ajAcdGetOutobo("outfile");
    subclasses = ajAcdGetBoolean("subclasses");
    obsolete = ajAcdGetBoolean("obsolete");
    
    foundtable = ajTablestrNew(600);

    while(ajOboallNext(oboall, &obo))
    {
        ajListPushAppend(obolist, ajOboNewObo(obo));
        if(subclasses)
            ajOboGetTree(obo, obolist);

        while(ajListGetLength(obolist))
        {
            ajListPop(obolist, (void**) &obotest);
            if(!obsolete && ajOboIsObsolete(obotest))
            {
                ajOboDel(&obotest);
                continue;
            }

            ifound++;
            if(!ajTableMatchS(foundtable, obotest->Id))
            {
                ajObooutWrite(outfile, obotest);
                ajTablePut(foundtable, ajStrNewS(obotest->Id),
                           (void *) 1);
                ikeep++;
            }
            ajOboDel(&obotest);
        }
    }

    if(!ifound)
        ajErr("No matching terms");

    /* Memory clean-up and exit */

    ajListFree(&obolist);

    ajOboallDel(&oboall);
    ajOboDel(&obo);

    ajOutfileClose(&outfile);
    ajTablestrFreeKey(&foundtable);
   
    embExit();

    return 0;
}
Пример #24
0
int main(int argc, char **argv)
{
    AjPDasServer server   = NULL;
    AjPDasSource source   = NULL;
    AjPDasSegment segment = NULL;

    AjPStr host  = NULL;
    AjPStr path  = NULL;
    AjPFile outf = NULL;

    ajint port = 80;

    AjBool sequencesourcesonly;
    AjBool entrypoints;
    AjBool showtestqueries;
    AjBool runtestqueries = ajTrue;
    AjBool quickexit = ajFalse;

    ajint itest=0;
    ajint j=0;

    ajint maxtests=0;
    ajint maxfeatures=0;
    ajint maxsegments=0;

    AjIList iter     = NULL;
    AjIList coordsi  = NULL;
    AjIList itereps  = NULL;
    AjPFilebuff buff = NULL;
    AjPUrlref uo        = NULL;
    AjPList segments = NULL;
    AjPStr ffname    = NULL;
    AjPStr url       = NULL;

    AjPStr dbhttpver = ajStrNew();
    AjPStr dbname    = ajStrNew();
    AjPStr dbproxy   = ajStrNew();

    AjPStr servername   = NULL;
    AjPTable titlecount = NULL;
    const ajuint* count;
    int k=0;

    embInit("dastest", argc, argv);

    host = ajAcdGetString("host");
    path = ajAcdGetString("path");
    port = ajAcdGetInt("port");
    sequencesourcesonly = ajAcdGetBoolean("sequencesourcesonly");
    entrypoints = ajAcdGetBoolean("entrypoints");
    showtestqueries = ajAcdGetBoolean("showtestqueries");
    runtestqueries  = ajAcdGetBoolean("runtestqueries");

    servername = ajAcdGetString("servername");

    outf   = ajAcdGetOutfile("outfile");

    maxtests     = ajAcdGetInt("maxtests");
    maxfeatures = ajAcdGetInt("maxfeatures");
    maxsegments = ajAcdGetInt("maxsegments");

    server = ajDasServerNew();

    if(runtestqueries)
    {
	url = ajStrNew();

	if(!ajNamServer(servername))
	{
	    ajWarn("following das server is required to be defined "
		    "for test queries...");
	    ajWarn("\nSERVER %S [\n"
		    "   type: \"sequence\"\n"
		    "   method: \"das\"\n"
		    "   url: \"http://%S%S\"\n"
		    "]\n",servername, host,path);
	    ajWarn("ignoring -runtestqueries option...");
	    runtestqueries = ajFalse;
	}
	else
	{
	    ajNamSvrGetUrl(servername, &url);
	    ajHttpUrlDeconstruct(url, &port, &host, &path);

	    ajStrDel(&url);
	}
    }

    ajDasServerSethostS(server,host);
    ajDasServerSetport(server,port);


    if(ajStrGetCharLast(path)!='/')
	ajStrAppendK(&path,'/');

    ajStrAppendC(&path,"sources");

    ajDasServerSetpathS(server,path);

    ajFmtPrintF(outf,"host = %S\npath = %S\nport = %d\n",
	    server->host, server->path, server->port);


    /*
     * TODO: stop using http-read but instead use
     *       ajNamSvrListListDatabases(svrname, dbnames);
     */

    buff = ajHttpRead(dbhttpver, dbname, dbproxy, host, port, path);

    if(!buff)
	ajExitAbort();

    ajFilebuffHtmlNoheader(buff);

    ajDasParseRegistry(buff, server->sources);
    ajFmtPrintF(outf,"DAS sources and descriptions\n\n");

    titlecount = dastestGetTitleCount(server);

    iter = ajListIterNew(server->sources);

    while(!ajListIterDone(iter) && !quickexit)
    {
	source = ajListIterGet(iter);


	if ((sequencesourcesonly && !source->sequence)
		|| ajStrMatchC(source->title,"cath") || k++ <50)
	    continue;

	ajFmtPrintF(outf,"%-30S %-50S\n%S\n",source->uri,source->title,
		source->description);

	if(entrypoints && source->entry_points)
	{
	    uo = ajHttpUrlrefNew();

	    ajHttpUrlrefParseC(&uo, ajStrGetPtr(source->entry_points_uri));

	    if(ajStrGetLen(uo->Port))
		ajStrToInt(uo->Port, &port);
	    else
		port = 80;

	    ajFilebuffDel(&buff);
	    buff = ajHttpRead(dbhttpver, dbname, dbproxy,
	                      uo->Host, port, uo->Absolute);
	    ajHttpUrlrefDel(&uo);

	    if(!buff)
		continue;

	    ajFilebuffHtmlNoheader(buff);

	    segments = ajListNew();
	    ajDasParseEntrypoints(buff, segments);

	    itereps = ajListIterNew(segments);

	    ajFmtPrintF(outf, "Number of entry points %d\n",
		    ajListGetLength(segments));

	    j=0;

	    while(!ajListIterDone(itereps))
	    {
		segment = ajListIterGet(itereps);

		if (j++ < maxsegments)
		    ajFmtPrintF(outf,
		            "segment id:%S orientation:%S start:%d stop:%d\n",
		            segment->id,
		            segment->orientation,
		            segment->start, segment->stop);

		ajDasSegmentDel(&segment);
	    }

	    ajListIterDel(&itereps);
	    ajListFree(&segments);
	}

	if(showtestqueries || runtestqueries)
	{
	    AjPDasCoordinate coord;

	    coordsi = ajListIterNew(source->coordinates);

	    while(!ajListIterDone(coordsi) && !quickexit)
	    {
		coord = ajListIterGet(coordsi);
		ajDebug("coordinate uri:%S taxid:%S source:%S test_range:%S\n",
			coord->uri,
			coord->taxid,
			coord->source,
			coord->test_range);

		if(showtestqueries)
		{
		    if(source->sequence)
			ajFmtPrintF(outf,
			       "example/test entry = '%S?segment=%S'\n",
			       source->sequence_query_uri,coord->test_range);

		    if(source->features)
			ajFmtPrintF(outf,
			       "example/test entry = '%S?segment=%S'\n",
			       source->features_query_uri,coord->test_range);

		}

		if(runtestqueries)
		{
		    AjPStr idqry = ajStrNew();
		    AjPStr entry = NULL;
		    AjPSeq seq   = NULL;
		    ajint ibegin = 0;
		    ajint iend   = 0;
		    AjPStr example = NULL;

		    example = ajDasTestrangeParse(coord->test_range,
		                                  &entry, &ibegin, &iend);

		    if(ajStrGetLen(entry))
		    {
			count = ajTableFetchS(titlecount, source->title);
			dbname = ajDasSourceGetDBname(source, *count>1);

			if (source->features)
			{
			    AjPStr qpath=NULL;

			    uo = ajHttpUrlrefNew();

			    ajFmtPrintS(&idqry,"dasgff::%S:%S:%S",
				    servername,
				    dbname,
				    entry);
			    ajFmtPrintF(outf,
				    "feature query: %S  start:%d end:%d\n",
				    idqry,
				    ibegin, iend);


			    ajHttpUrlrefParseC(&uo,
				    ajStrGetPtr(source->features_query_uri));
			    ajHttpUrlrefSplitPort(uo);

			    ajFmtPrintS(&qpath,"%S?segment=%S",
				    uo->Absolute,entry);

			    if(iend>0)
				ajFmtPrintAppS(&qpath,":%d,%d",ibegin, iend);

			    if(ajStrGetLen(uo->Port))
				ajStrToInt(uo->Port, &port);
			    else
				port = 80;

			    ajDebug("calling ajHttpRead to get the raw"
				    " output; host:%S port:%d path:%S\n",
				    uo->Host, port, qpath);

			    ajFilebuffDel(&buff);
			    buff = ajHttpRead(dbhttpver, dbname, dbproxy,
			                      uo->Host, port, qpath);

			    if(buff)
			    {
				AjPFeattable ft;

				ajFmtPrintS(&ffname, "%S.%S", source->uri,
					    entry);

				ajFilebuffHtmlNoheader(buff);

				dastestSaveRawFeatures(buff, ffname);

				ajDebug("now using EMBOSS feature queries\n");

				ft = dastestFeatureQuery(idqry,
                                                         ibegin, iend);

				dastestSaveMappedFeatures(ft, ffname,
                                                          outf, maxfeatures);

				ajStrDel(&ffname);
				ajFeattableDel(&ft);
			    }

			    ajHttpUrlrefDel(&uo);
			    ajStrDel(&qpath);

			    if(++itest>=maxtests)
				quickexit = ajTrue;
			}
			else if(source->sequence)
			{
			    seq = ajSeqNewRes(iend-ibegin+1);

			    ajFmtPrintS(&idqry,"%S:%S:%S",
				    servername, dbname, entry);
			    ajFmtPrintF(outf,
				    "sequence query: %S  start:%d end:%d\n",
				    idqry,
				    ibegin, iend);
			    ajSeqGetFromUsaRange(idqry, ajFalse, ibegin, iend,
				    seq);
			    ajFmtPrintF(outf,
				    "length of sequence returned: %d\n",
				    ajSeqGetLen(seq));

			    if(ajSeqGetLen(seq)>0)
				ajFmtPrintF(outf,
				        "sequence returned (first 100 bases):"
					" %-100.100s\n",
					ajSeqGetSeqC(seq));

			    ajSeqDel(&seq);

			}

			ajStrDel(&dbname);
		    }

		    ajStrDel(&entry);
		    ajStrDel(&idqry);
		    ajStrDel(&example);
		}
	    }
	    ajListIterDel(&coordsi);
	}

    }

    ajListIterDel(&iter);

    ajDasServerDel(&server);
    ajFilebuffDel(&buff);

    ajStrDel(&host);
    ajStrDel(&path);
    ajStrDel(&servername);

    ajStrDel(&dbhttpver);
    ajStrDel(&dbname);
    ajStrDel(&dbproxy);

    ajFileClose(&outf);

    ajTableDelValdel(&titlecount, ajMemFree);

    embExit();

    return 0;
}
Пример #25
0
static ajint supermatcher_findstartpoints(AjPTable seq1MatchTable,
					  const AjPSeq b,
					  const AjPSeq a, ajint *start1,
					  ajint *start2, ajint *end1,
					  ajint *end2)
{
    ajint max = -10;
    ajint offset = 0;
    AjPList matchlist = NULL;
    AjPList ordered = NULL;
    ajint amax;
    ajint bmax;
    ajint bega;
    ajint begb;

    amax = ajSeqGetLen(a)-1;
    bmax = ajSeqGetLen(b)-1;
    bega = ajSeqGetOffset(a);
    begb = ajSeqGetOffset(b);


    ajDebug("supermatcher_findstartpoints len %d %d off %d %d\n",
	     amax, bmax, bega, begb);
    matchlist = embWordBuildMatchTable(seq1MatchTable, b, ajTrue);

    if(!matchlist)
	return 0;
    else if(!matchlist->Count)
    {
        embWordMatchListDelete(&matchlist);
	return 0;
    }


    /* order and add if the gap is gapmax or less */

    /* create list header bit*/
    ordered = ajListNew();

    supermatcher_orderandconcat(matchlist, ordered);

    /* this sets global structure conmax to point to a matchlist element */
    ajListMap(ordered,supermatcher_findmax, &max);

    ajDebug("findstart conmax off:%d count:%d total:%d\n",
	    conmax->offset, conmax->count, conmax->total,
	    ajListGetLength(conmax->list));
    offset = conmax->offset;

    /* the offset is all we needed! we can delete everything */

    ajListMap(ordered,supermatcher_removelists, NULL);
    ajListFree(&ordered);
    embWordMatchListDelete(&matchlist);	/* free the match structures */


    if(offset > 0)
    {
	*start1 = offset;
	*start2 = 0;
    }
    else
    {
	*start2 = 0-offset;
	*start1 = 0;
    }
    *end1 = *start1;
    *end2 = *start2;

    ajDebug("++ end1 %d -> %d end2 %d -> %d\n", *end1, amax, *end2, bmax);
    while(*end1<amax && *end2<bmax)
    {
	(*end1)++;
	(*end2)++;
    }

    ajDebug("++ end1 %d end2 %d\n", *end1, *end2);
    
    
    ajDebug("supermatcher_findstartpoints has %d..%d [%d] %d..%d [%d]\n",
	    *start1, *end1, ajSeqGetLen(a), *start2, *end2, ajSeqGetLen(b));

    return 1;
}
Пример #26
0
ajuint ajPatlistRegexGetSize (const AjPPatlistRegex thys)
{
    return ajListGetLength(thys->Patlist);
}
Пример #27
0
ajuint ajPatlistSeqGetSize (const AjPPatlistSeq thys)
{
    return ajListGetLength(thys->Patlist);
}
Пример #28
0
static AjBool assemoutWriteNextSam(AjPOutfile outfile, const AjPAssem assem)
{
    AjPFile outf = ajOutfileGetFile(outfile);
    AjPAssemContig c = NULL;
    AjPAssemRead   r = NULL;
    AjPAssemTag    t = NULL;
    AjPAssemContig* contigs = NULL;
    AjIList j = NULL;
    AjPStr argstr = NULL;
    const AjPStr headertext = NULL;
    ajint n = 0;
    ajulong i = 0UL;
    AjBool ret = ajTrue;

    if(!outf || !assem)
	return ajFalse;

    ajDebug("assemoutWriteSam: # of contigs = %d\n", n);

    if(!assem->Hasdata)
    {
        ajFmtPrintF(outf, "@HD\tVN:1.3\tSO:%s\n", ajAssemGetSortorderC(assem));

        /* Program record */
        argstr = ajStrNewS(ajUtilGetCmdline());
        ajStrExchangeKK(&argstr, '\n', ' ');
        ajFmtPrintF(outf, "@PG\tID:%S\tVN:%S\tCL:%S\n",
                    ajUtilGetProgram(), ajNamValueVersion(), argstr);
        ajStrDel(&argstr);


        if(ajListGetLength(assem->ContigsOrder))
            ajListToarray(assem->ContigsOrder, (void***)&contigs);
        else
            ajTableToarrayValues(assem->Contigs, (void***)&contigs);

        while (contigs[i])   /* contigs */
        {
            c = contigs[i++];

            if(!ajStrMatchC(c->Name, "*"))
            {
                ajFmtPrintF(outf, "@SQ\tSN:%S\tLN:%d", c->Name, c->Length);

                if(c->URI)
                    ajFmtPrintF(outf, "\tUR:%S", c->URI);

                if(c->MD5)
                    ajFmtPrintF(outf, "\tM5:%S", c->MD5);

                if(c->Species)
                    ajFmtPrintF(outf, "\tSP:%S", c->Species);

                ajFmtPrintF(outf, "\n");

                j = ajListIterNewread(c->Tags);
                while (!ajListIterDone(j))
                {
                    t = ajListIterGet(j);
                    ajFmtPrintF(outf, "@CO\t%S %u %u %S\n",
                                t->Name, t->x1, t->y1,
                                t->Comment);
                }
                ajListIterDel(&j);
            }
        }

        headertext = assemSAMGetReadgroupHeaderlines(assem);
        if(headertext)
            ajFmtPrintF(outf,"%S", headertext);

        AJFREE(contigs);

        if(!assem->BamHeader)
            return ajTrue;
    }


    /* data */

    j = ajListIterNewread(assem->Reads);
    if(ajListGetLength(assem->ContigsOrder))
        i = ajListToarray(assem->ContigsOrder, (void***)&contigs);
    else
        i = ajTableToarrayValues(assem->Contigs, (void***)&contigs);

    while (!ajListIterDone(j))  /* reads */
    {
	r = ajListIterGet(j);
	assemoutWriteSamAlignment(outf, r, contigs, (ajuint) i);
    }

    ajListIterDel(&j);
    AJFREE(contigs);

    return ret;
}
Пример #29
0
static void jaspscan_ParseInput(const AjPStr dir, const AjPStr jaspdir,
				const AjPStr mats, const AjPStr excl,
				ajuint *recurs, AjPList ret)
{
    ajuint nm = 0;
    ajuint ne = 0;
    AjPStr *carr = NULL;
    AjPStr *earr = NULL;
    AjPFile inf = NULL;
    AjPStr line = NULL;
    AjPStr comm = NULL;
    AjPStr val  = NULL;
    
    ajuint i;
    ajuint j;
    
    char c;

    ajuint rlen = 0;
    

    if(*recurs > JASPSCAN_RECURS)
	ajFatal("Too many recursion levels in matrix list files");
    
    line = ajStrNew();
    comm = ajStrNew();
    

    if(mats)
    {
	nm = ajArrCommaList(mats,&carr);	
	for(i=0; i < nm; ++i)
	{
	    if(ajStrGetCharFirst(carr[i]) != '@')
		ajStrFmtUpper(&carr[i]);
	
	    if(ajStrMatchC(carr[i],"ALL"))
	    {
		jaspscan_GetFileList(dir, jaspdir, "*", ret);
		ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel);
	    }
	    else if(ajStrGetCharFirst(carr[i]) == '@')
	    {
		ajStrTrimStartC(&carr[i],"@");
		inf = ajFileNewInNameS(carr[i]);
		if(!inf)
		    ajFatal("Cannot open list file %S",carr[i]);

		while(ajReadlineTrim(inf,&line))
		{
		    ajStrRemoveWhite(&line);
		    c = ajStrGetCharFirst(line);
		    if(c == '#' || c== '!')
			continue;
		    if(ajStrGetLen(comm))
			ajStrAppendC(&comm,",");
		    ajStrFmtUpper(&line);
		    ajStrAppendS(&comm,line);
		}

		*recurs += 1;
		jaspscan_ParseInput(dir,jaspdir,comm,NULL,recurs,ret);
		*recurs -= 1;
		ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel);	    

		ajFileClose(&inf);
	    }
	    else
	    {
		jaspscan_GetFileList(dir,jaspdir,ajStrGetPtr(carr[i]),ret);
		ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel);
	    }
	}

	for(i=0; i < nm; ++i)
	    ajStrDel(&carr[i]);

	AJFREE(carr);
    }
    
    


    if(excl)
    {
	ne = ajArrCommaList(excl,&earr);
	
	for(i=0; i < ne; ++i)
	{
	    if(ajStrGetCharFirst(earr[i]) != '@')
		ajStrFmtUpper(&earr[i]);
	
	    if(ajStrGetCharFirst(earr[i]) == '@')
	    {
		ajStrTrimStartC(&earr[i],"@");
		inf = ajFileNewInNameS(earr[i]);
		if(!inf)
		    ajFatal("Cannot open list file %S",earr[i]);

		while(ajReadlineTrim(inf,&line))
		{
		    ajStrRemoveWhite(&line);
		    c = ajStrGetCharFirst(line);
		    if(c == '#' || c== '!')
			continue;
		    if(ajStrGetLen(comm))
			ajStrAppendC(&comm,",");
		    ajStrFmtUpper(&line);
		    ajStrAppendS(&comm,line);
		}

		*recurs += 1;
		jaspscan_ParseInput(dir,jaspdir,NULL,comm,recurs,ret);
		*recurs -= 1;
		ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel);	    

		ajFileClose(&inf);
	    }
	    else
	    {
		ajStrAssignS(&line,earr[i]);
		ajStrAppendC(&line,J_EXT);
		rlen = ajListGetLength(ret);
		for(j=0; j < rlen; ++j)
		{
		    ajListPop(ret,(void **)&val);
		    if(ajStrSuffixS(val,line))
			ajStrDel(&val);
		    else
			ajListPushAppend(ret,(void *)val);
		}
		
	    }
	} 


	for(i=0; i < ne; ++i)
	    ajStrDel(&earr[i]);
	AJFREE(earr);
    }
    

    ajStrDel(&line);
    ajStrDel(&comm);

    return;
}
Пример #30
0
/* @prog ssematch ***********************************************************
**
** Searches a DCF file (domain classification file) for secondary structure 
** matches.
**
****************************************************************************/
int main(int argc, char **argv)
{
    /* Variables declarations */
    AjPFile dcfin        = NULL; /* Domain classification file */
    AjPFile ssin         = NULL; /* Secondary structure input file*/
    AjPMatrixf matrix    = NULL; /* Substitution matrix */
    AjPFile out_ss       = NULL; /* For ss top matches*/
    AjPFile out_se       = NULL; /* For se top matches*/
    AjPFile outfile      = NULL; /* Output file*/
    AjPFile logf         = NULL; /* Log file */
    float gapopen_sss    = 0.0;  /* Gap insertion penalty */
    float gapopen_sse    = 0.0;
    float gapopen        = 0.0;
    float gapextend_sss  = 0.0;  /* Gap extension penalty */
    float gapextend_sse  = 0.0;
    float gapextend      = 0.0;
    ajint max_hits       = 0;    /* number of top alignments to display*/
    ajint mode           = 0;
    ajint x              = 0;

    AjPScop temp_scop    = NULL; /* scop object pointer*/

    AjPList  scop_list   = NULL; /* list of scop objects for entire domain
				    classification file */
     
    AjIList       iter   = NULL;
    AjPStr        msg    = NULL; /* Pointer to String used for messages */
    AjPStr        line   = NULL;
   
    AjPStr    qse        = NULL; /* query secondary structure elements*/
    AjPStr    qss        = NULL; /* query secondary structure (by residue)*/
    AjPSeq    q3se       = NULL; /* query secondary structure elements, 3-letter 
				    code*/
    AjPSeq    q3ss       = NULL; /* query secondary structure 
				    (by residue), 3-letter code*/
    AjPSeq    query      = NULL;
    




    /* Read data from acd */
    embInitPV("ssematch",argc,argv,"DOMAINATRIX",VERSION);
    dcfin       = ajAcdGetInfile("dcfinfile");
    ssin       = ajAcdGetInfile("ssinfile");
    max_hits      = ajAcdGetInt("maxhits");
    matrix        = ajAcdGetMatrixf("datafile");
    gapopen_sss   = ajAcdGetFloat("rgapopen");
    gapextend_sss = ajAcdGetFloat("rgapextend");
    gapopen_sse   = ajAcdGetFloat("egapopen");
    gapextend_sse = ajAcdGetFloat("egapextend");
    out_ss        = ajAcdGetOutfile("outssfile");
    out_se        = ajAcdGetOutfile("outsefile");
    logf       = ajAcdGetOutfile("logfile");






    /* Create list of scop objects for entire input domain classification file. */
    scop_list  = ajListNew();
    while((temp_scop = (ajScopReadCNew(dcfin, "*"))))
        ajListPushAppend(scop_list,temp_scop);


    /* Error handing if domain classification file was empty. */
    if(!(ajListGetLength(scop_list)))
    {
      
        ajWarn("Empty list from scop input file\n");
	ajFileClose(&dcfin);
	ajFileClose(&ssin);
	ajMatrixfDel(&matrix);
       	ajFileClose(&out_ss);
	ajFileClose(&out_se);
       	ajFileClose(&logf);
	while(ajListPop(scop_list, (void *) &temp_scop))
	    ajScopDel(&temp_scop);
	ajListFree(&scop_list);
        ajListIterDel(&iter);    
	
	ajExit();
	return 1;
    }

    /* Error handling in case of empty query file. */
    if(ssin == NULL)   
    {
        ajWarn("Empty secondary structure query file\n");
	ajFileClose(&dcfin);
	ajFileClose(&ssin);
	ajMatrixfDel(&matrix);
       	ajFileClose(&out_ss);
	ajFileClose(&out_se);
       	ajFileClose(&logf);
	while(ajListPop(scop_list, (void *) &temp_scop))
	    ajScopDel(&temp_scop);
	ajListFree(&scop_list);
        ajListIterDel(&iter);    
	
	ajExit();
	return 1; 
    }      
    
    /* Assign sequences in query file to sequence objects. */
    qse = ajStrNew();
    qss = ajStrNew();
    
    while(ajReadlineTrim(ssin,&line))
    {
        /* SE string */
        if(ajStrPrefixC(line,"SE"))
	{
	    ajFmtScanS(line, "%*s %S", &qse);
            /* Convert this string to 3-letter code & then convert to AjPSeq 
	       object. */
            q3se = ssematch_convertbases(qse);
        }
        /* SS string */
	else if(ajStrPrefixC(line,"SS"))
	{
            while((ajReadlineTrim(ssin,&line)) && !ajStrPrefixC(line,"XX"))
                ajStrAppendS(&qss,line);
            ajStrRemoveWhite(&qss);

            /* Convert this string to 3-letter code & then to AjPSeq object. */
            q3ss = ssematch_convertbases(qss);
      	}
    }



    /* For se & then for ss, modes 0 & 1. */
    for(mode = 0; mode <= 1; mode++)
    {
        /* Assign arguments for alignment function. */
        if (mode == 0) 
        {
            query = q3se;
            gapopen = gapopen_sse; 
            gapextend = gapextend_sse;
            outfile =  out_se;
        } 
        else if(mode == 1)
        {
            query = q3ss;  
            gapopen = gapopen_sss; 
            gapextend = gapextend_sss;
            outfile =  out_ss;   
        }


        /* Iterate through list of scop objects & calculate alignment scores. */
        iter=ajListIterNew(scop_list);
        while((temp_scop=(AjPScop)ajListIterGet(iter)))
        {
            /* The function extracts the se (mode 0) or ss (mode 1) subject 
	       sequences from the scop object, performs a Needleman-Wunsch 
	       global alignment with the query sequence & allocates the score 
	       to the Score element of the scop object*/ 

	    if(!(ssematch_NWScore(temp_scop , query, mode, matrix, gapopen, gapextend)))

	    {
                ajFmtPrintF(logf, "%-15s\n", "ALIGNMENT");
                ajFmtPrintF(logf, "Could not align sequence in scop domain %S\n ", 
			    temp_scop->Entry); 
	        ajFmtPrintS(&msg, "Could not align sequence in scop domain %S\n ", 
			    temp_scop->Entry);
	        ajWarn(ajStrGetPtr(msg));
                continue;
	    }
	}


        ajListIterDel(&iter);
      	temp_scop    = NULL;


        /* Sort list of Scop objects by Score */
        ajListSort(scop_list, ssematch_CompScoreInv);
	
	
        iter=ajListIterNew(scop_list);
        /* Write top-scoring hits to outfile. */
        for(x=0; x < max_hits; x++ )
	{
            temp_scop=(AjPScop)ajListIterGet(iter);
 
	    /* Print score to output file. */
	    ajFmtPrintF(outfile, "XX   ALIGNMENT SCORE %.3f\nXX\n", temp_scop->Score);
	    
	    /* Could also write alignment - later modification. */
	    if(!ajScopWrite(outfile, temp_scop))
		ajFatal("Could not write output file %S\n", outfile);

        
        }

	ajListIterDel(&iter); 
     	temp_scop    = NULL;
    }


      
    /* Memoryt management. */
    ajFileClose(&dcfin);
    ajFileClose(&ssin);
    ajMatrixfDel(&matrix);
    ajFileClose(&out_ss);
    ajFileClose(&out_se);
    ajFileClose(&logf);
    while(ajListPop(scop_list, (void *) &temp_scop))
	ajScopDel(&temp_scop);
    ajListFree(&scop_list);
    ajStrDel(&msg);
    ajStrDel(&line);
    ajStrDel(&qse); 
    ajStrDel(&qss);
    ajSeqDel(&q3se);
    ajSeqDel(&q3ss);
    

    ajExit();
    return 0;
}