Example #1
0
static void jaspextract_getjaspdirs(AjPList jdirlist)
{
    const AjPStr datadir = NULL;
    AjPStr line = NULL;
    
    ajuint n = 0;
    ajuint i = 0;
    
    datadir = ajDatafileValuePath();
    if(!datadir)
        ajFatal("jaspextract: Cannot determine the EMBOSS data directory");


    n = ajFilelistAddPathDir(jdirlist, datadir);

    
    for(i=0; i < n; ++i)
    {
        ajListPop(jdirlist,(void **)&line);
        if(ajStrFindC(line,"JASPAR_") != -1)
            ajListPushAppend(jdirlist,(void *)line);
        else
            ajStrDel(&line);
    }

    return;
}
Example #2
0
static void jaspextract_readmatrixlist(AjPTable mtable, const AjPStr directory)
{
    const AjPStr datadir = NULL;

    AjPStr matrixfile = NULL;
    AjPFile inf = NULL;

    AjPStr line  = NULL;
    AjPStr key   = NULL;
    AjPStr value = NULL;
    
    matrixfile = ajStrNew();
    

    datadir = ajDatafileValuePath();
    if(!datadir)
        ajFatal("jaspextract: Cannot determine the EMBOSS data directory");
    
    ajFmtPrintS(&matrixfile,"%S%s",directory,MATRIXFILE);

    if(!ajFilenameExistsRead(matrixfile))
        ajFatal("jaspextract: Directory (%S) doesn't appear to be a JASPAR "
                "one\nNo matrix_list.txt file found",directory);


    inf  = ajFileNewInNameS(matrixfile);
    if(!inf)
        ajFatal("Cannot open input file: %S",matrixfile);

    while(ajReadline(inf,&line))
    {
        key = ajStrNew();
        
        if(ajFmtScanS(line,"%S",&key) != 1)
        {
            ajStrDel(&key);
            continue;
        }

        value = ajStrNew();
        ajStrAssignS(&value,line);

        ajTablePut(mtable,(void *)key, (void *)value);
    }
    

    ajFileClose(&inf);
    
    ajStrDel(&matrixfile);
    ajStrDel(&line);
        
    return;
}
Example #3
0
static void jaspextract_openoutdirs(void)
{
    const AjPStr datadir = NULL;
    AjPStr dir = NULL;
    const char *p = NULL;
    
    ajuint i = 0;
    
    datadir = ajDatafileValuePath();
    if(!datadir)
        ajFatal("jaspextract: Cannot determine the EMBOSS data directory");

    dir  = ajStrNew();
    
    i = 0;

    while(Jprefix[i].Directory)
    {
        ajFmtPrintS(&dir,"%S%s",datadir,Jprefix[i].Directory);

        if(!ajFilenameExistsDir(dir))
        {
            p = ajStrGetPtr(dir);
#ifndef WIN32
            mkdir(p,0644);
#else
            _mkdir(p);
#endif
        }
        
        if(!ajFilenameExistsDir(dir))
            ajFatal("jaspextract: No such directory %S",
                    dir);

        ++i;
    }
    
    ajStrDel(&dir);
    
    return;
}
Example #4
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;
}
Example #5
0
static void jaspextract_copyfiles(AjPStr directory)
{
    AjPStr matrixfile = NULL;
    AjPList flist     = NULL;
    
    AjPStr wild  = NULL;
    AjPStr entry = NULL;
    AjPStr bname = NULL;
    AjPStr line  = NULL;
    AjPStr dest  = NULL;

    const AjPStr datadir = NULL;
    
    ajuint preflen = 0;
    ajuint i       = 0;
    const char *p  = NULL;

    AjPFile inf   = NULL;
    AjPFile outf  = NULL;    
    
    matrixfile = ajStrNew();
    flist      = ajListNew();
    wild       = ajStrNewC("*.pfm");
    bname      = ajStrNew();
    line       = ajStrNew();
    dest       = ajStrNew();


    datadir = ajDatafileValuePath();
    if(!datadir)
        ajFatal("jaspextract: Cannot determine the EMBOSS data directory");
    
    ajFmtPrintS(&matrixfile,"%S%s",directory,MATRIXFILE);

    if(!ajFilenameExistsRead(matrixfile))
        ajFatal("jaspextract: Directory (%S) doesn't appear to be a JASPAR "
                "one\nNo matrix_list.txt file found",directory);
    
    ajFilelistAddPathWild(flist, directory, wild);


    while(ajListPop(flist,(void **)&entry))
    {
        ajStrAssignS(&bname,entry);
        ajFilenameTrimPath(&bname);
        
        i = 0;

        while(Jprefix[i].Prefix)
        {
            if(!ajStrPrefixC(bname,Jprefix[i].Prefix))
            {
                ++i;
                continue;
            }

            preflen = strlen(Jprefix[i].Prefix);
            p = ajStrGetPtr(bname);
            if(p[preflen]>='0' && p[preflen]<='9')
                break;

            ++i;
        }

        if(!Jprefix[i].Prefix)
        {
            ajStrDel(&entry);
            continue;
        }


        ajFmtPrintS(&dest,"%S%s%c%S",datadir,Jprefix[i].Directory,SLASH_CHAR,
                    bname);

        outf = ajFileNewOutNameS(dest);
        if(!outf)
            ajFatal("Cannot open output file %S",dest);

        /* Avoid UNIX copy for portability */
        inf  = ajFileNewInNameS(entry);
        if(!inf)
            ajFatal("Cannot open input file: %S",entry);

        while(ajReadlineTrim(inf,&line))
            ajFmtPrintF(outf,"%S\n",line);

        ajFileClose(&inf);
        ajFileClose(&outf);
        
        ajStrDel(&entry);        

    }
    
    ajListFree(&flist);
    
    ajStrDel(&wild);
    ajStrDel(&dest);
    ajStrDel(&line);
    ajStrDel(&bname);
    ajStrDel(&matrixfile);

    return;
}