Exemplo n.º 1
0
static void tfscan_print_hits(AjPList *l,
			      ajint hits, AjPReport outf,
			      const AjPTable t,
			      const AjPSeq seq, ajuint minlength,
			      const  AjPTable btable)
{
    ajint i;
    EmbPMatMatch m;
    const AjPStr acc = NULL;
    const AjPStr bf  = NULL;
    AjPFeattable ftable = NULL;
    AjPFeature gf  = NULL;
    AjPStr type = ajStrNewC("SO:0000235");
    AjPStr tmpstr = NULL;

    ftable = ajFeattableNewSeq(seq);

    /*ajFmtPrintF(outf,"TFSCAN of %s from %d to %d\n\n",ajStrGetPtr(name),
      begin,end);*/

    for(i=0;i<hits;++i)
    {
	ajListPop(*l,(void **)&m);
	acc = ajTableFetchS(t, m->seqname);

	if(m->len >= minlength)
        {
	    /*ajFmtPrintF(outf,"%-20s %-8s %-5d %-5d %s\n",
                        ajStrGetPtr(m->seqname),
			ajStrGetPtr(acc),m->start,
			m->start+m->len-1,ajStrGetPtr(s));*/
            if(m->forward)
                gf = ajFeatNew(ftable, ajUtilGetProgram(), type,
                               m->start,
                               m->start+m->len-1,
                               (float) m->score,
                               '+',0);
            else
                gf = ajFeatNew(ftable, ajUtilGetProgram(), type,
                               m->start,
                               m->start+m->len-1,
                               (float) m->score,
                               '-',0);
            ajFmtPrintS(&tmpstr, "*acc %S", acc);
            ajFeatTagAddSS(gf, NULL, tmpstr);
            bf  = ajTableFetchS(btable, m->seqname);
            ajFmtPrintS(&tmpstr, "*factor %S", bf);
            ajFeatTagAddSS(gf, NULL, tmpstr);
        }

	embMatMatchDel(&m);
    }

    ajReportWrite(outf, ftable, seq);
    ajFeattableDel(&ftable);
    ajStrDel(&tmpstr);
    ajStrDel(&type);

    return;
}
Exemplo n.º 2
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.º 3
0
static void primersearch_clean_hitlist(AjPList* hlist)
{
    AjIList lIter;

    lIter = ajListIterNewread(*hlist);
    while(!ajListIterDone(lIter))
    {
	EmbPMatMatch fm = ajListIterGet(lIter);
	embMatMatchDel(&fm);
    }
    ajListFree(hlist);
    ajListFree(hlist);
    ajListIterDel(&lIter);

    return;
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
    ajint begin, end;
    AjPSeqall seqall;
    AjPSeq seq;
    EmbPShow ss;
    AjPFile outfile;
    AjPStr tablename;
    ajint table;
    AjPRange uppercase;
    AjPRange highlight;
    AjBool threeletter;
    AjBool numberseq;
    AjBool nameseq;
    ajint width;
    ajint length;
    ajint margin;
    AjBool description;
    ajint offset;
    AjBool html;
    AjPStr descriptionline;
    ajint orfminsize;
    AjPTrn trnTable;
    AjBool translation;
    AjBool reverse;
    AjBool cutlist;
    AjBool flat;
    EmbPMatMatch mm = NULL;

    AjPStr *framelist;
    AjBool frames[6];   /* frames to be translated 1 to 3, -1 to -3 */
	 
    /* stuff for tables and lists of enzymes and hits */
    ajint default_mincuts = 1;
    ajint default_maxcuts = 2000000000;
    AjPTable hittable; /* enzyme hits */

    /* stuff lifted from Alan's 'restrict.c' */
    AjPStr enzymes = NULL;
    ajint mincuts;
    ajint maxcuts;
    ajint sitelen;
    AjBool single;
    AjBool blunt;
    AjBool sticky;
    AjBool ambiguity;
    AjBool plasmid;
    AjBool commercial;
    AjBool limit;
    AjBool methyl;
    AjPFile enzfile  = NULL;
    AjPFile equfile  = NULL;
    AjPFile methfile = NULL;
    AjPTable retable = NULL;
    ajint hits;
    AjPList restrictlist = NULL;

    embInit("remap", argc, argv);

    seqall      = ajAcdGetSeqall("sequence");
    outfile     = ajAcdGetOutfile("outfile");
    tablename   = ajAcdGetListSingle("table");
    uppercase   = ajAcdGetRange("uppercase");
    highlight   = ajAcdGetRange("highlight");
    threeletter = ajAcdGetBoolean("threeletter");
    numberseq   = ajAcdGetBoolean("number");
    width       = ajAcdGetInt("width");
    length      = ajAcdGetInt("length");
    margin      = ajAcdGetInt("margin");
    nameseq     = ajAcdGetBoolean("name");
    description = ajAcdGetBoolean("description");
    offset      = ajAcdGetInt("offset");
    html        = ajAcdGetBoolean("html");
    orfminsize  = ajAcdGetInt("orfminsize");
    translation = ajAcdGetBoolean("translation");
    reverse     = ajAcdGetBoolean("reverse");
    cutlist     = ajAcdGetBoolean("cutlist");
    flat        = ajAcdGetBoolean("flatreformat");
    framelist   = ajAcdGetList("frame");
    
    /*  restriction enzyme stuff */
    mincuts    = ajAcdGetInt("mincuts");
    maxcuts    = ajAcdGetInt("maxcuts");
    sitelen    = ajAcdGetInt("sitelen");
    single     = ajAcdGetBoolean("single");
    blunt      = ajAcdGetBoolean("blunt");
    sticky     = ajAcdGetBoolean("sticky");
    ambiguity  = ajAcdGetBoolean("ambiguity");
    plasmid    = ajAcdGetBoolean("plasmid");
    commercial = ajAcdGetBoolean("commercial");
    limit      = ajAcdGetBoolean("limit");
    enzymes    = ajAcdGetString("enzymes");
    methfile   = ajAcdGetDatafile("mfile");
    methyl     = ajAcdGetBoolean("methylation");
    
    if(!blunt  && !sticky)
	ajFatal("Blunt/Sticky end cutters shouldn't both be disabled.");

    /* get the number of the genetic code used */
    ajStrToInt(tablename, &table);
    trnTable = ajTrnNewI(table);

    /* read the local file of enzymes names */
    remap_read_file_of_enzyme_names(&enzymes);

    /* get the frames to be translated */
    remap_GetFrames(framelist, frames);
	 
    while(ajSeqallNext(seqall, &seq))
    {
	/* get begin and end positions */
	begin = ajSeqGetBegin(seq)-1;
	end   = ajSeqGetEnd(seq)-1;

	/* do the name and description */
	if(nameseq)
	{
	    if(html)
		ajFmtPrintF(outfile, "<H2>%S</H2>\n",
				   ajSeqGetNameS(seq));
	    else
		ajFmtPrintF(outfile, "%S\n", ajSeqGetNameS(seq));
	}

	if(description)
	{
	    /*
	    **  wrap the description line at the width of the sequence
	    **  plus margin
	    */
	    if(html)
		ajFmtPrintF(outfile, "<H3>%S</H3>\n",
				   ajSeqGetDescS(seq));
	    else
	    {
		descriptionline = ajStrNew();
		ajStrAssignS(&descriptionline, ajSeqGetDescS(seq));
		ajStrFmtWrap(&descriptionline, width+margin);
		ajFmtPrintF(outfile, "%S\n", descriptionline);
		ajStrDel(&descriptionline);
	    }
	}

	/* get the restriction cut sites */
	/*
	**  most of this is lifted from the program 'restrict.c' by Alan
	**  Bleasby
	 */
	if(single)
	    maxcuts=mincuts=1;
	retable = ajTablestrNew(EQUGUESS);
	enzfile = ajDatafileNewInNameC(ENZDATA);
	if(!enzfile)
	    ajFatal("Cannot locate enzyme file. Run REBASEEXTRACT");

	if(limit)
	{
	    equfile = ajDatafileNewInNameC(EQUDATA);
	    if(!equfile)
		limit = ajFalse;
	    else
		remap_read_equiv(&equfile, &retable, commercial);
	}

	ajFileSeek(enzfile, 0L, 0);
	restrictlist = ajListNew();
	/* search for hits, but don't use mincuts and maxcuts criteria yet */
	hits = embPatRestrictMatch(seq, begin+1, end+1, enzfile, methfile,
                                   enzymes, sitelen,plasmid, ambiguity,
                                   default_mincuts, default_maxcuts, blunt,
                                   sticky, commercial, methyl,
				   restrictlist);

	ajDebug("Remap found %d hits\n", hits);

	if(hits)
	{
	    /* this bit is lifted from printHits */
	    embPatRestrictRestrict(restrictlist, hits, !limit,
					  ajFalse);
	    if(limit)
		remap_RestrictPreferred(restrictlist,retable);
	}


	ajFileClose(&enzfile);
	ajFileClose(&methfile);


	/*
	** Remove those violating the mincuts and maxcuts
	** criteria, but save them in hittable for printing out later.
	** Keep a count of how many hits each enzyme gets in hittable.
	*/
        hittable = ajTablestrNewCase(TABLEGUESS);
	remap_RemoveMinMax(restrictlist, hittable, mincuts, maxcuts);


	/* make the Show Object */
	ss = embShowNew(seq, begin, end, width, length, margin, html, offset);

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

	/* create the format to display */
	embShowAddBlank(ss);
	embShowAddRE(ss, 1, restrictlist, plasmid, flat);
	embShowAddSeq(ss, numberseq, threeletter, uppercase, highlight);

	if(!numberseq)
	    embShowAddTicknum(ss);
	embShowAddTicks(ss);

	if(reverse)
	{
	    embShowAddComp(ss, numberseq);
	    embShowAddRE(ss, -1, restrictlist, plasmid, flat);
	}


	if(translation)
	{
	    if(reverse)
		embShowAddBlank(ss);

            if(frames[0])	    
	      embShowAddTran(ss, trnTable, 1, threeletter,
			     numberseq, NULL, orfminsize,
			     AJFALSE, AJFALSE, AJFALSE, AJFALSE);
            if(frames[1])
	      embShowAddTran(ss, trnTable, 2, threeletter,
			     numberseq, NULL, orfminsize,
			     AJFALSE, AJFALSE, AJFALSE, AJFALSE);
            if(frames[2])
	      embShowAddTran(ss, trnTable, 3, threeletter,
			     numberseq, NULL, orfminsize,
			     AJFALSE, AJFALSE, AJFALSE, AJFALSE);
	    
	    if(reverse)
	    {
		embShowAddTicks(ss);
                if(frames[5])
		  embShowAddTran(ss, trnTable, -3, threeletter,
			         numberseq, NULL, orfminsize,
			         AJFALSE, AJFALSE, AJFALSE, AJFALSE);
                if(frames[4])
		  embShowAddTran(ss, trnTable, -2, threeletter,
			         numberseq, NULL, orfminsize,
			         AJFALSE, AJFALSE, AJFALSE, AJFALSE);
                if(frames[3])
		  embShowAddTran(ss, trnTable, -1, threeletter,
			         numberseq, NULL, orfminsize,
			         AJFALSE, AJFALSE, AJFALSE, AJFALSE);
	    }
	}

	embShowPrint(outfile, ss);

	/* display a list of the Enzymes that cut and don't cut */
	if(cutlist)
	{
	    remap_CutList(outfile, hittable,
	    		limit, html, mincuts, maxcuts);
	    remap_NoCutList(outfile, hittable, html, enzymes, blunt,
			sticky, sitelen, commercial, ambiguity, 
			limit, retable);
	}

	/* add a gratuitous newline at the end of the sequence */
	ajFmtPrintF(outfile, "\n");

	/* tidy up */
	embShowDel(&ss);

	while(ajListPop(restrictlist,(void **)&mm))
	    embMatMatchDel(&mm);
	ajListFree(&restrictlist);

        remap_DelTable(&hittable);

	ajTablestrFree(&retable);
    }


    ajTrnDel(&trnTable);

    ajSeqallDel(&seqall);
    ajSeqDel(&seq);
    ajFileClose(&outfile);
    ajStrDel(&tablename);
    ajStrDel(&enzymes);
    ajStrDelarray(&framelist);

    ajRangeDel(&uppercase);
    ajRangeDel(&highlight);

    embExit();

    return 0;
}
Exemplo n.º 5
0
void embPatternSeqSearch (AjPFeattable ftable, const AjPSeq seq,
			  const AjPPatternSeq pat, AjBool reverse)
{
    const void *tidy;
    ajuint hits;
    ajuint i;
    AjPPatComp pattern;
    EmbPMatMatch m = NULL;
    AjPFeature sf  = NULL;
    AjPSeq revseq  = NULL;
    AjPList list   = ajListNew();
    AjPStr seqstr  = ajStrNew();
    AjPStr seqname = ajStrNew();
    AjPStr tmp     = ajStrNew();
    ajint adj;
    ajint begin;
    AjBool isreversed;
    ajint seqlen;

    seqlen = ajSeqGetLen(seq);
    if(!seqlen)
        return;

    isreversed = ajSeqIsReversedTrue(seq);

    if(isreversed)
	seqlen += ajSeqGetOffset(seq);

    begin = ajSeqGetBeginTrue(seq);
    adj = ajSeqGetEndTrue(seq);

    if(!ajStrGetLen(featMotifProt))
        ajStrAssignC(&featMotifProt, "SO:0001067");

    if(!ajStrGetLen(featMotifNuc))
        ajStrAssignC(&featMotifNuc, "SO:0000714");

    ajStrAssignS(&seqname,ajSeqGetNameS(seq));
    pattern = ajPatternSeqGetCompiled(pat);

    if (reverse)
    {
        revseq = ajSeqNewSeq(seq);
        ajStrAssignSubS(&seqstr, ajSeqGetSeqS(revseq),
			begin-1,adj-1);
        ajSeqstrReverse(&seqstr);
    }
    else
        ajStrAssignSubS(&seqstr, ajSeqGetSeqS(seq),
			begin-1,adj-1);

    ajStrFmtUpper(&seqstr);
    /*ajDebug("seqlen:%d len: %d offset: %d offend: %d begin: %d end: %d\n"
	   "'%S'\n",
	   seqlen , ajSeqGetLen(seq), ajSeqGetOffset(seq),
	   ajSeqGetOffend(seq), ajSeqGetBegin(seq), ajSeqGetEnd(seq),
	   seqstr);*/

    ajDebug("embPatternSeqSearch '%S' protein: %B reverse: %B\n",
	    pattern->pattern, pat->Protein, reverse);
    embPatFuzzSearchII(pattern,begin,seqname,seqstr,list,
                       ajPatternSeqGetMismatch(pat),&hits,&tidy);

    ajDebug ("embPatternSeqSearch: found %d hits\n",hits);

    if(!reverse)
	ajListReverse(list);

    for(i=0;i<hits;++i)
    {
        ajListPop(list,(void **)&m);

 	if (reverse)
	    sf = ajFeatNew(ftable, NULL, featMotifNuc,
                           adj - m->start - m->len + begin + 1,
                           adj - m->start + begin,
                           0.0, '-', 0);
	else
        {
	    if(ajSeqIsProt(seq) || ajFeattableIsProt(ftable))
                sf = ajFeatNewProt(ftable, NULL, featMotifProt,
                                   m->start,
                                   m->start + m->len - 1,
                                   0.0);
            else
                sf = ajFeatNew(ftable, NULL, featMotifNuc,
                               m->start,
                               m->start + m->len - 1,
                               0.0, '.', 0);
        }
        
	if(isreversed)
	    ajFeatReverse(sf, seqlen);

	/*
	ajUser("isrev: %B reverse: %B begin: %d adj: %d "
	       "start: %d len: %d seqlen: %d %d..%d '%c'\n",
	       isreversed, reverse, begin, adj, m->start, m->len, seqlen,
	       sf->Start, sf->End, sf->Strand);
	*/

	ajFeatSetScore(sf, (float) (m->len - m->mm));

        ajFmtPrintS(&tmp, "*pat %S: %S",
                    ajPatternSeqGetName(pat),
                    ajPatternSeqGetPattern(pat));
        ajFeatTagAdd(sf,NULL,tmp);

        if(m->mm)
        {
            ajFmtPrintS(&tmp, "*mismatch %d", m->mm);
            ajFeatTagAdd(sf, NULL, tmp);
        }

        embMatMatchDel(&m);
    }

    ajStrDel(&seqname);
    ajStrDel(&seqstr);
    ajStrDel(&tmp);
    ajListFree(&list);

    if (reverse)
        ajSeqDel(&revseq);

    return;
}
Exemplo n.º 6
0
static AjPList silent_mismatch(const AjPStr sstr, AjPList relist,
			       AjPStr* tailstr,
			       const AjPStr sname, ajint RStotal, ajint begin,
			       ajint radj,AjBool rev, ajint end,
			       AjBool tshow)
{
    PSilent res;
    AjPList results;
    AjPStr str;                          /*holds RS patterns*/
    AjPStr tstr;
    AjBool dummy = ajFalse;              /*need a bool for ajPatClassify*/
    ajint mm;                            /*number of mismatches*/
    ajint hits;                          /*number of pattern matches found*/
    ajint i;
    ajint aw;
    ajint start;
    AjPList patlist = NULL;            /*a list for pattern matches.
                                             a list of ..*/
    EmbPMatMatch match;                /*..AjMatMatch structures*/
    PRinfo rlp = NULL;
    AjPStr pep   = NULL;               /*string to hold protein*/
    AjPTrn table = NULL;               /*object to hold translation table*/

    str   = ajStrNew();
    tstr  = ajStrNew();
    pep   = ajStrNew();
    table = ajTrnNewI(0);                /*0 stands for standard DNA-
                                         see fuzztran.acd*/
    results = ajListNew();
    start = 1;
    if(!rev)                           /* forward strand */
    {
	ajTrnSeqFrameS(table,sstr,1,&pep); /*1 stands for frame number*/
    	if(tshow)
    	{
                silent_fmt_sequence("TRANSLATED SEQUENCE",
				    pep,tailstr,start,ajFalse);
     	}
    }
    else                               /* reverse strand */
    {
	ajStrAssignC(&tstr,ajStrGetPtr(sstr)+(end-begin+1)%3);
	ajTrnSeqFrameS(table,tstr,1,&pep);
        if(tshow)
	{
		silent_fmt_sequence("REVERSE TRANSLATED SEQUENCE",
				    pep,tailstr,start,ajFalse);
	}
    }

    for(aw=0;aw<RStotal;aw++)          /* loop to read in restriction
					  enzyme patterns */
    {
	/* Pop off the first RE */
	ajListPop(relist,(void **)&rlp);
        /* ignore unknown cut sites and zero cutters */
       	if(*ajStrGetPtr(rlp->site)=='?'||!rlp->ncuts)
        {
	    ajListPushAppend(relist,(void*)rlp);
	    continue;
	}
	ajStrFmtUpper(&rlp->site);   /* convert all RS to upper case */
	ajStrAssignS(&str,rlp->site);      /* str now holds RS patterns */

	patlist = ajListNew();
        if(!embPatClassify(str,&str,
			   &dummy,&dummy,&dummy,&dummy,&dummy,&dummy,0))
	    continue;


	mm = 0;
	hits=embPatBruteForce(sstr,str,ajFalse,ajFalse,patlist,begin+1,mm,
                              sname);

	if(hits)
	    while(ajListPop(patlist,(void**)&match))
		embMatMatchDel(&match);
 	else
        {
	    mm = 1;
	    hits = embPatBruteForce(sstr,str,ajFalse,ajFalse,patlist,
				  begin+1,mm,sname);

	    if(hits)
		for(i=0;i<hits;++i)
		{
		    ajListPop(patlist,(void**)&match);
		    res = silent_checktrans(sstr,match,rlp,begin,radj,
					    rev,end);
		    if (res)
			ajListPushAppend(results,(void *)res);
		    embMatMatchDel(&match);
         	}
   	}

        ajListPushAppend(relist,(void *)rlp);

	ajListFree(&patlist);
    }
    
    ajStrDel(&str);
    ajStrDel(&tstr);
    ajStrDel(&pep);
    ajTrnDel(&table);
    return (results);
}
Exemplo n.º 7
0
static void pscan_print_hits(AjPFile outf, AjPList l, ajuint nmotifs,
			     ajuint begin)
{
    EmbPMatMatch mm;
    ajuint i;
    ajuint j;
    AjBool found;
    ajuint nleft;
    ajuint maxelem = 0;
    ajuint maxhpm;
    ajuint hpm = 0;

    nleft = nmotifs;


    ajFmtPrintF(outf,"\n\nCLASS 1\n");
    ajFmtPrintF(outf,"Fingerprints with all elements in order\n\n");


    found = ajTrue;

    while(found && nleft)
    {
	found = ajFalse;
	maxelem = 0;
	for(i=0;i<nleft;++i)
	{
	    ajListPop(l,(void **)&mm);
	    if(mm->all && mm->ordered)
	    {
		maxelem = AJMAX(maxelem,mm->n);
		found = ajTrue;
	    }
	    hpm = mm->hpm;

	    ajListPushAppend(l,(void *)mm);
	    for(j=1;j<hpm;++j)
	    {
		ajListPop(l,(void **)&mm);
		ajListPushAppend(l,(void *)mm);
	    }
	}


	if(found)
	{
	    found = ajFalse;
	    for(i=0;i<nleft;++i)
	    {
		ajListPop(l,(void **)&mm);
		hpm = mm->hpm;

		if(mm->all && mm->ordered && maxelem==mm->n)
		    break;
		ajListPushAppend(l,(void *)mm);

		for(j=1;j<hpm;++j)
		{
		    ajListPop(l,(void **)&mm);
		    ajListPushAppend(l,(void *)mm);
		}
	    }

	    if(mm->all && mm->ordered && maxelem==mm->n)
	    {
		ajFmtPrintF(outf,"Fingerprint %s Elements %d\n",
			    ajStrGetPtr(mm->cod),mm->n);
		ajFmtPrintF(outf,"    Accession number %s\n",
			    ajStrGetPtr(mm->acc));
		ajFmtPrintF(outf,"    %s\n",ajStrGetPtr(mm->tit));
		ajFmtPrintF(outf,"  Element %d Threshold %d%% Score %d%%\n",
			    mm->element+1, mm->thresh, mm->score);
		ajFmtPrintF(outf,"             Start position %d Length %d\n",
			    mm->start+begin,mm->len);

		embMatMatchDel(&mm);
	    }

	    for(i=1;i<hpm;++i)
	    {
		ajListPop(l,(void **)&mm);
		ajFmtPrintF(outf,"  Element %d Threshold %d%% Score %d%%\n",
			    mm->element+1, mm->thresh, mm->score);
		ajFmtPrintF(outf,"             Start position %d Length %d\n",
			    mm->start+begin,mm->len);

		embMatMatchDel(&mm);
	    }

	    --nleft;
	}

    }

    ajFmtPrintF(outf,"\n\nCLASS 2\n");
    ajFmtPrintF(outf,"All elements match but not all in the "
		"correct order\n\n");

    found = ajTrue;

    while(found && nleft)
    {
	found = ajFalse;
	maxelem = 0;

	for(i=0;i<nleft;++i)
	{
	    ajListPop(l,(void **)&mm);
	    if(mm->all)
	    {
		maxelem = AJMAX(maxelem,mm->n);
		found = ajTrue;
	    }
	    hpm = mm->hpm;
	    ajListPushAppend(l,(void *)mm);

	    for(j=1;j<hpm;++j)
	    {
		ajListPop(l,(void **)&mm);
		ajListPushAppend(l,(void *)mm);
	    }
	}

	if(found)
	{

	    found=ajFalse;
	    for(i=0;i<nleft;++i)
	    {
		ajListPop(l,(void **)&mm);
		hpm = mm->hpm;
		if(mm->all && maxelem==mm->n)
		    break;
		ajListPushAppend(l,(void *)mm);

		for(j=1;j<hpm;++j)
		{
		    ajListPop(l,(void **)&mm);
		    ajListPushAppend(l,(void *)mm);
		}
	    }

	    if(mm->all && maxelem==mm->n)
	    {
		ajFmtPrintF(outf,"Fingerprint %s Elements %d\n",
			    ajStrGetPtr(mm->cod),mm->n);
		ajFmtPrintF(outf,"    Accession number %s\n",
			    ajStrGetPtr(mm->acc));
		ajFmtPrintF(outf,"    %s\n",ajStrGetPtr(mm->tit));
		ajFmtPrintF(outf,"  Element %d Threshold %d%% Score %d%%\n",
			    mm->element+1, mm->thresh, mm->score);
		ajFmtPrintF(outf,"             Start position %d Length %d\n",
			    mm->start+begin,mm->len);

		embMatMatchDel(&mm);
	    }

	    for(i=1;i<hpm;++i)
	    {
		ajListPop(l,(void **)&mm);
		ajFmtPrintF(outf,"  Element %d Threshold %d%% Score %d%%\n",
			    mm->element+1, mm->thresh, mm->score);
		ajFmtPrintF(outf,"             Start position %d Length %d\n",
			    mm->start+begin,mm->len);

		embMatMatchDel(&mm);
	    }

	    --nleft;
	}

    }




    ajFmtPrintF(outf,"\n\nCLASS 3\n");
    ajFmtPrintF(outf,
		"Not all elements match but those that do are in order\n\n");

    found = ajTrue;

    while(found && nleft)
    {
	found  = ajFalse;
	maxhpm = 0;
	for(i=0;i<nleft;++i)
	{
	    ajListPop(l,(void **)&mm);
	    if(mm->ordered)
	    {
		maxhpm = AJMAX(maxelem,mm->hpm);
		found  = ajTrue;
	    }
	    hpm = mm->hpm;
	    ajListPushAppend(l,(void *)mm);

	    for(j=1;j<hpm;++j)
	    {
		ajListPop(l,(void **)&mm);
		ajListPushAppend(l,(void *)mm);
	    }
	}


	if(found)
	{
	    found = ajFalse;
	    for(i=0;i<nleft;++i)
	    {
		ajListPop(l,(void **)&mm);
		hpm = mm->hpm;

		if(mm->ordered && maxhpm==mm->hpm)
		    break;
		ajListPushAppend(l,(void *)mm);

		for(j=1;j<hpm;++j)
		{
		    ajListPop(l,(void **)&mm);
		    ajListPushAppend(l,(void *)mm);
		}
	    }

	    if(mm->ordered && maxhpm==mm->hpm)
	    {
		ajFmtPrintF(outf,"Fingerprint %s Elements %d\n",
			    ajStrGetPtr(mm->cod),mm->n);
		ajFmtPrintF(outf,"    Accession number %s\n",
			    ajStrGetPtr(mm->acc));
		ajFmtPrintF(outf,"    %s\n",ajStrGetPtr(mm->tit));
		ajFmtPrintF(outf,"  Element %d Threshold %d%% Score %d%%\n",
			    mm->element+1, mm->thresh, mm->score);
		ajFmtPrintF(outf,"             Start position %d Length %d\n",
			    mm->start+begin,mm->len);


		embMatMatchDel(&mm);
	    }

	    for(i=1;i<hpm;++i)
	    {
		ajListPop(l,(void **)&mm);
		ajFmtPrintF(outf,"  Element %d Threshold %d%% Score %d%%\n",
			    mm->element+1, mm->thresh, mm->score);
		ajFmtPrintF(outf,"             Start position %d Length %d\n",
			    mm->start+begin,mm->len);

		embMatMatchDel(&mm);
	    }

	    --nleft;
	}

    }




    ajFmtPrintF(outf,"\n\nCLASS 4\n");
    ajFmtPrintF(outf,
		"Remaining partial matches\n\n");

    found = ajTrue;

    while(found && nleft)
    {
	found = ajFalse;
	maxhpm = 0;

	for(i=0;i<nleft;++i)
	{
	    ajListPop(l,(void **)&mm);
	    maxhpm = AJMAX(maxelem,mm->hpm);
	    found = ajTrue;

	    hpm = mm->hpm;
	    ajListPushAppend(l,(void *)mm);
	    for(j=1;j<hpm;++j)
	    {
		ajListPop(l,(void **)&mm);
		ajListPushAppend(l,(void *)mm);
	    }
	}


	if(found)
	{
	    found = ajFalse;
	    for(i=0;i<nleft;++i)
	    {
		ajListPop(l,(void **)&mm);
		hpm = mm->hpm;

		if(maxhpm==mm->hpm)
		    break;
		ajListPushAppend(l,(void *)mm);

		for(j=1;j<hpm;++j)
		{
		    ajListPop(l,(void **)&mm);
		    ajListPushAppend(l,(void *)mm);
		}
	    }

	    if(maxhpm==mm->hpm)
	    {
		ajFmtPrintF(outf,"Fingerprint %s Elements %d\n",
			    ajStrGetPtr(mm->cod),mm->n);
		ajFmtPrintF(outf,"    Accession number %s\n",
			    ajStrGetPtr(mm->acc));
		ajFmtPrintF(outf,"    %s\n",ajStrGetPtr(mm->tit));
		ajFmtPrintF(outf,"  Element %d Threshold %d%% Score %d%%\n",
			    mm->element+1, mm->thresh, mm->score);
		ajFmtPrintF(outf,"             Start position %d Length %d\n",
			    mm->start+begin,mm->len);


		embMatMatchDel(&mm);
	    }

	    for(i=1;i<hpm;++i)
	    {
		ajListPop(l,(void **)&mm);
		ajFmtPrintF(outf,"  Element %d Threshold %d%% Score %d%%\n",
			    mm->element+1, mm->thresh, mm->score);
		ajFmtPrintF(outf,"             Start position %d Length %d\n",
			    mm->start+begin,mm->len);

		embMatMatchDel(&mm);
	    }

	    --nleft;
	}

    }


    while(ajListPop(l,(void **)&mm))
	if(mm)
	    embMatMatchDel(&mm);

    return;
}
Exemplo n.º 8
0
static void restover_printHits(const AjPSeq seq, const AjPStr seqcmp,
			       AjPFile outf,
			       AjPList l, const AjPStr name, ajint hits,
			       ajint begin, ajint end,
			       ajint mincut, ajint maxcut, AjBool plasmid,
			       ajint sitelen,
			       AjBool limit, const AjPTable table,
			       AjBool alpha, AjBool frags,
			       AjBool html)
{
    EmbPMatMatch m = NULL;
    AjPStr ps = NULL;
    ajint *fa = NULL;
    ajint *fx = NULL;
    ajint fc = 0;
    ajint fn = 0;
    ajint fb = 0;
    ajint last = 0;
    AjPStr overhead = NULL;

    const AjPStr value = NULL;

    ajint i;
    ajint c = 0;

    ajint hang1;
    ajint hang2;


    ps = ajStrNew();
    fn = 0;

    if(html)
	ajFmtPrintF(outf,"<BR>");
    ajFmtPrintF(outf,"# Restrict of %S from %d to %d\n",name,begin,end);

    if(html)
	ajFmtPrintF(outf,"<BR>");
    ajFmtPrintF(outf,"#\n");

    if(html)
	ajFmtPrintF(outf,"<BR>");
    ajFmtPrintF(outf,"# Minimum cuts per enzyme: %d\n",mincut);

    if(html)
	ajFmtPrintF(outf,"<BR>");
    ajFmtPrintF(outf,"# Maximum cuts per enzyme: %d\n",maxcut);

    if(html)
	ajFmtPrintF(outf,"<BR>");
    ajFmtPrintF(outf,"# Minimum length of recognition site: %d\n",
		sitelen);
    if(html)
	ajFmtPrintF(outf,"<BR>");

    hits = embPatRestrictRestrict(l,hits,!limit,alpha);

    if(frags)
    {
	fa = AJALLOC(hits*2*sizeof(ajint));
	fx = AJALLOC(hits*2*sizeof(ajint));
    }


    ajFmtPrintF(outf,"# Number of hits with any overlap: %d\n",hits);

    if(html)
	ajFmtPrintF(outf,"<BR>");

    if(html)
	ajFmtPrintF(outf,"</p><table  border cellpadding=4 "
		    "bgcolor=\"#FFFFF0\">\n");
    if(html)
	ajFmtPrintF(outf,
		    "<th>Base Number</th><th>Enzyme</th><th>Site</th>"
		    "<th>5'</th><th>3'</th><th>[5'</th><th>3']</th>\n");
    else
	ajFmtPrintF(outf,"# Base Number\tEnzyme\t\tSite\t\t5'\t3'\t"
		    "[5'\t3']\n");

    for(i=0;i<hits;++i)
    {
	ajListPop(l,(void **)&m);
	ajDebug("hit %d start:%d cut1:%d cut2:%d\n",
		i, m->start, m->cut1, m->cut2);

	hang1 = (ajint)m->cut1 - (ajint)m->start;
	hang2 = (ajint)m->cut2 - (ajint)m->start;

	if(!plasmid && (hang1>100 || hang2>100))
	{
	    embMatMatchDel(&m);
	    continue;
	}

	if(limit)
	{
	    value=ajTableFetchS(table,m->cod);
	    if(value)
		ajStrAssignS(&m->cod,value);
	}

	if(m->cut2 >= m->cut1)
	    ajStrAssignSubS(&overhead, ajSeqGetSeqS( seq), m->cut1, m->cut2-1);
	else
	{
	    ajStrAssignSubS(&overhead, ajSeqGetSeqS( seq), m->cut2, m->cut1-1);
	    ajStrReverse(&overhead);
	}

	ajDebug("overhead:%S seqcmp:%S\n", overhead, seqcmp);

	/* Print out only those who have the same overhang. */
	if(ajStrMatchCaseS(overhead, seqcmp))
	{
	    if(html)
	    {
		ajFmtPrintF(outf,
			    "<tr><td>%-d</td><td>%-16s</td><td>%-16s"
			    "</td><td>%d</td><td>%d</td></tr>\n",
			    m->start,ajStrGetPtr(m->cod),ajStrGetPtr(m->pat),
			    m->cut1,m->cut2);
	    }
	    else
		ajFmtPrintF(outf,"\t%-d\t%-16s%-16s%d\t%d\t\n",
			    m->start,ajStrGetPtr(m->cod),ajStrGetPtr(m->pat),
			    m->cut1,m->cut2);
	}

	if(frags)
	    fa[fn++] = m->cut1;

	if(m->cut3 || m->cut4)
	{
	    if(m->cut4 >= m->cut3)
		ajStrAssignSubS(&overhead, ajSeqGetSeqS( seq),
				m->cut3, m->cut4-1);
	    else
	    {
		ajStrAssignSubS(&overhead, ajSeqGetSeqS( seq),
				m->cut4, m->cut3-1);
		ajStrReverse(&overhead);
	    }

	    if(ajStrMatchCaseS(overhead, seqcmp))
	    {
		if(html)
		    ajFmtPrintF(outf,
				"<tr><td>%-d</td><td>%-16s</td><td>%-16s"
				"</td><td></td><td></td><td>%d</td><td>%d"
				"</td></tr>\n",
				m->start,ajStrGetPtr(m->cod),
				ajStrGetPtr(m->pat),
				m->cut1,m->cut2);
		else
		    ajFmtPrintF(outf,"\t%-d\t%-16s%-16s\t\t%d\t%d\t\n",
				m->start,ajStrGetPtr(m->cod),
				ajStrGetPtr(m->pat),
				m->cut1,m->cut2);
	    }
	}

	/* I am not sure what fragments are doing so I left it in ...*/
	/* used in the report tail in restrict - restover does much the same */
	if(m->cut3 || m->cut4)
	{
	    if(frags)
		fa[fn++] = m->cut3;
	    /*	       ajFmtPrintF(*outf,"%d\t%d",m->cut3,m->cut4);*/
	}
	ajStrDel(&overhead);

	embMatMatchDel(&m);
    }



    if(frags)
    {
	ajSortIntInc(fa,fn);
	ajFmtPrintF(outf,"\n\nFragment lengths:\n");
	if(!fn || (fn==1 && plasmid))
	    ajFmtPrintF(outf,"    %d\n",end-begin+1);
	else
	{
	    last = -1;
	    fb = 0;
	    for(i=0;i<fn;++i)
	    {
		if((c=fa[i])!=last)
		    fa[fb++]=c;
		last = c;
	    }
	    fn = fb;
	    /* Calc lengths */

	    for(i=0;i<fn-1;++i)
		fx[fc++] = fa[i+1]-fa[i];
	    if(!plasmid)
	    {
		fx[fc++] = fa[0]-begin+1;
		fx[fc++] = end-fa[fn-1];
	    }
	    else
		fx[fc++] = (fa[0]-begin+1)+(end-fa[fn-1]);

	    ajSortIntDec(fx,fc);
	    for(i=0;i<fc;++i)
		ajFmtPrintF(outf,"    %d\n",fx[i]);
	}
	AJFREE(fa);
	AJFREE(fx);
    }


    ajStrDel(&ps);

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

    return;
}