Exemple #1
0
static void silent_split_hits(AjPList *hits, AjPList *silents,
			      AjPList *nonsilents, AjBool allmut)
{
    PSilent res;

    while(ajListPop(*hits,(void **)&res))
    {
	if(res->issilent)
	{
           	ajListPushAppend(*silents,(void *)res);
	   	continue;
	}
	if(allmut)
           	ajListPushAppend(*nonsilents,(void *)res);
	else
	{
	    ajStrDel(&res->code);
	    ajStrDel(&res->site);
	    ajStrDel(&res->seqaa);
	    ajStrDel(&res->reaa);
	    AJFREE(res);
	}
    }

    return;
}
static void prima_prune_nearby(AjPList pairlist, ajint *npair, ajint range)
{
    PPair pair;

    ajint count;
    ajint fst;
    ajint fst2;
    ajint blim;
    ajint blim2;
    ajint elim;
    ajint elim2;
    ajint i;
    ajint j;
    ajint len;

    for(i=0;i<*npair;++i)
    {
	for(j=0;j<i;++j)	/* Ignore those already processed */
	{
	    ajListPop(pairlist,(void **)&pair);
	    ajListPushAppend(pairlist,(void *)pair);
	}

	ajListPop(pairlist,(void **)&pair);/* Get next high scoring pair */
	len  = pair->f->primerlen;
	fst  = pair->f->start + len -1;
	blim = fst-range;
	elim = fst+range;

	len   = pair->r->primerlen;
	blim2 = pair->r->start - range;
	elim2 = pair->r->start + range;

	ajListPushAppend(pairlist,(void *)pair);
	count = *npair;
	for(j=i+1;j<*npair;++j)
	{
	    ajListPop(pairlist,(void **)&pair);
	    fst2=pair->f->start+pair->f->primerlen-1;
	    if((fst2<blim || fst2>elim) && (pair->r->start<blim2 ||
					    pair->r->start>elim2))
		ajListPushAppend(pairlist,(void *)pair);
	    else
	    {
		prima_PrimerDel(&pair->f);
		prima_PrimerDel(&pair->r);
		AJFREE(pair);
		--count;
	    }
	}

	*npair = count;
    }

    return;
}
Exemple #3
0
static void jaspscan_GetFileList(const AjPStr dir, const AjPStr jaspdir,
				 const char *wild, AjPList list)
{
    AjPList tlist = NULL;
    AjPStr jdir = NULL;
    AjPStr wstr = NULL;
    AjPStr str  = NULL;
    
    tlist = ajListNew();
    jdir  = ajStrNew();
    wstr  = ajStrNew();
    

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

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

    ajFilelistAddPathWild(tlist,jdir,wstr);

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

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

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

    ajListFree(&tlist);

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


    n = ajFilelistAddPathDir(jdirlist, datadir);

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

    return;
}
Exemple #5
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;
}
static void prima_TwoSortscorepos(AjPList *pairlist)
{
    PPair tmp = NULL;
    AjPList intlist = NULL;
    AjPList filist  = NULL;
    PPair save  = NULL;
    float   score = 0.0;


    ajListSort(*pairlist,prima_Compare);
    intlist = ajListNew();
    filist  = ajListNew();

    score = (float) -1.0;

    while(ajListPop(*pairlist,(void **)&tmp))
    {
	if(tmp->f->score == score)
	{
	    ajListPush(intlist,(void *)tmp);
	    continue;
	}

	save = tmp;
	ajListSort(intlist,prima_PosCompare);
	score = tmp->f->score;
	prima_RevSort(&intlist);

	while(ajListPop(intlist,(void **)&tmp))
	    ajListPushAppend(filist,(void *)tmp);
	ajListPush(intlist,(void *)save);
    }

    ajListSort(intlist,prima_PosCompare);
    prima_RevSort(&intlist);

    while(ajListPop(intlist,(void **)&tmp))
	ajListPushAppend(filist,(void *)tmp);

    ajListFree(&intlist);
    ajListFree(pairlist);

    *pairlist = filist;
    return;
}
Exemple #7
0
void ajPatlistAddSeq (AjPPatlistSeq thys, AjPPatternSeq pat)
{
    ajDebug ("ajPatlistAddSeq list size %d '%S' '%S' '%B' '%d'\n",
             ajListGetLength (thys->Patlist), pat->Name,
             pat->Pattern, pat->Protein, pat->Mismatch);
    ajListPushAppend(thys->Patlist, pat);

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

    return;
}
Exemple #9
0
static void supermatcher_matchListOrder(void **x,void *cl)
{
    EmbPWordMatch p;
    AjPList ordered;
    ajint offset;
    AjIList listIter;
    concat *con;
    concat *c=NULL;

    p = (EmbPWordMatch)*x;
    ordered = (AjPList) cl;

    offset = (*p).seq1start-(*p).seq2start;

    /* iterate through ordered list to find if it exists already*/
    listIter = ajListIterNewread(ordered);

    while(!ajListIterDone( listIter))
    {
	con = ajListIterGet(listIter);
	if(con->offset == offset)
	{
	    /* found so add count and set offset to the new value */
	    con->offset = offset;
	    con->total+= (*p).length;
	    con->count++;
	    ajListPushAppend(con->list,p);
	    ajListIterDel(&listIter);
	    return;
	}
    }
    ajListIterDel(&listIter);

    /* not found so add it */
    AJNEW(c);
    c->offset = offset;
    c->total  = (*p).length;
    c->count  = 1;
    c->list   = ajListNew();
    ajListPushAppend(c->list,p);
    ajListPushAppend(ordered, c);

    return;
}
static void prima_check_overlap(AjPList pairlist, ajint *npair, ajint overlap)
{
    PPair pair;

    ajint i;
    ajint j;
    ajint end;
    ajint limit;
    ajint count;

    for(i=0;i<*npair;++i)
    {
	for(j=0;j<i;++j)
	{
	    ajListPop(pairlist,(void **)&pair);
	    ajListPushAppend(pairlist,(void *)pair);
	}

	ajListPop(pairlist,(void **)&pair);

	end   = pair->r->start;
	limit = end-overlap;
	ajListPushAppend(pairlist,(void *)pair);

	count = *npair;
	for(j=i+1;j<*npair;++j)
	{
	    ajListPop(pairlist,(void **)&pair);
	    if(pair->f->start+pair->f->primerlen-1 < limit)
	    {
		prima_PrimerDel(&pair->f);
		prima_PrimerDel(&pair->r);
		AJFREE(pair);
		--count;
	    }
	    else
		ajListPushAppend(pairlist,(void *)pair);
	}

	*npair = count;
    }

    return;
}
Exemple #11
0
static void acdrelations_readtypefile
            (AjPFile inf, 
	     PKtype *T)
{
    AjPStr     line    = NULL;
    PKtypedat  dattmp  = NULL;
    AjPList    datlist = NULL;
    
    if(!T)
        ajFatal("Null arg error 1 in acdrelations_readtypefile");
    if(!inf)
        ajFatal("Null arg error 3 in acdrelations_readtypefile");


    /* Allocate memory */
    line           = ajStrNew();
    datlist        = ajListNew();

    
    /* Read data from file */
    while(ajReadline(inf,&line))
    {
        /* Discard comment lines */
        if(ajStrPrefixC(line,"#")) 
            continue;

        /* Create object for holding line */
        dattmp = ajKtypedatNew();
        
        /* Tokenise line delimited by '|'
           Parse first token (value of knowntype: attribute) */
        ajStrAssignS(&dattmp->ktype, ajStrParseC(line, "|"));
        ajStrRemoveSetC(&dattmp->ktype, "_");
        ajStrRemoveWhite(&dattmp->ktype);
        
        /* Parse second token (ACD datatype) */
        ajStrAssignS(&dattmp->acdtype, ajStrParseC(NULL, "|"));

        /* Parse third token (EDAM relations: value ) */
        ajStrAssignS(&dattmp->edam, ajStrParseC(NULL, "|"));

        /* Push line onto list */
        ajListPushAppend(datlist, dattmp);
    }
    

    /* Write PKtype structure */
    ((*T)->n) = ajListToarray(datlist, (void***) &((*T)->dat));
  
    
    /* Free memory */
    ajStrDel(&line);
    ajListFree(&datlist);

    return;
}
static void prima_RevSort(AjPList *alist)
{
    PPair tmp = NULL;
    AjPList intlist = NULL;
    AjPList filist  = NULL;
    PPair save = NULL;
    ajint pos = -1;


    intlist = ajListNew();
    filist  = ajListNew();

    pos = -1;

    while(ajListPop(*alist,(void **)&tmp))
    {
	if(tmp->f->start+tmp->f->primerlen == pos)
	{
	    ajListPush(intlist,(void *)tmp);
	    continue;
	}

	save = tmp;
	ajListSort(intlist,prima_PosEndCompare);
	pos = tmp->f->start+tmp->f->primerlen;
	while(ajListPop(intlist,(void **)&tmp))
	    ajListPushAppend(filist,(void *)tmp);
	ajListPush(intlist,(void *)save);
    }

    ajListSort(intlist,prima_PosEndCompare);
    while(ajListPop(intlist,(void **)&tmp))
	ajListPushAppend(filist,(void *)tmp);

    ajListFree(&intlist);
    ajListFree(alist);

    *alist = filist;

    return;
}
Exemple #13
0
/* @funcstatic skipredundant_SeqsetToList **************************************
**
** Builds a list of sequences from a sequence set.
** The sequences are NOT copied (only a reference is pushed onto the list)
**
** @param [u] list   [AjPList] List 
** @param [w] seqset [AjPSeqset] Sequence set
** @return [AjBool] True on success
******************************************************************************/
static AjBool skipredundant_SeqsetToList (AjPList list, AjPSeqset seqset)
{
    ajint     n      = 0;
    ajint     x      = 0;
    EmbPDmxNrseq seq_tmp = NULL;    /* Temp. pointer for making seq_list.    */
  
    if(!list || !seqset)
      return ajFalse;
    
    n = ajSeqsetGetSize(seqset);
    for(x=0; x<n; x++)
    {
        seq_tmp = embDmxNrseqNew(ajSeqsetGetseqSeq(seqset, x));
	ajListPushAppend(list, seq_tmp);
        seq_tmp = NULL;
    }

    return ajTrue;
}
Exemple #14
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;
}
Exemple #15
0
AjBool ajResquerylistClone(const AjPList src, AjPList dest)
{
    AjIList iter;
    AjPResquery qryout = NULL;
    AjPResquery qryin = NULL;

    if(ajListGetLength(dest))
	return ajFalse;

    iter = ajListIterNewread(src);

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

    ajListIterDel(&iter);

    return ajTrue;
}
Exemple #16
0
AjBool ajRestermlistClone(const AjPList src, AjPList dest)
{
    AjIList iter;
    AjPResterm termout = NULL;
    AjPResterm termin = NULL;

    if(ajListGetLength(dest))
	return ajFalse;

    iter = ajListIterNewread(src);

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

    ajListIterDel(&iter);

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

    ajuint rlen = 0;
    

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

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

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

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

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

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

	AJFREE(carr);
    }
    
    


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

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

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

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


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

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

    return;
}
Exemple #18
0
AjPMatrix ajMatrixNewFile(const AjPStr filename)
{
    AjPMatrix ret = NULL;
    AjPStr buffer = NULL;
    const AjPStr tok    = NULL;

    AjPStr firststring  = NULL;
    AjPStr *orderstring = NULL;

    AjPFile file    = NULL;
    AjBool first    = ajTrue;
    const char *ptr = NULL;
    ajint **matrix  = NULL;

    ajint minval = -1;
    ajint i      = 0;
    ajint l      = 0;
    ajint k      = 0;
    ajint cols   = 0;
    ajint rows   = 0;

    ajint *templine = NULL;

    AjPList rlabel_list = NULL;
    AjPStr  *rlabel_arr  = NULL;

#ifndef WIN32
    static const char *delimstr = " :\t\n";
#else
    static const char *delimstr = " :\t\n\r";
#endif

    rlabel_list = ajListNew();
    

    firststring = ajStrNew();
    
    file = ajDatafileNewInNameS(filename);
    
    if(!file)
    {
	ajStrDel(&firststring);
	ajListFree(&rlabel_list);

	return NULL;
    }
    
    /* Read row labels */
    while(ajReadline(file,&buffer))
    {
	ptr = ajStrGetPtr(buffer);
#ifndef WIN32
	if(*ptr != '#' && *ptr != '\n')
#else
	if(*ptr != '#' && *ptr != '\n' && *ptr != '\r')
#endif
	{
	    if(first)
		first = ajFalse;
	    else
	    {	
		ajFmtScanC(ptr, "%S", &firststring);
		ajListPushAppend(rlabel_list, firststring);
		firststring = ajStrNew();	
	    }
	}
    }

    first = ajTrue;
    ajStrDel(&firststring);
    rows = ajListToarray(rlabel_list, (void ***) &rlabel_arr);
    ajFileSeek(file, 0, 0);


    while(ajReadline(file,&buffer))
    {
	ajStrRemoveWhiteExcess(&buffer);
	ptr = ajStrGetPtr(buffer);

	if(*ptr && *ptr != '#')
	{				
	    if(first)
	    {
		cols = ajStrParseCountC(buffer,delimstr);
		AJCNEW0(orderstring, cols);

		for(i=0; i<cols; i++)   
		    orderstring[i] = ajStrNew();
		
		tok = ajStrParseC(buffer, " :\t\n");
		ajStrAssignS(&orderstring[l++], tok);

		while((tok = ajStrParseC(NULL, " :\t\n")))
		    ajStrAssignS(&orderstring[l++], tok);

		first = ajFalse;

		ret = ajMatrixNewAsym(orderstring, cols, 
						rlabel_arr, rows, 
						filename);
		matrix = ret->Matrix;
	    }
	    else
	    {
		ajFmtScanC(ptr, "%S", &firststring);
		
		/* JISON 19/7/4
		   k = ajSeqcvtGetCodeK(ret->Cvt, ajStrGetCharFirst(firststring)); */
		k = ajSeqcvtGetCodeS(ret->Cvt, firststring);

		/* 
		 ** cols+1 is used below because 2nd and subsequent lines have 
		 ** one more string in them (the residue label) 
		 */
		templine = ajArrIntLine(buffer,delimstr,2,cols+1);
		
		for(i=0; i<cols; i++)   
		{
		    if(templine[i] < minval) 
			minval = templine[i];

		    /* JISON 19/7/4
		    matrix[k][ajSeqcvtGetCodeK(ret->Cvt,
					ajStrGetCharFirst(orderstring[i]))] 
					    = templine[i]; */
		    matrix[k][ajSeqcvtGetCodeAsymS(ret->Cvt,
					       orderstring[i])] 
						   = templine[i];
		}

		AJFREE(templine);
	    }
	}
    }

    ajDebug("fill rest with minimum value %d\n", minval);
    

    ajFileClose(&file);
    ajStrDel(&buffer);

    for(i=0; i<cols; i++)   
	ajStrDel(&orderstring[i]);

    AJFREE(orderstring);
        
    
    ajDebug("read matrix file %S\n", filename);
    
    ajStrDel(&firststring);    

    for(i=0; i<rows; i++)   
	ajStrDel(&rlabel_arr[i]);

    AJFREE(rlabel_arr);
    ajListFree(&rlabel_list);

    return ret;
}
Exemple #19
0
int main(int argc, char **argv)
{
    AjPSeqall seqall;
    AjPSeq seq   = NULL;
    AjPReport report = NULL;

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

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

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

    embInit("jaspscan", argc, argv);

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

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


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


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


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

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

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

	TabRpt = ajFeattableNewSeq(seq);


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

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

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

	jaspscan_ReportHits(TabRpt,mattab,hits);

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


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

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

    ajSeqDel(&seq);

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

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

    return 0;
}
Exemple #20
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;
}
Exemple #21
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;
}
Exemple #22
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;    
}
Exemple #23
0
int main(int argc, char **argv)
{
    /* Variable declarations */
    AjPOutfile outfile = NULL;    
    AjPOboall oboall = NULL;
    AjBool subclasses = ajFalse;
    AjBool obsolete = ajFalse;

    AjPObo obo     = NULL;
    AjPObo obotest = NULL;

    AjPList obolist = ajListNew();

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

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

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

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

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

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

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

    /* Memory clean-up and exit */

    ajListFree(&obolist);

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

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

    return 0;
}
Exemple #24
0
AjPMatrixf ajMatrixfNewFile(const AjPStr filename)
{
    AjPMatrixf ret = NULL;
    AjPStr *orderstring = NULL;
    AjPStr buffer       = NULL;
    AjPStr firststring  = NULL;
    AjPStr reststring   = NULL;
    const AjPStr tok    = NULL;

    ajint len  = 0;
    ajint i    = 0;
    ajint l    = 0;
    ajint k    = 0;
    ajint cols = 0;
    ajint rows   = 0;
    
    const char *ptr = NULL;

    AjPFile file    = NULL;
    AjBool  first   = ajTrue;

    float **matrix  = NULL;
    float *templine = NULL;
    float minval    = -1.0;

    AjPList rlabel_list = NULL;
    AjPStr  *rlabel_arr  = NULL;
#ifndef WIN32
    static const char *delimstr = " :\t\n";
#else
    static const char *delimstr = " :\t\n\r";
#endif



    rlabel_list = ajListNew();
    

    
    firststring = ajStrNew();
    reststring  = ajStrNew();

    file = ajDatafileNewInNameS(filename);
    
    if(!file)
    {
	ajStrDel(&firststring);
	ajStrDel(&reststring);

	return NULL;
    }
    

    /* Read row labels */
    while(ajReadline(file,&buffer))
    {
	ptr = ajStrGetPtr(buffer);
#ifndef WIN32
	if(*ptr != '#' && *ptr != '\n')
#else
	if(*ptr != '#' && *ptr != '\n' && *ptr != '\r')
#endif
	{	
	    if(first)
		first = ajFalse;
	    else
	    {
		ajFmtScanC(ptr, "%S", &firststring);
		ajListPushAppend(rlabel_list, firststring);
		firststring = ajStrNew();
	    }
	}
    }
    first = ajTrue;
    ajStrDel(&firststring);
    rows = ajListToarray(rlabel_list, (void ***) &rlabel_arr);
    ajFileSeek(file, 0, 0);


    while(ajReadline(file,&buffer))
    {
	ajStrRemoveWhiteExcess(&buffer);
	ptr = ajStrGetPtr(buffer);

	if(*ptr && *ptr != '#')
	{				
	    if(first)
	    {
		cols = ajStrParseCountC(buffer,delimstr);
		AJCNEW0(orderstring, cols);

		for(i=0; i<cols; i++)   
		    orderstring[i] = ajStrNew();

		tok = ajStrParseC(buffer, " :\t\n");
		ajStrAssignS(&orderstring[l++], tok);

		while((tok = ajStrParseC(NULL, " :\t\n")))
		    ajStrAssignS(&orderstring[l++], tok);

		first = ajFalse;

		ret = ajMatrixfNewAsym(orderstring, cols, 
						 rlabel_arr, rows, 
						 filename);
		matrix = ret->Matrixf;
	    }
	    else
	    {
		ajFmtScanC(ptr, "%S", &firststring);
		/* JISON 19/7/4 
		   k = ajSeqcvtGetCodeK(ret->Cvt,
                   ajStrGetCharFirst(firststring)); */
		k = ajSeqcvtGetCodeS(ret->Cvt, firststring); 

		len = MAJSTRGETLEN(firststring);
		ajStrAssignSubC(&reststring, ptr, len, -1);

		/* 
		** Must discard the first string (label) and use 
		** reststring otherwise ajArrFloatLine would fail (it 
		** cannot convert a string to a float)
		**   
		** Use cols,1,cols in below because although 2nd and 
		** subsequent lines have one more string in them (the
		** residue label in the 1st column) we've discarded that
		** from the string that's passed
		*/
		templine = ajArrFloatLine(reststring,delimstr,1,cols);
		
		for(i=0; i<cols; i++)  
		{
		    if(templine[i] < minval) 
			minval = templine[i];

		    /* JISON 19/7/4
		    matrix[k][ajSeqcvtGetCodeK(ret->Cvt,
					ajStrGetCharFirst(orderstring[i]))] 
					    = templine[i]; */

		    matrix[k][ajSeqcvtGetCodeAsymS(ret->Cvt,
					       orderstring[i])] 
						   = templine[i];
		}
		AJFREE(templine);
	    }
	}
    }
    ajDebug("fill rest with minimum value %d\n", minval);
    

    ajFileClose(&file);
    ajStrDel(&buffer);

    for(i=0; i<cols; i++)   
	ajStrDel(&orderstring[i]);

    AJFREE(orderstring);


    ajDebug("read matrix file %S\n", filename);
    
    ajStrDel(&firststring);
    ajStrDel(&reststring);

   for(i=0; i<rows; i++)   
	ajStrDel(&rlabel_arr[i]);

   AJFREE(rlabel_arr);
   ajListFree(&rlabel_list);

   return ret;
}
Exemple #25
0
static AjBool cacheNodeInsert(EnsPCache cache, CachePNode node)
{
    CachePNode old = NULL;

    if(!cache)
        return ajFalse;

    if(!node)
        return ajFalse;

    if(cache->MaxSize && (node->Bytes > cache->MaxSize))
        return ajFalse;

    /* Insert the node into the AJAX List. */

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

    /* Insert the node into the AJAX Table. */

    ajTablePut(cache->Table, node->Key, (void *) node);

    /* Update the cache statistics. */

    cache->Bytes += node->Bytes;

    cache->Count++;

    cache->Stored++;

    /* If the cache is too big, remove the top node(s). */

    while((cache->MaxBytes && (cache->Bytes > cache->MaxBytes)) ||
          (cache->MaxCount && (cache->Count > cache->MaxCount)))
    {
        /* Remove the top node from the AJAX List. */

        ajListPop(cache->List, (void **) &old);

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

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

        /* Update the cache statistics. */

        cache->Bytes -= old->Bytes;

        cache->Count--;

        cache->Dropped++;

        /* Write changes of value data to disk if any. */

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

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

        cacheNodeDel(cache, &old);
    }

    return ajTrue;
}
Exemple #26
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;
}
static AjBool dbiblast_parseNcbi(const AjPStr line, AjPFile * alistfile,
				 AjBool systemsort, AjPStr const * fields,
				 ajint* maxFieldLen,
				 ajuint* countfield,
				 AjPStr* myid,
				 AjPList* fdlist)
{
    char* fd;

    static ajint numFields;
    static ajint accfield = -1;
    static ajint desfield = -1;
    static ajint svnfield = -1;
    static AjBool reset = AJTRUE;

    if(!fields)
    {
	reset = ajTrue;
	accfield = svnfield = desfield = -1;
	return ajFalse;
    }

    if(reset)
    {
	numFields = 0;
	while(fields[numFields])
	{
	    if(ajStrMatchCaseC(fields[numFields], "acc"))
		accfield=numFields;
	    else if(ajStrMatchCaseC(fields[numFields], "sv"))
		svnfield=numFields;
	    else if(ajStrMatchCaseC(fields[numFields], "des"))
		desfield=numFields;
	    else
		ajWarn("EMBL parsing unknown field '%S' ignored",
		       fields[numFields]);
	    numFields++;
	}
	reset = ajFalse;
    }

    if(!wrdexp)
	wrdexp = ajRegCompC("([A-Za-z0-9]+)");

    ajStrAssignC(&tmpdes,"");
    ajStrAssignC(&t,"");
    ajStrAssignC(&tmpac,"");
    ajStrAssignC(&tmpsv,"");
    ajStrAssignC(&tmpgi,"");
    ajStrAssignC(&tmpdb,"");

    ajFmtPrintS(&t,">%S",line);

    if(!ajSeqParseNcbi(t,myid,&tmpac,&tmpsv,&tmpgi,&tmpdb,&tmpdes))
	return ajFalse;

    if(ajStrGetLen(tmpac))
	ajStrFmtUpper(&tmpac);

    if(accfield >= 0)
	embDbiMaxlen(&tmpac, &maxFieldLen[accfield]);

    if(svnfield >= 0)
    {
	embDbiMaxlen(&tmpsv, &maxFieldLen[svnfield]);
	embDbiMaxlen(&tmpgi, &maxFieldLen[svnfield]);
    }


    ajStrFmtUpper(myid);

    /* ajDebug("parseNCBI success\n"); */

    if(systemsort)
    {
	if(accfield >= 0 && ajStrGetLen(tmpac))
	{
	    countfield[accfield]++;
	    ajFmtPrintF(alistfile[accfield], "%S %S\n", *myid, tmpac);
	}
	if(svnfield >= 0 && ajStrGetLen(tmpsv))
	{
	    countfield[svnfield]++;
	    ajFmtPrintF(alistfile[svnfield], "%S %S\n", *myid, tmpsv);
	}
	if(svnfield >= 0 && ajStrGetLen(tmpgi))
	{
	    countfield[svnfield]++;
	    ajFmtPrintF(alistfile[svnfield], "%S %S\n", *myid, tmpgi);
	}
	if(desfield >= 0 && ajStrGetLen(tmpdes))
	    while(ajRegExec(wrdexp, tmpdes))
	    {
		ajRegSubI(wrdexp, 1, &tmpfd);
		embDbiMaxlen(&tmpfd, &maxFieldLen[desfield]);
		ajStrFmtUpper(&tmpfd);
		ajDebug("++des '%S'\n", tmpfd);
		countfield[desfield]++;
		ajFmtPrintF(alistfile[desfield], "%S %S\n", *myid, tmpfd);
		ajRegPost(wrdexp, &tmpdes);
	    }
    }
    else
    {
        if(accfield >= 0 && ajStrGetLen(tmpac))
	{
	    fd = ajCharNewS(tmpac);
	    countfield[accfield]++;
	    ajListPushAppend(fdlist[accfield], fd);
	}

        if(svnfield >= 0 && ajStrGetLen(tmpsv))
	{
	    fd = ajCharNewS(tmpsv);
	    countfield[svnfield]++;
	    ajListPushAppend(fdlist[svnfield], fd);
	}

        if(svnfield >= 0 && ajStrGetLen(tmpgi))
	{
	    fd = ajCharNewS(tmpgi);
	    ajListPushAppend(fdlist[svnfield], fd);
	}

        if(desfield >= 0 && ajStrGetLen(tmpdes))
	{
	    while(ajRegExec(wrdexp, tmpdes))
	    {
		ajRegSubI(wrdexp, 1, &tmpfd);
		embDbiMaxlen(&tmpfd, &maxFieldLen[desfield]);
		ajStrFmtUpper(&tmpfd);
		ajDebug("++des '%S'\n", tmpfd);
		fd = ajCharNewS(tmpfd);
		countfield[desfield]++;
		ajListPushAppend(fdlist[desfield], fd);
		ajRegPost(wrdexp, &tmpdes);
	    }
	}
    }

    /* ajDebug("parseNCBI '%S' '%S'\n", *myid, tmpac); */

    return ajTrue;
}
Exemple #28
0
static void jaspscan_scan(const AjPStr seq, const ajuint begin,
			  const AjPStr mfname, const char type,
			  const float threshold,
			  const AjBool both, AjPList hits)
{
    PJsphits val = NULL;
    AjPStr mname   = NULL;
    float **matrix = NULL;
    ajuint cols;

    ajuint i;
    ajuint rc;
    ajuint cc;
    ajuint limit;
    
    ajuint slen;
    const char *p;

    char schar;
    float sum  = 0.;
    float rmax = 0.;

    float scorepc  = 0.;
    float maxscore = 0.;

    
    cols = jaspscan_readmatrix(mfname, &matrix);

    maxscore = 0.;
    for(cc = 0; cc < cols; ++cc)
    {
	rmax = 0.;
	for(rc = 0; rc < 4; ++rc)
	    rmax = (rmax > matrix[rc][cc]) ? rmax : matrix[rc][cc];
	maxscore += rmax;
    }
    

 
    slen = ajStrGetLen(seq);

    limit = (slen - cols) + 1;
    if(limit <= 0)
	return;

    mname = ajStrNew();

    ajStrAssignS(&mname,mfname);
    ajFilenameTrimPath(&mname);
    ajFilenameTrimExt(&mname);

    p = ajStrGetPtr(seq);

    for(i=0; i < limit; ++i)
    {
	sum = 0.;
	schar = p[i];
	for(cc = 0; cc < cols; ++cc)
	{
	    schar = p[i+cc];
	    if(schar == 'A')
		sum += matrix[0][cc];
	    else if(schar == 'C')
		sum += matrix[1][cc];
	    else if(schar == 'G')
		sum += matrix[2][cc];
	    else if(schar == 'T')
		sum += matrix[3][cc];
	}


	scorepc = (sum * (float)100.) / maxscore;


	if(scorepc >= threshold)
	{
	    val = jaspscan_hitsnew();
	    val->type = type;
	    ajStrAssignS(&val->matname,mname);
	    val->start = i + begin;
	    val->end = val->start + cols - 1;
	    val->score = sum;
	    val->threshold = threshold;
	    val->scorepc  = scorepc;
	    val->maxscore = maxscore;

	    ajListPushAppend(hits,(void *)val);
	}
    }
    

    if(both)
    {
	jaspscan_CompMat(matrix, cols);

	p = ajStrGetPtr(seq);

	for(i=0; i < limit; ++i)
	{
	    sum = 0.;
	    schar = p[i];
	    for(cc = 0; cc < cols; ++cc)
	    {
		schar = p[i+cc];
		if(schar == 'A')
		    sum += matrix[0][cc];
		else if(schar == 'C')
		    sum += matrix[1][cc];
		else if(schar == 'G')
		    sum += matrix[2][cc];
		else if(schar == 'T')
		    sum += matrix[3][cc];
	    }


	    scorepc = (sum * (float)100.) / maxscore;


	    if(scorepc >= threshold)
	    {
		val = jaspscan_hitsnew();
		val->type = type;
		ajStrAssignS(&val->matname,mname);
		val->end = i + begin;
		val->start = val->end + cols - 1;
		val->score = sum;
		val->threshold = threshold;
		val->scorepc  = scorepc;
		val->maxscore = maxscore;

		ajListPushAppend(hits,(void *)val);
	    }
	}
    }
    

    for(i = 0; i < 4; ++i)
	AJFREE(matrix[i]);
    AJFREE(matrix);


    ajStrDel(&mname);

    return;
}
Exemple #29
0
int main(int argc, char **argv)
{
    /* Variable declarations */
    AjPOutfile outfile = NULL;    
    AjPTaxall taxall = NULL;

    AjPTax tax     = NULL;
    AjPTax taxtest     = NULL;

    AjPList taxlist = ajListNew();

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

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

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

    foundtable = ajTablestrNew(600);

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

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

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

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

    /* Memory clean-up and exit */

    ajListFree(&taxlist);

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

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

    return 0;
}
static AjBool dbiblast_parseSimple(const AjPStr line,
				   AjPFile * alistfile,
				   AjBool systemsort, AjPStr const * fields,
				   ajint* maxFieldLen,
				   ajuint* countfield,
				   AjPStr* myid,
				   AjPList* myfdl)
{
    static AjPRegexp idexp = NULL;
    static AjPStr mytmpac    = NULL;
    char* ac;
    static ajint numFields;
    static ajint accfield = -1;
    static AjBool reset = AJTRUE;

    if(!fields)
    {
	reset = ajTrue;
	accfield = -1;
	return ajFalse;
    }

    if(reset)
    {
	numFields = 0;
	while(fields[numFields])
	{
	    if(ajStrMatchCaseC(fields[numFields], "acc"))
		accfield=numFields;
	    else if(!ajStrMatchCaseC(fields[numFields], "sv") &&
		    !ajStrMatchCaseC(fields[numFields], "des"))
		ajWarn("Simple ID parsing unknown field '%S' ignored",
		       fields[numFields]);
	    numFields++;
	}
	reset = ajFalse;
    }


    if(!idexp)
	idexp = ajRegCompC("^([^ ]+)( +([A-Za-z][A-Za-z0-9]+[0-9]))");

    if(!ajRegExec(idexp, line))
	return ajFalse;

    ajRegSubI(idexp, 1, myid);
    ajRegSubI(idexp, 3, &mytmpac);
    ajStrFmtUpper(myid);
    ajStrFmtUpper(&mytmpac); /* GCG mixes case on new SwissProt acnums */

    if(accfield >= 0)
    {
        embDbiMaxlen(&mytmpac, &maxFieldLen[accfield]);
	countfield[accfield]++;
	if(systemsort)
	    ajFmtPrintF(alistfile[accfield], "%S %S\n", *myid, mytmpac);
	else
	{
	    ac = ajCharNewS(mytmpac);
	    ajListPushAppend(myfdl[accfield], ac);
	}
    }

    ajDebug("parseSimple '%S' '%S'\n", *myid, mytmpac);

    return ajTrue;
}