Exemplo n.º 1
0
AjBool ensCacheSynchronise(EnsPCache cache)
{
    AjIList iter = NULL;

    CachePNode node = NULL;

    if(!cache)
        return ajFalse;

    iter = ajListIterNew(cache->List);

    while(!ajListIterDone(iter))
    {
        node = (CachePNode) ajListIterGet(iter);

        if(cache->Write && node->Value && node->Dirty)
        {
            (*cache->Write)(node->Value);

            node->Dirty = ajFalse;
        }
    }

    ajListIterDel(&iter);

    return ajTrue;
}
Exemplo n.º 2
0
static void assemblyexceptionadaptorFetchAll(const void *key,
                                             void **value,
                                             void *cl)
{
    AjIList iter = NULL;

    EnsPAssemblyexception ae = NULL;

    if(!key)
        return;

    if(!value)
        return;

    if(!*value)
        return;

    if(!cl)
        return;

    iter = ajListIterNew(*((AjPList *) value));

    while(!ajListIterDone(iter))
    {
        ae = (EnsPAssemblyexception) ajListIterGet(iter);

        ajListPushAppend((AjPList) cl,
                         (void *) ensAssemblyexceptionNewRef(ae));
    }

    ajListIterDel(&iter);

    return;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
AjBool ajPatlistSeqGetNext (AjPPatlistSeq thys, AjPPatternSeq* pattern)
{
    if (!thys->Iter)
	thys->Iter = ajListIterNew(thys->Patlist);

    if (!ajListIterDone(thys->Iter))
	*pattern = ajListIterGet(thys->Iter);
    else
    {
	ajPatlistSeqRewind(thys);
	return ajFalse;
    }

    return ajTrue;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
/* @funcstatic skipredundant_ClearList **************************************
**
** Clears a list of sequences from a sequence set.
** The sequences are copied
**
** @param [u] list   [AjPList] List 
** @return [AjBool] True on success
******************************************************************************/
static AjBool skipredundant_ClearList (AjPList list)
{
    EmbPDmxNrseq seq_tmp = NULL;
    AjIList iter;

    if(!list)
      return ajFalse;
    
    iter = ajListIterNew(list);
    while(!ajListIterDone(iter))
    {
        seq_tmp = (EmbPDmxNrseq)ajListIterGet(iter);
        embDmxNrseqDel(&seq_tmp);
    }
    ajListIterDel(&iter);
    
    return ajTrue;
}
Exemplo n.º 7
0
static AjBool cacheNodeRemove(EnsPCache cache, const CachePNode node)
{
    AjIList iter = NULL;

    CachePNode lnode = NULL;

    if(!cache)
        return ajFalse;

    if(!node)
        return ajFalse;

    /* Remove the node from the AJAX List. */

    iter = ajListIterNew(cache->List);

    while(!ajListIterDone(iter))
    {
        lnode = (CachePNode) ajListIterGet(iter);

        if(lnode == node)
        {
            ajListIterRemove(iter);

            break;
        }
    }

    ajListIterDel(&iter);

    /* Remove the node from the AJAX Table. */

    ajTableRemove(cache->Table, node->Key);

    /* Update the cache statistics. */

    cache->Bytes -= node->Bytes;

    cache->Count--;

    cache->Removed++;

    return ajTrue;
}
Exemplo n.º 8
0
/* @funcstatic sigscanlig_WriteResults ****************************************
**
** Function to write SIGSCANLIG results file. 
**
** @param [r] results  [AjPList] List of Lighit objects. 
** @param [r] resultsf  [AjPFile] Results file.
**
** @return [ajint] 1 if score1<score2, 0 if score1==score2, else -1.
** @@
******************************************************************************/
void sigscanlig_WriteResults(AjPList results, AjPFile resultsf)
{
    AjIList   iter      = NULL;   /* Iterator. */
    SigPLighit lighit    = NULL;
    
    iter = ajListIterNew(results);

    ajFmtPrintF(resultsf, "%-10s%-10s%-10s%-10s\n",
		"LIGID", "PATCHES", "SITES", "SCORE");
    
    while((lighit = (SigPLighit) ajListIterGet(iter)))
	ajFmtPrintF(resultsf, "%-10S%-10d%-10d%-10.2f\n",
		    lighit->ligid, lighit->np, lighit->ns, lighit->score);


    ajListIterDel(&iter);

    return;
}
Exemplo n.º 9
0
AjBool ensAssemblyexceptionadaptorFetchAllBySeqregionIdentifier(
    const EnsPAssemblyexceptionadaptor aea,
    ajuint srid,
    AjPList aes)
{
    AjIList iter = NULL;
    AjPList list = NULL;

    EnsPAssemblyexception ae = NULL;

    if(ajDebugTest("ensAssemblyexceptionadaptorFetchAllBySeqregionIdentifier"))
        ajDebug("ensAssemblyexceptionadaptorFetchAllBySeqregionIdentifier\n"
                "  aea %p\n"
                "  srid %u\n"
                "  aes %p\n",
                aea,
                srid,
                aes);

    if(!aea)
        return ajFalse;

    if(!aes)
        return ajFalse;

    list = (AjPList) ajTableFetch(aea->CacheBySeqregionIdentifier,
                                  (const void *) &srid);

    iter = ajListIterNew(list);

    while(!ajListIterDone(iter))
    {
        ae = (EnsPAssemblyexception) ajListIterGet(iter);

        ajListPushAppend(aes, (void *) ensAssemblyexceptionNewRef(ae));
    }

    ajListIterDel(&iter);

    return ajTrue;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
static void extractfeat_FeatureFilter(AjPFeattable featab,
				      const AjPStr source, const AjPStr type,
				      ajint sense, AjBool testscore,
				      float minscore, float maxscore,
				      const AjPStr tag, const AjPStr value)
{
    AjIList iter = NULL;
    AjPFeature gf = NULL;

    /*
     ** 'tagsmatch' is set true if a parent of a join()
     ** has matching tag/values.
     ** Remember the value of a the pattern match to the tags
     ** of the parent of a join() because the children of the join()
     ** don't contain the tags information in their gf's
     */
    AjBool tagsmatch = ajFalse;


    /* foreach feature in the feature table */
    if(featab)
    {
	iter = ajListIterNew(featab->Features);
	while(!ajListIterDone(iter))
	{
	    gf = (AjPFeature)ajListIterGet(iter);
	    if(!extractfeat_MatchFeature(gf, source, type, sense, testscore,
					 minscore, maxscore, tag, value,
					 &tagsmatch))
	    {
		/* no match, so delete feature from feature table */
		ajFeatDel(&gf);
		ajListIterRemove(iter);
	    }
	}
	ajListIterDel(&iter);
   }

    return;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
int main(int argc, char** argv)
{
    AjPFile outf = NULL;
    AjPFile cachef = NULL;

    AjIList iterator = NULL;
    AjPList aliases  = NULL;
    AjPList dbas     = NULL;
    AjPList species  = NULL;

    AjPStr alias   = NULL;
    AjPStr dbname  = NULL;
    AjPStr spname  = NULL;
    AjPStr svrname = NULL;
    AjPStr svrurl  = NULL;
    AjPStr dbcurl  = NULL;

    AjPTime svrtime = NULL;

    EnsEDatabaseadaptorGroup dbag = ensEDatabaseadaptorGroupNULL;

    EnsPDatabaseadaptor dba = NULL;

    EnsPDatabaseconnection dbc = NULL;

    embInit("cacheensembl", argc, argv);
    ensInit();

    svrname = ajAcdGetString("servername");
    outf    = ajAcdGetOutfile("outfile");
    cachef = ajAcdGetOutfile("cachefile");

    dbcurl = ajStrNew();
    svrurl = ajStrNew();
    dbname = ajStrNew();

    ajNamSvrGetUrl(svrname, &svrurl);

    if(!svrurl)
        ajFatal("Could not resolve server name '%S'.", svrname);

    dbc = ensDatabaseconnectionNewUrl(svrurl);
    ensRegistryLoadDatabaseconnection(dbc);
    ensDatabaseconnectionDel(&dbc);

    /* Write the server file header. */

    svrtime = ajTimeNewTodayFmt("cachefile");
    ajFmtPrintF(cachef, "# %S %D\n", ajFileGetNameS(cachef), svrtime);
    ajTimeDel(&svrtime);

    ajFmtPrintF(cachef,
                "# Automatically generated by cacheensembl "
                "for server '%S'.\n\n",
                svrname);

    /*
    ** Get all Ensembl Database Adaptor objects and write them as
    ** EMBOSS Database definitions.
    */

    aliases = ajListstrNew();
    dbas    = ajListNew();
    species = ajListstrNew();

    ensRegistryRetrieveAllSpecies(species);

    while(ajListstrPop(species, &spname))
    {
        ensRegistryGetAllDatabaseadaptors(ensEDatabaseadaptorGroupNULL,
                                          spname,
                                          dbas);

        while(ajListPop(dbas, (void**) &dba))
        {
            dbag = ensDatabaseadaptorGetGroup(dba);

            if(dbag == ensEDatabaseadaptorGroupNULL)
            {
                ajDebug("cacheensembl main got unexpected "
                        "Ensembl Database Adaptor Group %d.\n",
                        dbag);

                continue;
            }

            ajStrAssignS(&dbname, ensDatabaseadaptorGetSpecies(dba));

            if(dbag != ensEDatabaseadaptorGroupCore)
            {
                ajStrAppendC(&dbname, "_");
                ajStrAppendC(&dbname, ensDatabaseadaptorGroupToChar(dbag));
            }

            dbc = ensDatabaseadaptorGetDatabaseconnection(dba);

            ensDatabaseconnectionFetchUrl(dbc, &dbcurl);

            if(outf)
                ajFmtPrintF(outf, "%S\n", dbname);

            ajFmtPrintF(cachef, "DBNAME %S [\n", dbname);
            ajFmtPrintF(cachef, "  release: \"%s\"\n", ensSoftwareGetVersion());
            ajFmtPrintF(cachef, "  server:  \"%S\"\n", svrname);
            ajFmtPrintF(cachef, "  url:     \"%S\"\n", dbcurl);
            ajFmtPrintF(cachef, "]\n");
            ajFmtPrintF(cachef, "\n");

            if(dbag != ensEDatabaseadaptorGroupCore)
                continue;

            ensRegistryAliasFetchAllbySpecies(
                ensDatabaseadaptorGetSpecies(dba),
                aliases);

            /*
            ** Format all aliases to lower case,
            ** sort them alphabetically and remove duplicates.
            */

            iterator = ajListIterNew(aliases);
            while(!ajListIterDone(iterator))
            {
                alias = ajListstrIterGet(iterator);
                ajStrFmtLower(&alias);
            }
            ajListIterDel(&iterator);

            ajListSortUnique(aliases,
                             cacheensembl_stringcompare,
                             cacheensembl_stringdelete);

            alias = NULL;
            if(ajListGetLength(aliases) > 0)
            {
                while(ajListstrPop(aliases, &alias))
                {
                    /*
                    ** Reject any aliases with other than alpha-numeric
                    ** characters like white space.
                    */

                    if(ajStrIsAlnum(alias))
                        ajFmtPrintF(cachef,
                                    "ALIAS %S %S\n",
                                    alias,
                                    ensDatabaseadaptorGetSpecies(dba));

                    ajStrDel(&alias);
                }

                ajFmtPrintF(cachef, "\n");
            }

            /* Ensembl Database Adaptor objects *must not* be deleted. */
        }

        ajStrDel(&spname);
    }

    ajListstrFree(&aliases);
    ajListFree(&dbas);

    ajStrDel(&dbcurl);
    ajStrDel(&svrurl);
    ajStrDel(&dbname);
    ajStrDel(&svrname);

    ajFileClose(&outf);
    ajFileClose(&cachef);

    embExit();

    return EXIT_SUCCESS;
}
Exemplo n.º 14
0
static void remap_NoCutList(AjPFile outfile, const AjPTable hittable,
			    AjBool html, const AjPStr enzymes, AjBool blunt,
			    AjBool sticky, ajuint sitelen, AjBool commercial,
			    AjBool ambiguity, AjBool limit,
			    const AjPTable retable)
{

    /* for iterating over hittable */
    PValue value;
    void **keyarray = NULL;			/* array for table */
    void **valarray = NULL;			/* array for table */
    ajint i;

    /* list of enzymes that cut */
    AjPList cutlist;
    AjIList citer;			/* iterator for cutlist */
    AjPStr cutname = NULL;
    AjBool found;

    /* for parsing value->iso string */
    AjPStrTok tok;
    char tokens[] = " ,";
    AjPStr code = NULL;
    const char *p;

    /* for reading in enzymes names */
    AjPFile enzfile = NULL;
    AjPStr *ea;
    ajint ne;				/* number of enzymes */
    AjBool isall = ajTrue;

    /* list of enzymes that don't cut */
    AjPList nocutlist;
    AjIList niter;			/* iterator for nocutlist */
    AjPStr nocutname = NULL;

    /* count of rejected enzymes not matching criteria */
    ajint rejected_count = 0;

    EmbPPatRestrict enz;

    /* for renaming preferred isoschizomers */
    AjPList newlist;

     /*
     **
     ** Make a list of enzymes('cutlist') that hit
     ** including the isoschizomer names
     **
     */
    ajDebug("Make a list of all enzymes that cut\n");


    cutlist   = ajListstrNew();
    nocutlist = ajListstrNew();


    ajTableToarrayKeysValues(hittable, &keyarray, &valarray);
    for(i = 0; keyarray[i]; i++)
    {
        value = (PValue) valarray[i];
        cutname = ajStrNew();
        ajStrAssignRef(&cutname, keyarray[i]);
        ajListstrPushAppend(cutlist, cutname);

        /* Add to cutlist all isoschizomers of enzymes that cut */
        ajDebug("Add to cutlist all isoschizomers of enzymes that cut\n");

        /* start token to parse isoschizomers names */
        tok = ajStrTokenNewC(value->iso,  tokens);
        while(ajStrTokenNextParseC(&tok, tokens, &code))
        {
            cutname = ajStrNew();
            ajStrAssignS(&cutname, code);
            ajListstrPushAppend(cutlist, cutname);
        }
        ajStrTokenDel(&tok);
    }
    ajStrDel(&code);
    AJFREE(keyarray);
    AJFREE(valarray);



     /*
     ** Read in list of enzymes ('nocutlist') - either all or
     ** the input enzyme list.
     ** Exclude those that don't match the selection criteria - count these.
     */

    ajDebug("Read in a list of all input enzyme names\n");

    ne = 0;
    if(!enzymes)
	isall = ajTrue;
    else
    {
	/* get input list of enzymes into ea[] */
	ne = ajArrCommaList(enzymes, &ea);
	if(ajStrMatchCaseC(ea[0], "all"))
	    isall = ajTrue;
	else
	{
	    isall = ajFalse;
	    for(i=0; i<ne; ++i)
		ajStrRemoveWhite(&ea[i]);
	}
    }

    enzfile = ajDatafileNewInNameC(ENZDATA);

    /* push all enzyme names without the required criteria onto nocutlist */

    enz = embPatRestrictNew();
    while(!ajFileIsEof(enzfile))
    {
        if(!embPatRestrictReadEntry(enz, enzfile))
	    continue;

         /* 
	 ** If user entered explicit enzyme list, then check to see if
	 ** this is one of that explicit list 
	 */
        if(!isall)
	{
            found = AJFALSE;
            for(i=0; i<ne; ++i)
                if(ajStrMatchCaseS(ea[i], enz->cod))
		{
		    found = AJTRUE;
                    break;
                }

	    if(!found)			/* not in the explicit list */
		continue;

	    ajDebug("RE %S is in the input explicit list of REs\n", enz->cod);
	}

	/* ignore ncuts==0 as they are unknown */
	if(!enz->ncuts)
	{
	    /* number of cut positions */
            ajDebug("RE %S has an unknown number of cut positions\n",
		    enz->cod);
	    continue;
	}
        ajDebug("RE %S has a known number of cut sites\n", enz->cod);

	if(enz->len < sitelen)
	{
	    /* recognition site length */
            ajDebug("RE %S does not have a long enough recognition site\n", 
		    enz->cod);
	    rejected_count++;
	    continue;
	}

	if(!blunt && enz->blunt)
	{
	    /* blunt/sticky */
            ajDebug("RE %S is blunt\n", enz->cod);
	    rejected_count++;
	    continue;
	}

	if(!sticky && !enz->blunt)
	{
	    /* blunt/sticky */
            ajDebug("RE %S is sticky\n", enz->cod);
	    rejected_count++;
	    continue;
	}

	/* commercially available enzymes have uppercase patterns */
	p = ajStrGetPtr(enz->pat);

         /* 
	 ** The -commercial qualifier is only used if we are searching
	 ** through 'all' of the REBASE database - if we have specified an
	 ** explicit list of enzymes then they are searched for whether or
	 ** not they are commercially available
	 */
	if((*p >= 'a' && *p <= 'z') && commercial && isall)
	{
            ajDebug("RE %S is not commercial\n", enz->cod);
	    rejected_count++;
	    continue;
        }

	if(!ambiguity && remap_Ambiguous(enz->pat)) {
	    ajDebug("RE %S is ambiguous\n", enz->cod);
	    rejected_count++;
	    continue;	
	}

        ajDebug("RE %S matches all required criteria\n", enz->cod);

        code = ajStrNew();
	ajStrAssignS(&code, enz->cod);
	ajListstrPushAppend(nocutlist, code);
    }
    embPatRestrictDel(&enz);
    ajFileClose(&enzfile);


    for(i=0; i<ne; ++i)
	if(ea[i])
	    ajStrDel(&ea[i]);

    if(ne)
	AJFREE(ea);

    /*
     ** Change names of enzymes in the non-cutter list
     ** to that of preferred (prototype) 
     ** enzyme name so that the isoschizomers of cutters
     ** will be removed from the 
     ** non-cutter list in the next bit.
     ** Remove duplicate prototype names.
     */
    if(limit)
    {
        newlist = ajListstrNew();
        remap_RenamePreferred(nocutlist, retable, newlist);
        ajListstrFreeData(&nocutlist);
        nocutlist = newlist;
        ajListSortUnique(nocutlist, remap_cmpcase, remap_strdel);
    }


     /*
     ** Iterate through the list of input enzymes removing those that are in
     ** the cutlist.
     */

    ajDebug("Remove from the nocutlist all enzymes and isoschizomers "
	    "that cut\n");

     /*
     **  This steps down both lists at the same time, comparing names and
     **  iterating to the next name in whichever list whose name compares
     **  alphabetically before the other.  Where a match is found, the
     **  nocutlist item is deleted.
     */

    ajListSort(nocutlist, remap_cmpcase);
    ajListSort(cutlist, remap_cmpcase);

    citer = ajListIterNewread(cutlist);
    niter = ajListIterNew(nocutlist);

    /*
       while((cutname = (AjPStr)ajListIterGet(citer)) != NULL)
       ajDebug("dbg cutname = %S\n", cutname);
       */

    nocutname = (AjPStr)ajListIterGet(niter);
    cutname   = (AjPStr)ajListIterGet(citer);

    ajDebug("initial cutname, nocutname: '%S' '%S'\n", cutname, nocutname);

    while(nocutname != NULL && cutname != NULL)
    {
	i = ajStrCmpCaseS(cutname, nocutname);
	ajDebug("compare cutname, nocutname: %S %S ", cutname, nocutname);
	ajDebug("ajStrCmpCase=%d\n", i);
	if(i == 0)
	{
	    /* match - so remove from nocutlist */
	    ajDebug("ajListstrRemove %S\n", nocutname);
	    ajListstrIterRemove(niter);
	    nocutname = (AjPStr)ajListIterGet(niter);
	     /* 
	     ** Don't increment the cutname list pointer here
	     ** - there may be more than one entry in the nocutname
	     ** list with the same name because we have converted 
	     ** isoschizomers to their preferred name
	     */
	    /* cutname = (AjPStr)ajListIterGet(citer); */
	}
	else if(i == -1)
	    /* cutlist name sorts before nocutlist name */
	    cutname = (AjPStr)ajListIterGet(citer);
	else if(i == 1)
	    /* nocutlist name sorts before cutlist name */
	    nocutname = (AjPStr)ajListIterGet(niter);
    }

    ajListIterDel(&citer);
    ajListIterDel(&niter);
    ajListstrFreeData(&cutlist);


     /* Print the resulting list of those that do not cut*/

    ajDebug("Print out the list\n");

    /* print the title */
    if(html)
	ajFmtPrintF(outfile, "<H2>");
    ajFmtPrintF(outfile, "\n\n# Enzymes that do not cut\n\n");

    if(html)
	ajFmtPrintF(outfile, "</H2>\n");

    if(html)
	ajFmtPrintF(outfile, "<PRE>");

    /*  ajListSort(nocutlist, ajStrVcmp);*/
    niter = ajListIterNewread(nocutlist);
    i = 0;
    while((nocutname = (AjPStr)ajListIterGet(niter)) != NULL)
    {
	ajFmtPrintF(outfile, "%-10S", nocutname);
	/* new line after every 7 names printed */
	if(i++ == 7)
	{
	    ajFmtPrintF(outfile, "\n");
	    i = 0;
	}
    }
    ajListIterDel(&niter);


    /* end the output */
    ajFmtPrintF(outfile, "\n");
    if(html) {ajFmtPrintF(outfile, "</PRE>\n");}



     /*
     ** Print the count of rejected enzymes
     ** N.B. This is the count of ALL rejected enzymes including all
     ** isoschizomers
     */

    if(html)
        ajFmtPrintF(outfile, "<H2>");
    ajFmtPrintF(outfile,
		"\n\n# No. of cutting enzymes which do not match the\n"
		"# SITELEN, BLUNT, STICKY, COMMERCIAL, AMBIGUOUS criteria\n\n");
    if(html)
	ajFmtPrintF(outfile, "</H2>\n");
    ajFmtPrintF(outfile, "%d\n", rejected_count);

    ajDebug("Tidy up\n");
    ajListstrFreeData(&nocutlist);
    ajListstrFreeData(&cutlist);

    return;
}
Exemplo n.º 15
0
AjPList sigscanlig_score_ligands_patch(AjPList hits)
{ 
    AjPList ret         = NULL;
    AjIList iter        = NULL;   /* Iterator. */
    EmbPHit  hit         = NULL;   
    AjPStr  prev_ligand = NULL;
    SigPLighit lighit    = NULL;
    float  score        = 0.0;
    ajint  nhits      = 0;      /* No. of hits (patches) for current ligand. */
    ajint  nsites     = 0;      /* No. of sites for current ligand. */


    ajint  prevsn      = -1;        /* Previous site number */    

    

    ret = ajListNew();
    prev_ligand = ajStrNew();

    iter = ajListIterNew(hits);

    while((hit = (EmbPHit) ajListIterGet(iter)))
    {
	/* New ligand */
	if((!ajStrMatchS(hit->Sig->Ligid, prev_ligand)))
	{
	    if(nhits)
		score /= nhits;
	    
	    if(lighit)
	    {
		lighit->ns = nsites; 
		lighit->np = nhits; 
		lighit->score =  score;
		ajStrAssignS(&lighit->ligid, prev_ligand);
		ajListPushAppend(ret, lighit);

	    }
	    
	    
	    lighit = sigscanlig_LighitNew();

	    nsites = 0;
	    nhits=0;
	    prevsn = -1;
	    score = 0;
	}
	
	
	/* Increment count of sites and hits/patches (for current ligand)
	   and patches (for current site) */
	if(hit->Sig->sn != prevsn)
	    nsites++;
	score+= hit->Score;
	
	nhits++;

	ajStrAssignS(&prev_ligand, hit->Sig->Ligid);
	prevsn = hit->Sig->sn;
    }
    
    /* Process last hit */
    if(nhits)
	score /= nhits;
	    
    if(lighit)
    {
	lighit->ns = nsites;
	lighit->np = nhits; 
	lighit->score = score;
	ajStrAssignS(&lighit->ligid, prev_ligand);
	ajListPushAppend(ret, lighit);
    }
	
    ajListSort(ret, sigscanlig_MatchinvScore);
    

    ajListIterDel(&iter);
    ajStrDel(&prev_ligand);

    return ret;
}
Exemplo n.º 16
0
/* @funcstatic sigscanlig_score_ligands_site *********************************
**
** Writes score data for ligands (Lighit objects) from individual hits to 
** signatures (Hit objects).  Site score method is used. List of hit objects
** must be sorted by ligand type and site number.
** 
** @param [r] hits    [const AjPList] List of hit objects.
** @return [AjBool] True on success
** @@
******************************************************************************/
AjPList sigscanlig_score_ligands_site(AjPList hits)

{ 
    AjPList ret         = NULL;
    AjIList iter        = NULL;   /* Iterator. */
    EmbPHit  hit         = NULL;   
    AjPStr  prev_ligand = NULL;
    SigPLighit lighit    = NULL;


    ajint  prevsn      = -1;        /* Previous site number */


    float  score        = 0.0;    /* Score for current ligand */
    ajint  nhits        = 0;      /* No. of hits (patches) for current
				     ligand. */
    ajint  nsites       = 0;      /* No. of sites for current ligand */

    float  score_site   = 0.0;    /* Score for this site. */
    ajint  patch_cnt    = 0;      /* No. of patches in current site. */
    
    

    ret = ajListNew();
    prev_ligand = ajStrNew();
  
    iter = ajListIterNew(hits);


    /* Hits are already sorted by ligid & site number */
    while((hit = (EmbPHit) ajListIterGet(iter)))
    {
	/* ajFmtPrint("Current hit: %S (ligid: %S, sn: %d) score: %f\n", 
		   hit->Acc, hit->Sig->Ligid, hit->Sig->sn, hit->Score); */
	
	/* New site */
	if(hit->Sig->sn != prevsn)
	{
	    if(patch_cnt)
		score_site /= patch_cnt;
	    score += score_site;

	    patch_cnt  = 0;
	    score_site = 0;
	}

	/* New ligand */
	if((!ajStrMatchS(hit->Sig->Ligid, prev_ligand)))
	{
	    if(nsites)
		score /= nsites;
	    
	    if(lighit)
	    {
		/* lighit->ns = snarr_siz; */
		lighit->ns = nsites;
		lighit->np = nhits; 
		lighit->score =  score;

		ajStrAssignS(&lighit->ligid, prev_ligand);
		ajListPushAppend(ret, lighit);

	    }
	    
	    lighit = sigscanlig_LighitNew();

	    nsites = 0;
	    nhits=0;
	    prevsn = -1;
	    score = 0;
	}

	
	/* Increment count of sites and hits/patches (for current
           ligand) and patches (for current site) */
	if(hit->Sig->sn != prevsn)
	    nsites++;
	score_site += hit->Score;

	nhits++;
	patch_cnt++;
	
	ajStrAssignS(&prev_ligand, hit->Sig->Ligid);
	prevsn = hit->Sig->sn;
    }
    
    /* Process last hit */
    if(patch_cnt)
	score_site /= patch_cnt;
    score += score_site;
    
    if(nsites)
	score /= nsites;
	    
    if(lighit)
    {
	/* lighit->ns = snarr_siz; */
	lighit->ns = nsites;
	lighit->np = nhits; 
	lighit->score = score;
	ajStrAssignS(&lighit->ligid, prev_ligand);
	ajListPushAppend(ret, lighit);
    }
	

    ajListSort(ret, sigscanlig_MatchinvScore);
    

    ajListIterDel(&iter);
    ajStrDel(&prev_ligand);

    return ret;
}
Exemplo n.º 17
0
int main(int argc, char **argv)
{
    AjPList      sigin   = NULL;   /* Signature input file names.            */
    AjPStr       signame = NULL;   /* Name of signature file.                */
    AjPFile      sigf    = NULL;   /* Signature input file.                  */
    EmbPSignature sig    = NULL;   /* Signature.                             */
    AjPList      siglist = NULL;   /* List of signatures.                    */
    AjIList      sigiter = NULL;   /* Iterator for siglist.                  */
    AjBool       sigok  = ajFalse; /* True if signature processed ok.        */
    
    EmbPHit      hit = NULL;      /* Hit to store signature-sequence match.  */
    AjPList      hits = NULL;     /* List of hits */


    AjPList      ligands = NULL;     /* List of top-scoring ligands. */

    AjPSeqall    database=NULL;   /* Protein sequences to match signature 
				     against.                                */
    AjPSeq       seq = NULL;      /* Current sequence.                       */
    AjPMatrixf   sub  =NULL;      /* Residue substitution matrix.            */
    float        gapo =0.0;       /* Gap insertion penalty.                  */
    float        gape =0.0;       /* Gap extension penalty.                  */

    AjPStr        nterm=NULL;     /* Holds N-terminal matching options from 
				     acd.                                    */
    ajint         ntermi=0;        /* N-terminal option as int. */

    AjPFile      hitsf =NULL;     /* Hits output file.                       
				     sequence matches.                       */
    AjPDirout    hitsdir=NULL;    /* Directory of hits files (output).       */

    AjPFile      alignf =NULL;    /* Alignment output file.                  */
    AjPDirout    aligndir=NULL;   /* Directory of alignment files (output).  */

    
    AjPFile    resultsf =NULL;    /* Results file (output).  */
    AjPDirout  resultsdir=NULL;   /* Directory of results files (output).  */

    AjPStr  mode         = NULL;  /* Mode, 1: Patch score mode, 2:
				     Site score mode.  */
    ajint   modei        = 0;     /* Selected mode as integer.  */

    SigPLighit lighit   = NULL;

    embInitPV("sigscanlig", argc, argv, "SIGNATURE",VERSION);
    

    /* GET VALUES FROM ACD */
    sigin      = ajAcdGetDirlist("siginfilesdir");
    database   = ajAcdGetSeqall("dbseqall");
    sub        = ajAcdGetMatrixf("sub");
    gapo       = ajAcdGetFloat("gapo");
    gape       = ajAcdGetFloat("gape");
    nterm      = ajAcdGetListSingle("nterm");
    hitsdir    = ajAcdGetOutdir("hitsoutdir");
    aligndir   = ajAcdGetOutdir("alignoutdir"); 
    resultsdir = ajAcdGetOutdir("resultsoutdir"); 
    mode        = ajAcdGetListSingle("mode");



    /*Assign N-terminal matching option etc. */
    ajFmtScanS(nterm, "%d", &ntermi);
    modei       = (ajint) ajStrGetCharFirst(mode)-48;



    /* READ & PROCESS SIGNATURES */
    siglist = ajListNew();
    while(ajListPop(sigin, (void **) &signame))
    {
	/* Read signature files, compile signatures and populate list. */
	sigok = ajFalse;
	if((sigf = ajFileNewInNameS(signame)))
	    if((sig = embSignatureReadNew(sigf)))
		if(embSignatureCompile(&sig, gapo, gape, sub))
		{
		    sigok=ajTrue;
		    ajListPushAppend(siglist, sig);
		    /*
		    ajFmtPrint("Id: %S\nDomid: %S\nLigid: %S\nns: %d\n"
                               "sn: %d\nnp: %d\npn: %d\nminpatch: %d\n"
                               "maxgap: %d\n", 
			       sig->Id, sig->Domid, sig->Ligid, sig->ns,
                               sig->sn, sig->np, sig->pn, sig->minpatch,
                               sig->maxgap); */
		    

		}
	if(!sigok)
	{
	    ajWarn("Could not process %S", signame);
	    embSignatureDel(&sig);
	    ajFileClose(&sigf);
	    ajStrDel(&signame);
	    continue;
	}

	ajFileClose(&sigf);
	ajStrDel(&signame);
    }
    ajListFree(&sigin);

    
    
    /* ALIGN EACH QUERY SEQUENCE TO LIST OF SIGNATURE */
    while(ajSeqallNext(database, &seq))
    {
	/* Do sequence-signature alignment and save results */
	hits = ajListNew();
	sigiter = ajListIterNew(siglist);
	
	while((sig = (EmbPSignature) ajListIterGet(sigiter)))
	{
	    if(embSignatureAlignSeq(sig, seq, &hit, ntermi))
	    {
		hit->Sig = sig;
		
		ajListPushAppend(hits, hit);
		hit=NULL; /* To force reallocation by embSignatureAlignSeq */
	    }
	    /* There has to be a hit for each signature for correct
	       generation of the LHF by sigscanlig_WriteFasta. So push
	       an empty hit if necessary.  'hit'=NULL forces
	       reallocation by embSignatureAlignSeq. */
	    /*
	       else
	       {
		hit = embHitNew();
		ajListPushAppend(hits, hit);
		hit=NULL; 
		}
		*/
	}
	
	ajListIterDel(&sigiter);
	

	/* Rank-order the list of hits by score */
	ajListSort(hits, embMatchinvScore);

	
	/* Write ligand hits & alignment files (output)  */	
	hitsf    = ajFileNewOutNameDirS(ajSeqGetNameS(seq), hitsdir);
	alignf   = ajFileNewOutNameDirS(ajSeqGetNameS(seq), aligndir);
	resultsf = ajFileNewOutNameDirS(ajSeqGetNameS(seq), resultsdir);
	

	
	/* if((!sigscanlig_WriteFasta(hitsf, siglist, hits)))
	    ajFatal("Bad args to sigscanlig_WriteFasta"); */

	if((!sigscanlig_WriteFasta(hitsf, hits)))
	    ajFatal("Bad args to sigscanlig_WriteFasta");


    	if((!sigscanlig_SignatureAlignWriteBlock(alignf, hits)))
	    ajFatal("Bad args to sigscanlig_SignatureAlignWriteBlock");

    	/* if((!sigscanlig_SignatureAlignWriteBlock(alignf, siglist, hits)))
	    ajFatal("Bad args to sigscanlig_SignatureAlignWriteBlock"); */


	/* Sort list of hits by ligand type and site number.
	   Process list of ligands and print out. */
	ajListSortTwo(hits, embMatchLigid, embMatchSN);


	if(modei==1)
	    ligands = sigscanlig_score_ligands_patch(hits);
	else if(modei==2)
	    ligands = sigscanlig_score_ligands_site(hits);
	else 
	    ajFatal("Unrecognised mode");
	

	sigscanlig_WriteResults(ligands, resultsf);	
	

    	ajFileClose(&hitsf);
	ajFileClose(&alignf);
	ajFileClose(&resultsf);


	/* Memory management */
	while(ajListPop(hits, (void **) &hit))
	    embHitDel(&hit);
	ajListFree(&hits);

        while(ajListPop(ligands, (void **) &lighit))
            sigscanlig_LigHitDel(&lighit);
        ajListFree(&ligands);
    }	
    

    /* MEMORY MANAGEMENT */
    while(ajListPop(siglist, (void **) &sig))
	embSignatureDel(&sig);
    ajListFree(&siglist);

    ajSeqallDel(&database);
    ajMatrixfDel(&sub);
	
    ajStrDel(&nterm);    
    ajDiroutDel(&hitsdir);
    ajDiroutDel(&aligndir);
    ajDiroutDel(&resultsdir);
    ajStrDel(&mode);


    embExit();

    return 0;    
}
Exemplo n.º 18
0
static AjBool sigscanlig_SignatureAlignWriteBlock(AjPFile outf,
						  AjPList hits)

/*
static AjBool sigscanlig_SignatureAlignWriteBlock(AjPFile outf,
						  AjPList siglist, 
						  AjPList hits)
*/

{
    /*
    ** A line of the alignment (including accession number, a space and the 
    ** sequence) in the output file is 70 characters long. An index number is 
    ** also printed after this 70 character field.
    */
    ajint  wid1  = 0;    /*Temp. width of Accession Number */
    ajint  mwid1 = 0;    /*
			 ** Max. width of Accession Number or the string
			 ** "Number". 
			 ** This is the field width the accession numbers
			 ** will be  printed into
			 */
    ajint  mwid2 = 0;    /* Width of region to print sequence into */
    ajint  len   = 0;    /* Temp. length of sequence */
    ajint  mlen  = 0;    /* Max. length of sequence */
    const char   *ptrp = NULL; /* Pointer to sequence string */ 
    const char   *ptrs = NULL; /* Pointer to alignment string */ 
    ajint  idx   = 0;    /* Start position for printing */
    ajint  niter = 0;    /*
			 ** No. iterations of loop for printing out
			 ** sequence blocks
			 */
    ajint  fwid1 = 70;   /*
			 ** Including accession number, a space, 7 characters 
			 ** for the first index number, and the sequence
			 */
    ajint  fwid2 = 7;    /* Field width for the first index number */
    ajint  num   = 0;    /* Index number for alignment */
    ajint  y     = 0;    /* Loop counter */

    AjIList iter    = NULL;	
    AjIList itersig = NULL;
    EmbPHit hit = NULL;
    ajint hitcnt=0;      /* Counter for current hit */
    AjPStr label = NULL;
    


    /* Check args */
/*    if(!outf || !hits || !siglist)
	return ajFalse; */

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


    /* Cycle through hits to find longest width of accession number. */
    len=0;
    mlen=0;	
    wid1=0;
    mwid1=0;
    label = ajStrNew();
    
	
    iter = ajListIterNew(hits);
    while((hit = (EmbPHit) ajListIterGet(iter)))
    {
	if((wid1=MAJSTRGETLEN(hit->Sig->Ligid))>mwid1)
	    mwid1 = wid1; 
	if((len=MAJSTRGETLEN(hit->Seq))>mlen)
	    mlen = len;
    }
    ajListIterDel(&iter);
    ajListIterDel(&itersig);



    /* Assign field widths and number of iterations for printing. */
    if((wid1 = strlen("SIGNATURE"))>mwid1)
	mwid1 = wid1;
    mwid1++;   /* A space */
    mwid1 += 8;  /* 2 underscores + 2 integers in 3 char spacing each. */
    mwid2 = fwid1-fwid2-mwid1;
    niter = (ajint)ceil( ((double)mlen/(double)mwid2));
    

    /* Print header info and SCOP classification records of signature */
    ajFmtPrintF(outf,
		"# DE   Alignment of query sequence against library of "
		"signatures\n");

    
    /* Main loop for printing alignment. */
    iter = ajListIterNew(hits);
    while((hit = (EmbPHit) ajListIterGet(iter)))
    {
	/* Get pointer to sequence & alignment string. */
	ptrp = ajStrGetPtr(hit->Seq);
	ptrs = ajStrGetPtr(hit->Alg);

	/* Print spacer */
	ajFmtPrintF(outf, "# XX\n");

	ajFmtPrintF(outf, "# ");
	/*	if((!sigscanlig_WriteFastaHit(outf, siglist, hits,
                                              hitcnt, ajFalse)))
		ajFatal("Bad args to sigscanlig_WriteFasta"); */

	if((!sigscanlig_WriteFastaHit(outf, hits, hitcnt, ajFalse)))
	    ajFatal("Bad args to sigscanlig_WriteFasta");
	ajFmtPrintF(outf, "\n# XX\n");

	/* Loop for each protein in Hitlist. */
	for(num=0, idx=0, y=0;y<niter;y++)
	{
	    num+=mwid2;


	    ajFmtPrintS(&label, "%S_%d_%d",
			hit->Sig->Ligid, hit->Sig->sn, hit->Sig->pn);
	    

	    /* There is some of the sequence left to print. */
	    if(idx<MAJSTRGETLEN(hit->Seq))
	    {
		ajFmtPrintF(outf,"%-*S%-*d%-*.*s %d\n", 
			    mwid1, hit->Acc, fwid2, 
			    (num-mwid2+1), mwid2, mwid2, ptrp+idx, num);
		ajFmtPrintF(outf,"%-*S%-*c%-*.*s\n", 
			    mwid1, label, fwid2, '-', mwid2, 
			    mwid2, ptrs+idx);
	    }	
	    /* Printed all the sequence already. */
	    else
	    {
		ajFmtPrintF(outf,"%-*S%-*d%-*.*s %d\n", 
			    mwid1, hit->Acc, fwid2,  
			    (num-mwid2+1), mwid2, mwid2, ".", num);
		ajFmtPrintF(outf,"%-*S%-*c%-*.*s\n", 
			    mwid1, label, fwid2, '-', mwid2, 
			    mwid2, "." );
	    }
	    idx += mwid2;
	}

	hitcnt++;
    }	 
    ajListIterDel(&iter);
    ajListIterDel(&itersig);
    ajStrDel(&label);
    

    return ajTrue;
}
Exemplo n.º 19
0
void* ensCacheFetch(EnsPCache cache, void *key)
{
    void *value = NULL;

    AjIList iter = NULL;

    CachePNode lnode = NULL;
    CachePNode tnode = NULL;

    if(!cache)
        return NULL;

    if(!key)
        return NULL;

    tnode = (CachePNode) ajTableFetch(cache->Table, key);

    if(tnode)
    {
        cache->Hit++;

        /* Move the node to the end of the list. */

        iter = ajListIterNew(cache->List);

        while(!ajListIterDone(iter))
        {
            lnode = (CachePNode) ajListIterGet(iter);

            if(lnode == tnode)
            {
                ajListIterRemove(iter);

                ajListPushAppend(cache->List, (void *) lnode);

                break;
            }
        }

        ajListIterDel(&iter);

        /*
        ** Reference the object when returned by the cache so that external
        ** code has to delete it irrespectively whether it was read from the
        ** cache or instantiated by the cache->Read function.
        */

        if(cache->Reference && tnode->Value)
            value = (*cache->Reference)(tnode->Value);
    }
    else
    {
        cache->Miss++;

        if(cache->Read)
        {
            value = (*cache->Read)(key);

            if(value)
            {
                tnode = cacheNodeNew(cache, key, value);

                if(!cacheNodeInsert(cache, tnode))
                    cacheNodeDel(cache, &tnode);
            }
        }
    }

    return value;
}
Exemplo n.º 20
0
static AjBool resourceoutWriteWebpage(AjPFile outf, const AjPResource resource)
{
    AjPResquery tmpqry = NULL;
    AjPResterm resterm = NULL;
    AjPStr  snstr   = NULL;
    AjPStr  tmpstr   = NULL;
    AjPStr  tmpurl   = NULL;
    AjPStr  tmpid    = NULL;
    AjPStr  tmpname  = NULL;
    AjPStr  tmpqid   = NULL;
    AjPStr  tmpqname = NULL;
    AjPStr  tmpqterm = NULL;
    AjIList iter     = NULL;
    AjIList iterq    = NULL;
    ajuint i = 0;
    AjPStrTok handle = NULL;
    AjPStrTok namehandle = NULL;
    AjPStrTok termhandle = NULL;
    const char* biourl = "http://bioportal.bioontology.org/ontologies/45846";

    if(!outf)
        return ajFalse;

    ajFmtPrintF(outf,
                "<!DOCTYPE HTML PUBLIC "
                "\"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
    ajFmtPrintF(outf,
                "<html>\n");

    ajFmtPrintF(outf,
                "<head>\n");
    ajFmtPrintF(outf,
                "<meta http-equiv=\"Content-Type\" "
                "content=\"text/html;charset=UTF-8\" />\n");
    ajFmtPrintF(outf,
                "<title>Bioinformatics Data Resource Catalogue</title>\n");
    ajFmtPrintF(outf,
                "</head>\n\n\n");

    ajFmtPrintF(outf,
                "<body bgcolor=\"#ffffff\">\n");

    ajFmtPrintF(outf,
                "<!-- ID -->\n");

    if(ajStrGetLen(resource->Url))
       ajFmtPrintF(outf,
                   "<center><h1><a href=\"%S\">%S</a></h1></center>\n",
                   resource->Url, resource->Id);
    else
       ajFmtPrintF(outf,
                   "<center><h1>%S</h1></center>\n",
                   resource->Id);

    ajFmtPrintF(outf,
                "<!-- Name -->\n");

    ajFmtPrintF(outf,
                "<center><h2>%S</h2> </center>\n",
                resource->Name);

    ajFmtPrintF(outf,
                "<!-- Desc -->\n");
    ajFmtPrintF(outf,
                "<p><i>%S</i></p>\n",
                resource->Desc);

    ajFmtPrintF(outf,
                "<table>\n");

    ajFmtPrintF(outf,
                "<!-- ID -->\n");

    ajFmtPrintF(outf,
                "  <tr align=\"left\"><th>ID</th><td>%S</td></tr>\n",
                resource->Id);

    ajFmtPrintF(outf,
                "<!-- IDalt or omit -->\n");

    if(ajListGetLength(resource->Idalt))
    {
        ajFmtPrintF(outf,
                    "  <tr align=\"left\"><th>IDalt</th><td>");

        i = 0;
        iter = ajListIterNew(resource->Idalt);
        while((tmpstr = ajListstrIterGet(iter)))
        {
            if(i++)
                ajFmtPrintF(outf, ", ");
            ajFmtPrintF(outf, "%S", tmpstr);
        }

        ajListIterDel(&iter);

        ajFmtPrintF(outf,
                    "</td></tr>\n");
    }
 
    if(ajStrGetLen(resource->Acc))
    {
        ajFmtPrintF(outf,
                    "<!-- ACC or omit -->\n");
        
        ajFmtPrintF(outf,
                    "  <tr align=\"left\"><th>Acc</th><td>%S</td></tr>\n",
                    resource->Acc);
    }


    if(ajStrGetLen(resource->Url))
        ajFmtPrintF(outf,
                    "  <tr align=\"left\"><th>Home</th><td>"
                    "<a href=\"%S\">%S</a></td></tr>\n",
                    resource->Url, resource->Url);

    if(ajListGetLength(resource->Edamtpc))
    {
        ajFmtPrintF(outf,
                "<!-- EDAMtpc -->\n");

        iter = ajListIterNew(resource->Edamtpc);

        while((resterm = ajListIterGet(iter)))
        {
            ajStrAssignS(&tmpid, resterm->Id);
            ajStrCutBraces(&tmpid);
            ajStrFmtPercentEncodeC(&tmpid, " /()");
            ajFmtPrintF(outf,
                        "  <tr align=\"left\"><th>EDAM topic</th><td>"
                        "<a href=\"%s?p=terms&conceptid=EDAM%%3A%S\">%S</a>"
                        "</td></tr>\n",
                        biourl, tmpid, resterm->Name);
        }
        ajListIterDel(&iter);
    }

    ajFmtPrintF(outf,
                "<!-- Cat or omit -->\n");

    if(ajListGetLength(resource->Cat))
    {
        iter = ajListIterNew(resource->Cat);
        while((tmpstr = ajListstrIterGet(iter)))
            ajFmtPrintF(outf,
                        "  <tr align=\"left\"><th>Category</th>"
                        "<td>%S</td></tr>\n",
                        tmpstr);
        ajListIterDel(&iter);
    }
    
    ajFmtPrintF(outf,
                "<!-- Taxon (comma-separated list) -->\n");

    ajFmtPrintF(outf,
                "  <tr align=\"left\"><th>Taxon</th><td>");
    i = 0;
    iter = ajListIterNew(resource->Taxon);
    while((resterm = ajListIterGet(iter)))
    {
        if(i++)
            ajFmtPrintF(outf, ", ");
        ajFmtPrintF(outf,
                    "<a href=\"http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/"
                    "wwwtax.cgi?id=%S\">%S</a>",
                    resterm->Id, resterm->Name);
    }

    ajListIterDel(&iter);
    ajFmtPrintF(outf,
                "</td></tr>\n");
    

    ajFmtPrintF(outf,
                "<!-- URLlink or omit -->\n");

    if(ajStrGetLen(resource->Urllink))
         ajFmtPrintF(outf,
                     "<tr align=\"left\"><th>Linking</th><td>"
                     "<a href=\"%S\">%S</a></td></tr>\n",
                     resource->Urllink, resource->Urllink);

    ajFmtPrintF(outf,
                "<!-- URLrest or omit -->\n");

    if(ajStrGetLen(resource->Urlrest))
         ajFmtPrintF(outf,
                     "<tr align=\"left\"><th>REST</th><td>"
                     "<a href=\"%S\">%S</a></td></tr>\n",
                     resource->Urlrest, resource->Urlrest);

    ajFmtPrintF(outf,
                "<!-- URLsoap or omit -->\n");

    if(ajStrGetLen(resource->Urlsoap))
         ajFmtPrintF(outf,
                     "<tr align=\"left\"><th>SOAP</th><td>"
                     "<a href=\"%S\">%S</a></td></tr>\n",
                     resource->Urlsoap, resource->Urlsoap);

    ajFmtPrintF(outf,
                "<!-- Xref - omit ! -->\n");

    ajFmtPrintF(outf,
                "</table>\n");


    ajFmtPrintF(outf,
                "<!-- Query or omit, free-text comments given in {} --> \n");
    if(ajListGetLength(resource->Query))
    {
        ajFmtPrintF(outf,
                    "<h3>Available data</h3>\n");
        ajFmtPrintF(outf,
                    "<table>\n");
        ajFmtPrintF(outf,
                    "   <thead>\n");
        ajFmtPrintF(outf,
                    "      <tr align=\"left\">\n");
        ajFmtPrintF(outf,
                    "         <th>Data</th>\n");
        ajFmtPrintF(outf,
                    "         <th>Format</th>\n");
        ajFmtPrintF(outf,
                    "         <th>Query</th>\n");
        ajFmtPrintF(outf,
                    "         <th>Link</th>\n");
        ajFmtPrintF(outf,
                    "      </tr>\n");
        ajFmtPrintF(outf,
                    "   </thead>\n");
        ajFmtPrintF(outf,
                    "   <tbody>\n");

        iter = ajListIterNew(resource->Query);
        while((tmpqry = ajListIterGet(iter)))
        {
            ajStrAssignS(&tmpname, tmpqry->Datatype);
            ajStrCutBraces(&tmpname);
            ajStrFmtPercentEncodeC(&tmpname, " /()");
            ajFmtPrintF(outf,
                        "     <tr>\n");
            ajFmtPrintF(outf,
                        "       <td>"
                        "<a href=\"%s?"
                        "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n",
                        biourl, tmpname, tmpqry->Datatype);

            ajStrAssignS(&tmpname, tmpqry->Format);
            ajStrCutBraces(&tmpname);
            ajStrFmtPercentEncodeC(&tmpname, " /()");
            ajFmtPrintF(outf,
                        "       <td>"
                        "<a href=\"%s?"
                        "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n",
                        biourl, tmpname, tmpqry->Format);

            ajStrAssignS(&tmpname, tmpqry->Term);
            ajStrCutBraces(&tmpname);
            ajStrFmtPercentEncodeC(&tmpname, " /()");
            ajFmtPrintF(outf,
                        "       <td>"
                        "<a href=\"%s?"
                        "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n",
                        biourl, tmpname, tmpqry->Term);
            ajFmtPrintF(outf,
                        "       <td>%S</td>\n",
                        tmpqry->Url);
            ajFmtPrintF(outf,
                        "     </tr>\n\n");
        }
        ajListIterDel(&iter);

        ajFmtPrintF(outf,
                    "   </tbody>\n");
        ajFmtPrintF(outf,
                    "</table>\n");
    }

    ajFmtPrintF(outf,
                "<!-- Example or omit -->\n");

    if(ajListGetLength(resource->Example))
    {
        ajFmtPrintF(outf,
                    "<h3>Example queries</h3>\n");

        ajFmtPrintF(outf,
                    "<table>\n");
        ajFmtPrintF(outf,
                    "   <thead>\n");
        ajFmtPrintF(outf,
                    "      <tr align=\"left\">\n");
        ajFmtPrintF(outf,
                    "         <th>Data</th>\n");
        ajFmtPrintF(outf,
                    "         <th>Format</th>\n");
        ajFmtPrintF(outf,
                    "         <th>Query</th>\n");
        ajFmtPrintF(outf,
                    "         <th>Example</th>\n");
        ajFmtPrintF(outf,
                    "      </tr>\n");
        ajFmtPrintF(outf,
                    "   </thead>\n");
        ajFmtPrintF(outf,
                    "   <tbody>\n");

        iter = ajListIterNew(resource->Example);
        while((tmpstr = ajListstrIterGet(iter)))
        {
            ajStrTokenAssignC(&handle, tmpstr, "|");
            ajStrTokenNextParse(handle, &tmpid);
            ajStrRemoveWhiteExcess(&tmpid);
            ajStrTokenNextParse(handle, &tmpname);
            ajStrRemoveWhiteExcess(&tmpname);
            
            iterq = ajListIterNew(resource->Query);
            while((tmpqry = ajListIterGet(iterq)))
            {
                if(!ajStrMatchS(tmpid, tmpqry->Term))
                   continue;

                ajStrAssignS(&tmpqid, tmpqry->Datatype);
                ajStrCutBraces(&tmpqid);
                ajStrFmtPercentEncodeC(&tmpqid, " /()");

                ajFmtPrintF(outf,
                            "     <tr>\n");
                ajFmtPrintF(outf,
                            "       <td>"
                            "<a href=\"%s?"
                            "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n",
                            biourl, tmpqid, tmpqry->Datatype); /* datatype */

                ajStrAssignS(&tmpqid, tmpqry->Format);
                ajStrCutBraces(&tmpqid);
                ajStrFmtPercentEncodeC(&tmpqid, " /()");

                ajFmtPrintF(outf,
                            "       <td>"
                            "<a href=\"%s?"
                            "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n",
                            biourl, tmpqid, tmpqry->Format); /* format */

                ajStrAssignS(&tmpurl, tmpqry->Url);
                ajStrAssignS(&tmpqid, tmpqry->Term);
                ajStrCutBraces(&tmpqid);
                ajStrFmtPercentEncodeC(&tmpqid, " /()");

                i = 0;
                ajStrTokenAssignC(&handle, tmpid, ";");
                ajStrTokenAssignC(&namehandle, tmpname, ";");
                ajStrTokenAssignC(&termhandle, tmpqry->Term, ";");
                ajFmtPrintF(outf,
                            "       <td>");

                while(ajStrTokenNextParse(handle, &tmpqid))
                {
                    ajStrTokenNextParse(namehandle, &tmpqname);
                    ajStrTokenNextParse(termhandle, &tmpqterm);

                    if(i)
                        ajFmtPrintF(outf,
                                    "; ");
                                    
                    ajStrRemoveWhiteExcess(&tmpqid);
                    ajStrCutBraces(&tmpqid);

                    ajFmtPrintF(outf,
                                "<a href=\"%s?"
                                "p=terms&conceptid=EDAM%%3A%S\">%S</a>",
                                biourl, tmpqid, tmpqterm); /* id term */

                    ajFmtPrintS(&snstr, "%%s%u", (i+1));
                    ajStrExchangeSS(&tmpurl, snstr, tmpqname);
                        
                    i++;

                }
                ajFmtPrintF(outf,
                                "</td>\n");

                ajFmtPrintS(&snstr, "%%s");
                ajStrExchangeSS(&tmpurl, snstr, tmpname);

                ajFmtPrintF(outf,
                            "       <td><a href=\"%S\">%S</a></td>\n",
                            tmpurl, tmpname); /* url, exampleid */

                ajFmtPrintF(outf,
                                "     </tr>\n");
            }
            ajListIterDel(&iterq);
        }

        ajListIterDel(&iter);

        ajFmtPrintF(outf,
                    "   </tbody>\n");
        ajFmtPrintF(outf,
                    "</table>\n");
    }

    ajFmtPrintF(outf, "\n\n</body></html>\n");

    ajStrDel(&tmpid);
    ajStrDel(&tmpname);
    ajStrDel(&tmpurl);
    ajStrDel(&tmpqid);
    ajStrDel(&tmpqname);
    ajStrDel(&tmpqterm);
    ajStrDel(&snstr);

    ajStrTokenDel(&handle);
    ajStrTokenDel(&namehandle);
    ajStrTokenDel(&termhandle);

    return ajTrue;
}
Exemplo n.º 21
0
AjBool ensSeqDescTrace(const AjPSeqDesc seqdesc, ajuint level)
{
    AjIList iter = NULL;

    AjPStr indent = NULL;
    AjPStr value = NULL;

    if(!seqdesc)
        return ajFalse;

    indent = ajStrNew();

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

    ajDebug("%SensSeqDescTrace %p\n"
            "%S  Name      '%S'\n"
            "%S  Short      %p\n"
            "%S  EC         %p\n"
            "%S  AltNames   %p\n"
            "%S  SubNames   %p\n"
            "%S  Includes   %p\n"
            "%S  Contains   %p\n"
            "%S  Precursor '%B'\n"
            "%S  Fragments  %u\n",
            indent, seqdesc,
            indent, seqdesc->Name,
            indent, seqdesc->Short,
            indent, seqdesc->EC,
            indent, seqdesc->AltNames,
            indent, seqdesc->SubNames,
            indent, seqdesc->Includes,
            indent, seqdesc->Contains,
            indent, seqdesc->Precursor,
            indent, seqdesc->Fragments);

    /* Trace the AJAX List of AJAX String short names. */

    if(seqdesc->Short)
    {
        ajDebug("%S    AJAX List of AJAX String short names:\n", indent);

        iter = ajListIterNew(seqdesc->Short);

        while(!ajListIterDone(iter))
        {
            value = (AjPStr) ajListIterGet(iter);

            ajDebug("%S      '%S'\n", indent, value);
        }

        ajListIterDel(&iter);
    }

    /* Trace the AJAX List of AJAX String EC numbers. */

    if(seqdesc->EC)
    {
        ajDebug("%S    AJAX List of AJAX String EC numbers:\n", indent);

        iter = ajListIterNew(seqdesc->EC);

        while(!ajListIterDone(iter))
        {
            value = (AjPStr) ajListIterGet(iter);

            ajDebug("%S      '%S'\n", indent, value);
        }

        ajListIterDel(&iter);
    }

    ajStrDel(&indent);

    return ajTrue;
}
Exemplo n.º 22
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;
}
Exemplo n.º 23
0
static AjBool resourceoutWriteDrcat(AjPFile outf, const AjPResource resource)
{
    AjPReslink tmplink = NULL;
    AjPResquery tmpqry = NULL;
    AjPResterm resterm = NULL;
    AjPStr  tmpstr  = NULL;
    AjIList iter    = NULL;

    if(!outf)
        return ajFalse;

    ajFmtPrintF(outf, "%-8s%S\n", "ID", resource->Id);

    iter = ajListIterNew(resource->Idalt);
    while((tmpstr = ajListstrIterGet(iter)))
        ajFmtPrintF(outf, "%-8s%S\n", "IDalt", tmpstr);
    ajListIterDel(&iter);

    if(ajStrGetLen(resource->Acc))
        ajFmtPrintF(outf, "%-8s%S\n", "Acc", resource->Acc);
    ajFmtPrintF(outf, "%-8s%S\n", "Name", resource->Name);
    ajFmtPrintF(outf, "%-8s%S\n", "Desc", resource->Desc);

    if(ajStrGetLen(resource->Url))
        ajFmtPrintF(outf, "%-8s%S\n", "URL", resource->Url);
    if(ajStrGetLen(resource->Urllink))
        ajFmtPrintF(outf, "%-8s%S\n", "URLlink", resource->Urllink);
    if(ajStrGetLen(resource->Urlrest))
        ajFmtPrintF(outf, "%-8s%S\n", "URLrest", resource->Urlrest);
    if(ajStrGetLen(resource->Urlsoap))
        ajFmtPrintF(outf, "%-8s%S\n", "URLsoap", resource->Urlsoap);

    iter = ajListIterNew(resource->Cat);
    while((tmpstr = ajListstrIterGet(iter)))
        ajFmtPrintF(outf, "%-8s%S\n", "Cat", tmpstr);
    ajListIterDel(&iter);
    
    iter = ajListIterNew(resource->Taxon);
    while((resterm = ajListIterGet(iter)))
        ajFmtPrintF(outf, "%-8s%S | %S\n", "Taxon",
                    resterm->Id, resterm->Name);
    ajListIterDel(&iter);
    
    iter = ajListIterNew(resource->Edamtpc);
    while((resterm = ajListIterGet(iter)))
        ajFmtPrintF(outf, "%-8s%S | %S\n", "EDAMtpc",
                    resterm->Id, resterm->Name);
    ajListIterDel(&iter);
    
    iter = ajListIterNew(resource->Edamdat);
    while((resterm = ajListIterGet(iter)))
        ajFmtPrintF(outf, "%-8s%S | %S\n", "EDAMdat",
                    resterm->Id, resterm->Name);
    ajListIterDel(&iter);

    iter = ajListIterNew(resource->Edamid);
    while((resterm = ajListIterGet(iter)))
        ajFmtPrintF(outf, "%-8s%S | %S\n", "EDAMid",
                    resterm->Id, resterm->Name);
    ajListIterDel(&iter);
    
    iter = ajListIterNew(resource->Edamfmt);
    while((resterm = ajListIterGet(iter)))
        ajFmtPrintF(outf, "%-8s%S | %S\n", "EDAMfmt",
                    resterm->Id, resterm->Name);
    ajListIterDel(&iter);

    iter = ajListIterNew(resource->Xref);
    while((tmplink = ajListIterGet(iter)))
        ajFmtPrintF(outf, "%-8s%S | %S\n",
                    "Xref", tmplink->Source,
                    tmplink->Term);
    ajListIterDel(&iter);
    
    iter = ajListIterNew(resource->Query);
    while((tmpqry = ajListIterGet(iter)))
        ajFmtPrintF(outf, "%-8s %S | %S | %S | %S\n",
                    "Query", tmpqry->Datatype, tmpqry->Format,
                    tmpqry->Term, tmpqry->Url);
    ajListIterDel(&iter);

    iter = ajListIterNew(resource->Example);
    while((tmpstr = ajListstrIterGet(iter)))
        ajFmtPrintF(outf, "%-8s%S\n", "Example", tmpstr);
    ajListIterDel(&iter);
    
    ajFmtPrintF(outf, "\n");

    return ajTrue;
}