Пример #1
0
static AjPTable emira_makepreftab(void)
{
    AjPTable ret = NULL;
    ajuint i;
    AjPStr key = NULL;
    AjPStr value = NULL;
    
    ret = ajTablestrNewLen(MIRATAB_GUESS);

    i = 0;
    while(miraprefix[i].qname)
    {
	key   = ajStrNewC(miraprefix[i].qname);
	value = ajStrNewC(miraprefix[i].prefix);

	ajTablePut(ret, (void *)key, (void *)value);
	++i;
    }

    return ret;
}
Пример #2
0
int main(int argc, char **argv)
{

    AjPStr directory = NULL;
    AjPTable mtable = NULL;

    AjPList jdirlist = NULL;
    AjPStr  jdirloc  = NULL;
    
    embInit("jaspextract",argc,argv);

    directory = ajAcdGetDirectoryName("directory");

    mtable = ajTablestrNewLen(PFMNUMGUESS);
    jdirlist = ajListNew();
    
    jaspextract_openoutdirs();
    jaspextract_copyfiles(directory);

    jaspextract_readmatrixlist(mtable, directory);
    
    jaspextract_getjaspdirs(jdirlist);

    while(ajListPop(jdirlist,(void **)&jdirloc))
    {
        jaspextract_writematrixfile(mtable, jdirloc);
        ajStrDel(&jdirloc);
    }
    
    ajTablestrFree(&mtable);
    ajStrDel(&directory);
    ajListFree(&jdirlist);
    
    embExit();

    return 0;
}
Пример #3
0
static AjPTable jaspscan_ReadFamList(const AjPStr jaspdir)
{
    AjPTable ret = NULL;
    AjPStr lfile = NULL;
    AjPStr line  = NULL;
    AjPStr key   = NULL;
    AjPStr str   = NULL;
 
    PJspmat info = NULL;
    
    AjPFile inf  = NULL;
    const char *p = NULL;
    const char *q = NULL;
    
    lfile = ajStrNew();
    line  = ajStrNew();
    str   = ajStrNew();
    
    ajFmtPrintS(&lfile,"%S%s%s",jaspdir,SLASH_STRING,J_LIST);


    inf = ajDatafileNewInNameS(lfile);
    if(!inf)
	ajFatal("Matrix list file %S not found",lfile);


    ret = ajTablestrNewLen(JASPTAB_GUESS);
    
    
    while(ajReadlineTrim(inf,&line))
    {
	info = jaspscan_infonew();
	ajFmtScanS(line,"%S%S",&info->id,&info->num);

	p = ajStrGetPtr(line);
	while(*p !='\t')
	    ++p;
	++p;
	while(*p != '\t')
	    ++p;
	++p;

	q = p;
	while(*q != '\t')
	    ++q;

	ajStrAssignSubC(&info->name,p,0,q-p-1);

	++q;
	p = q;
	while(*q != ';')
	    ++q;

	ajStrAssignSubC(&info->klass,p,0,q-p-1);
	ajStrRemoveWhiteExcess(&info->klass);

	p = q+1;
	while(*p)
	{
	    q = p;
	    while(* q && *q != ';')
		++q;
	    ajStrAssignSubC(&str,p,0,q-p-1);
	    ajStrRemoveWhiteExcess(&str);

	    jaspscan_coretoken(info, str);
	    
	    if(!*q)
		p = q;
	    else
		p = q +1;
	}

	key = ajStrNew();
	ajStrAssignS(&key,info->id);
	ajTablePut(ret,(void *)key,(void *) info);
    }
    

    ajFileClose(&inf);

    ajStrDel(&lfile);
    ajStrDel(&line);
    ajStrDel(&str);
	

    return ret;
}
Пример #4
0
EnsPCache ensCacheNew(AjEnum type,
                      ajuint maxbytes,
                      ajuint maxcount,
                      ajuint maxsize,
                      void* Freference(void* value),
                      void Fdelete(void** value),
                      ajuint Fsize(const void* value),
                      void* Fread(const void* key),
                      AjBool Fwrite(const void* value),
                      AjBool synchron,
                      const char *label)
{
    AjBool debug = AJFALSE;

    EnsPCache cache = NULL;

    debug = ajDebugTest("ensCacheNew");

    if(debug)
        ajDebug("ensCacheNew\n"
                "  type %d\n"
                "  maxbytes %u\n"
                "  maxcount %u\n"
                "  maxsize %u\n"
                "  Freference %p\n"
                "  Fdelete %p\n"
                "  Fsize %p\n"
                "  Fread %p\n"
                "  Fwrite %p\n"
                "  synchron '%B'\n"
                "  label '%s'\n",
                type,
                maxbytes,
                maxcount,
                maxsize,
                Freference,
                Fdelete,
                Fsize,
                Fread,
                Fwrite,
                synchron,
                label);

    if((type < ensECacheTypeNumeric) || (type > ensECacheTypeAlphaNumeric))
        ajFatal("ensCacheNew requires a valid type.\n");

    if((!maxbytes) && (!maxcount))
        ajFatal("ensCacheNew requires either a "
                "maximum bytes or maximum count limit.\n");

    if(!maxsize)
        maxsize = maxbytes ? maxbytes / 10 + 1 : 0;

    if(maxbytes && (!maxsize))
        ajFatal("ensCacheNew requires a maximum size limit, "
                "when a maximum bytes limit is set.");

    /* TODO: Find and set a sensible value here! */

    if(debug)
        ajDebug("ensCacheNew maxbytes %u, maxcount %u, maxsize %u.\n",
                maxbytes, maxcount, maxsize);

    if(maxbytes && (maxbytes < 1000))
        ajFatal("ensCacheNew cannot set a maximum bytes limit (%u) under "
                "1000, as each Cache Node requires %u bytes alone.",
                maxbytes, sizeof(CachePNode));

    /* TODO: Find and set a sensible value here! */

    if(maxsize && (maxsize < 3))
        ajFatal("ensCacheNew cannot set a maximum size limit (%u) under "
                "3 bytes. maximum bytes %u maximum count %u.",
                maxsize, maxbytes, maxcount);

    /*
    ** Pointers to functions for automatic reading of data not yet in the
    ** cache and writing of data modified in cache are not mandatory.
    ** If not specified the cache will simply lack this functionality.
    ** However, the specification of a function deleting stale cache entries
    ** and a function calculating the size of value data are required.
    */

    if(!(void*)Freference)
        ajFatal("ensCacheNew requires a referencing function.");

    if(!(void*)Fdelete)
        ajFatal("ensCacheNew requires a deletion function.");

    if(maxsize && (!(void*)Fsize))
        ajFatal("ensCacheNew requires a memory sizing function "
                "when a maximum size limit has been defined.");

    if(!label)
        ajFatal("ensCacheNew requires a label.");

    AJNEW0(cache);

    cache->Label = ajStrNewC(label);
    cache->List  = ajListNew();

    switch(type)
    {
        case ensECacheTypeNumeric:

            cache->Table = ajTableNewFunctionLen(0,
                                                 ensTableCmpUint,
                                                 ensTableHashUint);

            break;

        case ensECacheTypeAlphaNumeric:

            cache->Table = ajTablestrNewLen(0);

            break;

        default:
            ajWarn("ensCacheNew got unexpected Cache type %d.\n",
                   cache->Type);
    }

    cache->Reference = Freference;
    cache->Delete    = Fdelete;
    cache->Size      = Fsize;
    cache->Read      = Fread;
    cache->Write     = Fwrite;
    cache->Type      = type;
    cache->Synchron  = synchron;
    cache->MaxBytes  = maxbytes;
    cache->MaxCount  = maxcount;
    cache->MaxSize   = maxsize;
    cache->Bytes     = 0;
    cache->Count     = 0;
    cache->Dropped   = 0;
    cache->Removed   = 0;
    cache->Stored    = 0;
    cache->Hit       = 0;
    cache->Miss      = 0;

    return cache;
}
Пример #5
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;
}