Ejemplo n.º 1
0
static void emira_dointegers(AjPStr *cl, AjPTable table)
{
    ajuint i;
    ajint  iqual;
    int  dval = 0;
    AjPStr prefix = NULL;
    AjPStr key    = NULL;
    AjPStr value  = NULL;
    
    prefix = ajStrNew();
    key    = ajStrNew();
    
    i = 0;

    while(miraintegers[i].qname)
    {
	iqual = ajAcdGetInt(miraintegers[i].qname);
	ajStrAssignC(&key,miraintegers[i].qname);
	ajStrAssignC(&prefix,"");

	value = ajTableFetch(table, key);
	if(value)
	    ajStrAssignS(&prefix,value);

	if(sscanf(miraintegers[i].def,"%d",&dval) != 1)
	    ajFatal("Dval conversion error in emira_dointegers()");

	if(iqual != dval)
	    ajFmtPrintAppS(cl," -%S%s=%d",prefix,miraintegers[i].mname,iqual);

	++i;
    }

    ajStrDel(&key);
    ajStrDel(&prefix);
    
    return;
}
Ejemplo n.º 2
0
AjBool ensCacheRemove(EnsPCache cache, const void* key)
{
    CachePNode node = NULL;

    if(!cache)
        return ajFalse;

    if(!key)
        return ajFalse;

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

    if(node)
    {
        cacheNodeRemove(cache, node);

        /* Both, key and value data are deleted via cacheNodeDel. */

        cacheNodeDel(cache, &node);
    }

    return ajTrue;
}
Ejemplo n.º 3
0
void ajCallTableRegister(AjPTable table, const char *name, void *func)
{
    void *rec;
    char* keyname = NULL;
 
    if(!table)
      ajFatal("ajCallTableRegister called for undefined table with name '%s'",
	      name);

    rec = ajTableFetch(table, name);	/* does it exist already */

    if(!rec)
    {
	keyname = ajCharNewC(name);
	ajTablePut(table, keyname, (void *) func);
    }
    else
    {
        ajWarn("ajCallTableRegister duplicate name '%s'", name);
    }

    return;
}
Ejemplo n.º 4
0
static void jaspscan_ReportHits(AjPFeattable TabRpt, const AjPTable mattab,
				AjPList hits)
{
    PJsphits hit = NULL;
    PJspmat info = NULL;
    AjPFeature feat = NULL;
    AjPStr str = NULL;
    float fnum = 0.;
    
    str = ajStrNew();

    while(ajListPop(hits,(void **)&hit))
    {
	if(hit->start <= hit->end)
	    feat = ajFeatNewII(TabRpt,hit->start,hit->end);
	else
	    feat = ajFeatNewIIRev(TabRpt,hit->start,hit->end);

	ajFmtPrintS(&str,"*pc %.3f",hit->scorepc);
	ajFeatTagAdd(feat, NULL, str);

	ajFmtPrintS(&str,"*id %S",hit->matname);
	ajFeatTagAdd(feat, NULL, str);

	info = ajTableFetch(mattab,hit->matname);
	if(!info)
	    ajWarn("No info for matrix %S",hit->matname);
	
	if(ajStrGetLen(info->name))
	{
	    ajFmtPrintS(&str,"*name %S",info->name);
	    ajFeatTagAdd(feat, NULL, str);
	}

	if(ajStrGetLen(info->species))
	{
	    ajFmtPrintS(&str,"*species %S",info->species);
	    ajFeatTagAdd(feat, NULL, str);
	}

	if(ajStrGetLen(info->klass))
	{
	    ajFmtPrintS(&str,"*class %S",info->klass);
	    ajFeatTagAdd(feat, NULL, str);
	}

	if(ajStrGetLen(info->sgroup))
	{
	    ajFmtPrintS(&str,"*supergroup %S",info->sgroup);
	    ajFeatTagAdd(feat, NULL, str);
	}

	if(ajStrGetLen(info->protseq))
	{
	    ajFmtPrintS(&str,"*pseq %S",info->protseq);
	    ajFeatTagAdd(feat, NULL, str);
	}

	if(ajStrGetLen(info->exp))
	{
	    ajFmtPrintS(&str,"*exp %S",info->exp);
	    ajFeatTagAdd(feat, NULL, str);
	}

	if(ajStrGetLen(info->pmid))
	{
	    ajFmtPrintS(&str,"*pmid %S",info->pmid);
	    ajFeatTagAdd(feat, NULL, str);
	}

	if(ajStrGetLen(info->num))
	{
	    ajStrToFloat(info->num,&fnum);
	    ajFmtPrintS(&str,"*info %.3f",fnum);
	    ajFeatTagAdd(feat, NULL, str);
	}
	
	if(ajStrGetLen(info->jaspar))
	{
	    ajFmtPrintS(&str,"*jaspar %S",info->jaspar);
	    ajFeatTagAdd(feat, NULL, str);
	}

	if(ajStrGetLen(info->transfac))
	{
	    ajFmtPrintS(&str,"*transfac %S",info->transfac);
	    ajFeatTagAdd(feat, NULL, str);
	}

	if(ajStrGetLen(info->mcs))
	{
	    ajStrToFloat(info->mcs,&fnum);
	    ajFmtPrintS(&str,"*mcs %.3f",fnum);
	    ajFeatTagAdd(feat, NULL, str);
	}

	if(ajStrGetLen(info->models))
	{
	    ajFmtPrintS(&str,"*built %S",info->models);
	    ajFeatTagAdd(feat, NULL, str);
	}

	
	jaspscan_hitsdel(&hit);
    }

    ajStrDel(&str);
    
    return;
}
Ejemplo n.º 5
0
AjBool ajDebugTest(const char* token)
{
    AjPStr filename = NULL;
    const char* debugtestname = ".debugtest";
    char* ctoken = NULL;
    AjPStr line = NULL;
    AjPStr strtoken = NULL;
    AjPStr rest = NULL;
    static ajint depth    = 0;

    struct 
    {
        ajuint count;
        ajuint max;
    } *stats;
    
    if(depth)
        return ajFalse;

    depth++;

    if(!messDebugTestInit)
    {
        filename = ajStrNewC(debugtestname);

        if(ajFilenameExists(filename))
        {
            messDebugTestFile = ajFileNewInNameS(filename);
        }
        else
        {
            ajFmtPrintS(&filename, "%s%s%s",
                        getenv("HOME"), SLASH_STRING, debugtestname); 
            if(ajFilenameExists(filename))
                messDebugTestFile = ajFileNewInNameS(filename);
        }
        ajStrDel(&filename);

        if(messDebugTestFile) 
        {
            messDebugTestTable = ajTablecharNewLen(256);

            while(ajReadlineTrim(messDebugTestFile, &line))
            {
                if(ajStrExtractFirst(line, &rest, &strtoken))
                {
                    AJNEW0(stats);
                    ctoken = ajCharNewS(strtoken);
                    if(ajStrIsInt(rest))
                        ajStrToUint(rest, &stats->max);
                    else
                        stats->max = UINT_MAX;
                    ajTablePut(messDebugTestTable, ctoken, stats);
                    ctoken = NULL;
                    stats = NULL;
                }
            }

            ajStrDel(&line);
            ajStrDel(&strtoken);
            ajStrDel(&rest);
            ajFileClose(&messDebugTestFile);
        }
        messDebugTestInit = ajTrue;
     }

    depth--;
    
    if(!messDebugTestTable)
        return ajFalse;

    depth++;
    stats = ajTableFetch(messDebugTestTable, token);
    depth--;
    

    if(!stats)
        return ajFalse;

    if(!stats->max)
        return ajTrue;

    if(stats->count++ >= stats->max)
        return ajFalse;

    return ajTrue;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
    const char *codons[]=
    {
	"TAG","TAA","TGA","GCG","GCA","GCT","GCC","TGT", /* 00-07 */
	"TGC","GAT","GAC","GAA","GAG","TTT","TTC","GGT", /* 08-15 */
	"GGG","GGA","GGC","CAT","CAC","ATA","ATT","ATC", /* 16-23 */
	"AAA","AAG","CTA","TTA","TTG","CTT","CTC","CTG", /* 24-31 */
	"ATG","AAT","AAC","CCG","CCA","CCT","CCC","CAA", /* 32-39 */
	"CAG","CGT","CGA","CGC","AGG","AGA","CGG","TCG", /* 40-47 */
	"TCA","AGT","TCT","TCC","AGC","ACG","ACT","ACA", /* 48-55 */
	"ACC","GTA","GTT","GTC","GTG","TGG","TAT","TAC"	 /* 56-63 */
    };

    const char *aa=
	"***AAAACCDDEEFFGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVWYY";

    AjPFile inf     = NULL;
    AjPFile outf    = NULL;
    char *entryname = NULL;
    AjPStr fname    = NULL;
    AjPStr key      = NULL;
    AjPStr tmpkey   = NULL;
    AjBool allrecords = AJFALSE;

    AjPTable table  = NULL;
    ajint i = 0;
    ajint j = 0;
    ajint k = 0;
    ajint x = 0;
    ajint savecount[3];

    AjPStr *keyarray = NULL;
    CutgPValues *valarray = NULL;
    AjPCod codon  = NULL;
    ajint sum = 0;
    char c;

    AjPList flist = NULL;
    AjPFile logf = NULL;
    AjPStr  entry = NULL;
    AjPStr  baseentry = NULL;
    AjPStr  wild  = NULL;
    AjPStr division = NULL;
    AjPStr release = NULL;
    AjPStr wildspecies = NULL;
    CutgPValues value = NULL;
    AjPStr docstr = NULL;
    AjPStr species = NULL;
    AjPStr filename = NULL;
    ajint nstops;

    embInit("cutgextract",argc,argv);

    tmpkey = ajStrNew();
    fname  = ajStrNew();


    table = ajTablestrNewLen(TABLE_ESTIMATE);


    flist = ajAcdGetDirlist("directory");
    wild  = ajAcdGetString("wildspec");
    release  = ajAcdGetString("release");
    logf = ajAcdGetOutfile("outfile");
    wildspecies = ajAcdGetString("species");
    filename = ajAcdGetString("filename");
    allrecords = ajAcdGetBoolean("allrecords");

    ajStrInsertC(&release, 0, "CUTG");
    ajStrRemoveWhite(&release);

    while(ajListPop(flist,(void **)&entry))
    {
	ajStrAssignS(&baseentry, entry);
	ajFilenameTrimPath(&baseentry);
	ajDebug("Testing file '%S'\n", entry);
	if(!ajStrMatchWildS(baseentry,wild))
	{
	    ajStrDel(&entry);
	    continue;
	}

	ajDebug("... matched wildcard '%S'\n", wild);
	inf = ajFileNewInNameS(entry);
	if(!inf)
	    ajFatal("cannot open file %S",entry);

	ajFmtPrintS(&division, "%F", inf);
	ajFilenameTrimAll(&division);

	while((entryname = cutgextract_next(inf, wildspecies,
					    &species, &docstr)))
	{
	    if(ajStrGetLen(filename))
		ajStrAssignS(&tmpkey,filename);
	    else
		ajStrAssignC(&tmpkey,entryname);

	    /* See if organism is already in the table */
	    value = ajTableFetch(table,tmpkey);
	    if(!value)			/* Initialise */
	    {
		key = ajStrNewS(tmpkey);
		AJNEW0(value);
		ajStrAssignS(&value->Species,species);
		ajStrAssignS(&value->Division, division);
		ajTablePut(table,(void *)key,(void *)value);
	    }
	    for(k=0;k<3;k++)
		savecount[k] = value->Count[k];
	    nstops = cutgextract_readcodons(inf,allrecords, value->Count);
	    if(nstops < 1)
	    {
		value->Skip++;
		continue;
	    }
	    value->CdsCount++;
	    if(nstops>1)
	    {
		value->CdsCount += (nstops - 1);
		value->Warn++;
		ajWarn("Found %d stop codons (%d %d %d) for CDS '%S'",
		       nstops,
		       value->Count[0] - savecount[0],
		       value->Count[1] - savecount[1],
		       value->Count[2] - savecount[2],
		       cutgextractSavepid);
	    }
	}
	ajStrDel(&entry);
	ajFileClose(&inf);
    }

    ajTableToarrayKeysValues(table,(void***) &keyarray, (void***) &valarray);

    i = 0;
    while(keyarray[i])
    {
	key   = keyarray[i];
	value = (CutgPValues) valarray[i++];
	codon = ajCodNew();
	sum   = 0;
	for(j=0;j<CODONS;++j)
	{
	    sum += value->Count[j];
	    x = ajCodIndexC(codons[j]);
	    codon->num[x] = value->Count[j];

	    c = aa[j];
	    if(c=='*')
		codon->aa[x] = 27;
	    else
		codon->aa[x] = c-'A';
	}
	ajCodCalcUsage(codon,sum);

	ajStrAppendC(&key, ".cut");
	if(allrecords)
	{
	    if(value->Warn)
		ajFmtPrintF(logf, "Writing %S CDS: %d Warnings: %d\n",
			    key, value->CdsCount, value->Warn);
	    else
		ajFmtPrintF(logf, "Writing %S CDS: %d\n",
			    key, value->CdsCount);
	}
	else
	{
	    if(value->Skip)
		ajFmtPrintF(logf, "Writing %S CDS: %d Skipped: %d\n",
			    key, value->CdsCount, value->Skip);
	    else
		ajFmtPrintF(logf, "Writing %S CDS: %d\n",
			    key, value->CdsCount);
	}

	ajFmtPrintS(&fname,"CODONS/%S",key);
	outf = ajDatafileNewOutNameS(fname);
	if(!outf)
	    ajFatal("Cannot open output file %S",fname);

	ajCodSetNameS(codon, key);
	ajCodSetSpeciesS(codon, value->Species);
	ajCodSetDivisionS(codon, value->Division);
	ajCodSetReleaseS(codon, release);
	ajCodSetNumcds(codon, value->CdsCount);
	ajCodSetNumcodons(codon, sum);

	ajCodWrite(codon, outf);
	ajFileClose(&outf);


	ajStrDel(&key);
	ajStrDel(&value->Division);
	ajStrDel(&value->Doc);
	ajStrDel(&value->Species);
	AJFREE(value);
	ajCodDel(&codon);
    }

    AJFREE(keyarray);
    AJFREE(valarray);

    ajTableFree(&table);
    ajListFree(&flist);
    ajStrDel(&wild);
    ajStrDel(&release);
    ajStrDel(&wildspecies);
    ajStrDel(&filename);
    ajFileClose(&logf);

    ajStrDel(&cutgextractSavepid);
    ajStrDel(&cutgextractLine);
    ajStrDel(&cutgextractOrg);

    ajStrDel(&fname);
    ajStrDel(&tmpkey);
    ajStrDel(&species);
    ajStrDel(&docstr);
    ajStrDel(&division);
    ajStrDel(&baseentry);

    embExit();

    return 0;
}
Ejemplo n.º 8
0
static AjBool assemblyexceptionadaptorCacheInit(
    EnsPAssemblyexceptionadaptor aea)
{
    ajuint *Pidentifier = NULL;

    AjPList list = NULL;
    AjPList aes  = NULL;

    AjPStr statement = NULL;

    EnsPAssemblyexception ae = NULL;

    if(!aea)
        return ajFalse;

    if(aea->CacheBySeqregionIdentifier)
        return ajTrue;
    else
        aea->CacheBySeqregionIdentifier =
            ajTableNewFunctionLen(0, ensTableCmpUint, ensTableHashUint);

    statement = ajFmtStr(
        "SELECT "
        "assembly_exception.assembly_exception_id, "
        "assembly_exception.seq_region_id, "
        "assembly_exception.seq_region_start, "
        "assembly_exception.seq_region_end, "
        "assembly_exception.exc_type, "
        "assembly_exception.exc_seq_region_id, "
        "assembly_exception.exc_seq_region_start, "
        "assembly_exception.exc_seq_region_end, "
        "assembly_exception.ori "
        "FROM "
        "assembly_exception, "
        "seq_region, "
        "coord_system "
        "WHERE "
        "seq_region.seq_region_id = "
        "assembly_exception.seq_region_id "
        "AND "
        "seq_region.coord_system_id = "
        "coord_system.coord_system_id "
        "AND "
        "coord_system.species_id = %u",
        ensDatabaseadaptorGetIdentifier(aea->Adaptor));

    aes = ajListNew();

    assemblyexceptionadaptorFetchAllBySQL(aea, statement, aes);

    ajStrDel(&statement);

    while(ajListPop(aes, (void **) &ae))
    {
        list = (AjPList) ajTableFetch(aea->CacheBySeqregionIdentifier,
                                      (const void *)
                                      &ae->SeqregionIdentifier);

        if(!list)
        {
            AJNEW0(Pidentifier);

            *Pidentifier = ae->SeqregionIdentifier;

            list = ajListNew();

            ajTablePut(aea->CacheBySeqregionIdentifier,
                       (void *) Pidentifier,
                       (void *) list);
        }

        ajListPushAppend(list, (void *) ae);
    }

    ajListFree(&aes);

    return ajTrue;
}