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; }
AjBool ensCacheSynchronise(EnsPCache cache) { AjIList iter = NULL; CachePNode node = NULL; if(!cache) return ajFalse; iter = ajListIterNew(cache->List); while(!ajListIterDone(iter)) { node = (CachePNode) ajListIterGet(iter); if(cache->Write && node->Value && node->Dirty) { (*cache->Write)(node->Value); node->Dirty = ajFalse; } } ajListIterDel(&iter); return ajTrue; }
static void remap_RenamePreferred(const AjPList list, const AjPTable table, AjPList newlist) { AjIList iter = NULL; AjPStr key = NULL; const AjPStr value = NULL; AjPStr name = NULL; iter = ajListIterNewread(list); while((key = (AjPStr)ajListIterGet(iter))) { /* ** If a key-value entry found, write the new value to the new list ** else write the old key name to the new list */ value = ajTableFetchS(table, key); name = ajStrNew(); if(value) { ajDebug("Rename: %S renamed to %S\n", key, value); ajStrAssignS(&name, value); } else { ajDebug("Rename: %S not found\n", key); ajStrAssignS(&name, key); } ajListstrPushAppend(newlist, name); } ajListIterDel(&iter); return; }
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; }
void ajPatlistSeqRewind (AjPPatlistSeq thys) { if (thys->Iter) ajListIterDel(&thys->Iter); thys->Iter=NULL; return; }
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 AjBool extractfeat_MatchPatternTags(const AjPFeature feat, const AjPStr tpattern, const AjPStr vpattern) { AjIList titer; /* iterator for feat */ AjPStr tagnam = NULL; /* tag structure */ AjPStr tagval = NULL; /* tag structure */ AjBool val = ajFalse; /* returned value */ AjBool tval; /* tags result */ AjBool vval; /* value result */ /* ** if there are no tags to match, but the patterns are ** both '*', then allow this as a match */ if(!ajStrCmpC(tpattern, "*") && !ajStrCmpC(vpattern, "*")) return ajTrue; /* iterate through the tags and test for match to patterns */ titer = ajFeatTagIter(feat); while(ajFeatTagval(titer, &tagnam, &tagval)) { tval = embMiscMatchPatternDelimC(tagnam, tpattern, ",;|"); /* ** If tag has no value then ** If vpattern is '*' the value pattern is a match ** Else check vpattern */ if(!ajStrGetLen(tagval)) { if(!ajStrCmpC(vpattern, "*")) vval = ajTrue; else vval = ajFalse; } else vval = embMiscMatchPatternDelimC(tagval, vpattern, ",;|"); if(tval && vval) { val = ajTrue; break; } } ajListIterDel(&titer); ajStrDel(&tagnam); ajStrDel(&tagval); return val; }
static void primersearch_print_hits(const AjPList primerList, AjPFile outf) { /* iterate through list of hits */ AjIList lIter; ajint count = 1; lIter = ajListIterNewread(primerList); while(!ajListIterDone(lIter)) { Primer primer = ajListIterGet(lIter); AjIList hIter = ajListIterNewread(primer->hitlist); count = 1; ajFmtPrintF(outf, "\nPrimer name %s\n", ajStrGetPtr(primer->Name)); while(!ajListIterDone(hIter)) { PHit hit = ajListIterGet(hIter); ajFmtPrintF(outf, "Amplimer %d\n", count); ajFmtPrintF(outf, "\tSequence: %s %s \n\t%s\n", ajStrGetPtr(hit->seqname), ajStrGetPtr(hit->acc), ajStrGetPtr(hit->desc)); ajFmtPrintF(outf, "\t%s hits forward strand at %d with %d " "mismatches\n", ajStrGetPtr(hit->forward), hit->forward_pos, hit->forward_mismatch); ajFmtPrintF(outf, "\t%s hits reverse strand at [%d] with %d " "mismatches\n", ajStrGetPtr(hit->reverse), (hit->reverse_pos), (hit->reverse_mismatch)); ajFmtPrintF(outf, "\tAmplimer length: %d bp\n", hit->amplen); count++; } ajListIterDel(&hIter); } ajListIterDel(&lIter); return; }
static void splitter_AddSubSeqFeat(AjPFeattable ftable, ajuint start, ajuint end, const AjPSeq oldseq) { AjPFeattable old_feattable = NULL; AjIList iter = NULL; old_feattable = ajSeqGetFeatCopy(oldseq); if(!old_feattable) return; iter = ajListIterNewread(old_feattable->Features); while(!ajListIterDone(iter)) { AjPFeature gf = ajListIterGet(iter); AjPFeature copy = NULL; if (((ajFeatGetEnd(gf) < start + 1) && (gf->End2 == 0 || gf->End2 < start + 1)) || ((ajFeatGetStart(gf) > end + 1) && (gf->Start2 == 0 || gf->Start2 > end + 1))) { continue; } copy = ajFeatNewFeat(gf); copy->Start = copy->Start - start; copy->End = copy->End - start; if (copy->Start2 > 0) copy->Start2 = copy->Start2 - start; if (copy->End2 > 0) copy->End2 = copy->End2 - start; ajFeatTrimOffRange (copy, 0, 1, end - start + 1, AJTRUE, AJTRUE); ajFeattableAdd(ftable, copy); } ajFeattableDel(&old_feattable); ajListIterDel(&iter); return; }
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; }
static void dastestSaveMappedFeatures(const AjPFeattable fttable, const AjPStr ffname, AjPFile outf, ajint maxfeatures) { AjPFeature feature = NULL; AjIList iterfts = NULL; AjPFeattabOut ftout = NULL; AjPFile ffile = NULL; AjPStr ffnamee = ajStrNew(); ajint i=0; if (fttable == NULL) { ajWarn("null feature table, %S", ffname); return; } ajFmtPrintS(&ffnamee, "%S.mapped.dasgff", ffname); ffile = ajFileNewOutNameS(ffnamee); iterfts = ajListIterNew(fttable->Features); ftout= ajFeattabOutNewCSF("gff3",NULL,"",ffile); ajFmtPrintF(outf, "Number of features %d\n", ajListGetLength(fttable->Features)); while(!ajListIterDone(iterfts) && i++ < maxfeatures) { feature = ajListIterGet(iterfts); ajFmtPrintF(outf, "feature id:%S orientation:%c start:%d stop:%d\n", feature->Label, feature->Strand, feature->Start, feature->End); } ajListIterDel(&iterfts); ajFeattableWriteDasgff(ftout, fttable); ajFeattabOutDel(&ftout); ajFileClose(&ffile); ajStrDel(&ffnamee); return; }
/* @funcstatic skipredundant_ClearList ************************************** ** ** Clears a list of sequences from a sequence set. ** The sequences are copied ** ** @param [u] list [AjPList] List ** @return [AjBool] True on success ******************************************************************************/ static AjBool skipredundant_ClearList (AjPList list) { EmbPDmxNrseq seq_tmp = NULL; AjIList iter; if(!list) return ajFalse; iter = ajListIterNew(list); while(!ajListIterDone(iter)) { seq_tmp = (EmbPDmxNrseq)ajListIterGet(iter); embDmxNrseqDel(&seq_tmp); } ajListIterDel(&iter); return ajTrue; }
static AjBool extractfeat_MatchPatternDescribe(const AjPFeature feat, const AjPStr describe, AjPStr *strout) { AjIList titer; /* iterator for feat */ AjPStr tagnam = NULL; /* tag structure */ AjPStr tagval = NULL; /* tag structure */ AjBool val = ajFalse; /* returned value */ /* iterate through the tags and test for match to patterns */ titer = ajFeatTagIter(feat); while(ajFeatTagval(titer, &tagnam, &tagval)) { if(embMiscMatchPatternDelimC(tagnam, describe, ",;|")) { /* There's a match, so write to strout in a pretty format */ if(!val) ajStrAssignC(strout, "("); else ajStrAppendC(strout, ", "); val = ajTrue; ajStrAppendS(strout, tagnam); if(ajStrGetLen(tagval)) { ajStrAppendC(strout, "=\""); ajStrAppendS(strout, tagval); ajStrAppendC(strout, "\""); } } } ajListIterDel(&titer); if(val) ajStrAppendC(strout, ") "); ajStrDel(&tagnam); ajStrDel(&tagval); return val; }
static AjBool cacheNodeRemove(EnsPCache cache, const CachePNode node) { AjIList iter = NULL; CachePNode lnode = NULL; if(!cache) return ajFalse; if(!node) return ajFalse; /* Remove the node from the AJAX List. */ iter = ajListIterNew(cache->List); while(!ajListIterDone(iter)) { lnode = (CachePNode) ajListIterGet(iter); if(lnode == node) { ajListIterRemove(iter); break; } } ajListIterDel(&iter); /* Remove the node from the AJAX Table. */ ajTableRemove(cache->Table, node->Key); /* Update the cache statistics. */ cache->Bytes -= node->Bytes; cache->Count--; cache->Removed++; return ajTrue; }
/* @funcstatic sigscanlig_WriteResults **************************************** ** ** Function to write SIGSCANLIG results file. ** ** @param [r] results [AjPList] List of Lighit objects. ** @param [r] resultsf [AjPFile] Results file. ** ** @return [ajint] 1 if score1<score2, 0 if score1==score2, else -1. ** @@ ******************************************************************************/ void sigscanlig_WriteResults(AjPList results, AjPFile resultsf) { AjIList iter = NULL; /* Iterator. */ SigPLighit lighit = NULL; iter = ajListIterNew(results); ajFmtPrintF(resultsf, "%-10s%-10s%-10s%-10s\n", "LIGID", "PATCHES", "SITES", "SCORE"); while((lighit = (SigPLighit) ajListIterGet(iter))) ajFmtPrintF(resultsf, "%-10S%-10d%-10d%-10.2f\n", lighit->ligid, lighit->np, lighit->ns, lighit->score); ajListIterDel(&iter); return; }
void ajPatlistSeqDel (AjPPatlistSeq* pthys) { AjPPatlistSeq thys = NULL; AjPPatternSeq patternseq = NULL; thys = *pthys; while (ajListPop(thys->Patlist, (void **)&patternseq)) ajPatternSeqDel(&patternseq); if (thys->Iter) ajListIterDel(&thys->Iter); ajListFree(&thys->Patlist); AJFREE(*pthys); return; }
static void primersearch_primer_search(const AjPList primerList, const AjPSeq seq) { AjIList listIter; /* test each list node against this sequence */ listIter = ajListIterNewread(primerList); while(!ajListIterDone(listIter)) { Primer curr_primer = ajListIterGet(listIter); primersearch_scan_seq(curr_primer, seq, AJFALSE); primersearch_scan_seq(curr_primer, seq, AJTRUE); } ajListIterDel(&listIter); return; }
static AjPTable dastestGetTitleCount(const AjPDasServer server) { AjIList iter = NULL; AjPTable titlecount = NULL; AjPDasSource source = NULL; AjPStr title = NULL; ajuint* count = NULL; titlecount = ajTablestrNewCaseConst(ajListGetLength(server->sources)+20); iter = ajListIterNew(server->sources); while(!ajListIterDone(iter)) { source = ajListIterGet(iter); title = source->title; count = ajTableFetchmodS(titlecount,title); if (count != NULL) { (*count)++; } else { AJNEW(count); *count = 1; ajTablePut(titlecount, title, (void*)count); } } ajListIterDel(&iter); return titlecount; }
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; }
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; }
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; }
static void extractfeat_FeatureFilter(AjPFeattable featab, const AjPStr source, const AjPStr type, ajint sense, AjBool testscore, float minscore, float maxscore, const AjPStr tag, const AjPStr value) { AjIList iter = NULL; AjPFeature gf = NULL; /* ** 'tagsmatch' is set true if a parent of a join() ** has matching tag/values. ** Remember the value of a the pattern match to the tags ** of the parent of a join() because the children of the join() ** don't contain the tags information in their gf's */ AjBool tagsmatch = ajFalse; /* foreach feature in the feature table */ if(featab) { iter = ajListIterNew(featab->Features); while(!ajListIterDone(iter)) { gf = (AjPFeature)ajListIterGet(iter); if(!extractfeat_MatchFeature(gf, source, type, sense, testscore, minscore, maxscore, tag, value, &tagsmatch)) { /* no match, so delete feature from feature table */ ajFeatDel(&gf); ajListIterRemove(iter); } } ajListIterDel(&iter); } return; }
void ajPatlistRegexDel (AjPPatlistRegex* pthys) { AjPPatlistRegex thys = NULL; AjPPatternRegex patternregex = NULL; thys = *pthys; while (ajListPop(thys->Patlist, (void **)&patternregex)) { ajDebug("ajPatlistRegexDel list size: %d\n", ajListGetLength(thys->Patlist)); ajPatternRegexDel(&patternregex); } if (thys->Iter) ajListIterDel(&thys->Iter); ajListFree(&thys->Patlist); AJFREE(*pthys); return; }
static void primersearch_free_primer(void **x, void *cl) { Primer* p; Primer primdata; AjIList lIter; (void) cl; /* make it used */ p = (Primer*) x; primdata = *p; primersearch_free_pguts(&primdata->forward); primersearch_free_pguts(&primdata->reverse); ajStrDel(&primdata->Name); /* clean up hitlist */ lIter = ajListIterNewread(primdata->hitlist); while(!ajListIterDone(lIter)) { PHit phit = ajListIterGet(lIter); ajStrDel(&phit->forward); ajStrDel(&phit->reverse); ajStrDel(&phit->seqname); ajStrDel(&phit->acc); ajStrDel(&phit->desc); AJFREE(phit); } ajListFree(&primdata->hitlist); ajListFree(&primdata->hitlist); ajListIterDel(&lIter); AJFREE(primdata); return; }
static void remap_NoCutList(AjPFile outfile, const AjPTable hittable, AjBool html, const AjPStr enzymes, AjBool blunt, AjBool sticky, ajuint sitelen, AjBool commercial, AjBool ambiguity, AjBool limit, const AjPTable retable) { /* for iterating over hittable */ PValue value; void **keyarray = NULL; /* array for table */ void **valarray = NULL; /* array for table */ ajint i; /* list of enzymes that cut */ AjPList cutlist; AjIList citer; /* iterator for cutlist */ AjPStr cutname = NULL; AjBool found; /* for parsing value->iso string */ AjPStrTok tok; char tokens[] = " ,"; AjPStr code = NULL; const char *p; /* for reading in enzymes names */ AjPFile enzfile = NULL; AjPStr *ea; ajint ne; /* number of enzymes */ AjBool isall = ajTrue; /* list of enzymes that don't cut */ AjPList nocutlist; AjIList niter; /* iterator for nocutlist */ AjPStr nocutname = NULL; /* count of rejected enzymes not matching criteria */ ajint rejected_count = 0; EmbPPatRestrict enz; /* for renaming preferred isoschizomers */ AjPList newlist; /* ** ** Make a list of enzymes('cutlist') that hit ** including the isoschizomer names ** */ ajDebug("Make a list of all enzymes that cut\n"); cutlist = ajListstrNew(); nocutlist = ajListstrNew(); ajTableToarrayKeysValues(hittable, &keyarray, &valarray); for(i = 0; keyarray[i]; i++) { value = (PValue) valarray[i]; cutname = ajStrNew(); ajStrAssignRef(&cutname, keyarray[i]); ajListstrPushAppend(cutlist, cutname); /* Add to cutlist all isoschizomers of enzymes that cut */ ajDebug("Add to cutlist all isoschizomers of enzymes that cut\n"); /* start token to parse isoschizomers names */ tok = ajStrTokenNewC(value->iso, tokens); while(ajStrTokenNextParseC(&tok, tokens, &code)) { cutname = ajStrNew(); ajStrAssignS(&cutname, code); ajListstrPushAppend(cutlist, cutname); } ajStrTokenDel(&tok); } ajStrDel(&code); AJFREE(keyarray); AJFREE(valarray); /* ** Read in list of enzymes ('nocutlist') - either all or ** the input enzyme list. ** Exclude those that don't match the selection criteria - count these. */ ajDebug("Read in a list of all input enzyme names\n"); ne = 0; if(!enzymes) isall = ajTrue; else { /* get input list of enzymes into ea[] */ ne = ajArrCommaList(enzymes, &ea); if(ajStrMatchCaseC(ea[0], "all")) isall = ajTrue; else { isall = ajFalse; for(i=0; i<ne; ++i) ajStrRemoveWhite(&ea[i]); } } enzfile = ajDatafileNewInNameC(ENZDATA); /* push all enzyme names without the required criteria onto nocutlist */ enz = embPatRestrictNew(); while(!ajFileIsEof(enzfile)) { if(!embPatRestrictReadEntry(enz, enzfile)) continue; /* ** If user entered explicit enzyme list, then check to see if ** this is one of that explicit list */ if(!isall) { found = AJFALSE; for(i=0; i<ne; ++i) if(ajStrMatchCaseS(ea[i], enz->cod)) { found = AJTRUE; break; } if(!found) /* not in the explicit list */ continue; ajDebug("RE %S is in the input explicit list of REs\n", enz->cod); } /* ignore ncuts==0 as they are unknown */ if(!enz->ncuts) { /* number of cut positions */ ajDebug("RE %S has an unknown number of cut positions\n", enz->cod); continue; } ajDebug("RE %S has a known number of cut sites\n", enz->cod); if(enz->len < sitelen) { /* recognition site length */ ajDebug("RE %S does not have a long enough recognition site\n", enz->cod); rejected_count++; continue; } if(!blunt && enz->blunt) { /* blunt/sticky */ ajDebug("RE %S is blunt\n", enz->cod); rejected_count++; continue; } if(!sticky && !enz->blunt) { /* blunt/sticky */ ajDebug("RE %S is sticky\n", enz->cod); rejected_count++; continue; } /* commercially available enzymes have uppercase patterns */ p = ajStrGetPtr(enz->pat); /* ** The -commercial qualifier is only used if we are searching ** through 'all' of the REBASE database - if we have specified an ** explicit list of enzymes then they are searched for whether or ** not they are commercially available */ if((*p >= 'a' && *p <= 'z') && commercial && isall) { ajDebug("RE %S is not commercial\n", enz->cod); rejected_count++; continue; } if(!ambiguity && remap_Ambiguous(enz->pat)) { ajDebug("RE %S is ambiguous\n", enz->cod); rejected_count++; continue; } ajDebug("RE %S matches all required criteria\n", enz->cod); code = ajStrNew(); ajStrAssignS(&code, enz->cod); ajListstrPushAppend(nocutlist, code); } embPatRestrictDel(&enz); ajFileClose(&enzfile); for(i=0; i<ne; ++i) if(ea[i]) ajStrDel(&ea[i]); if(ne) AJFREE(ea); /* ** Change names of enzymes in the non-cutter list ** to that of preferred (prototype) ** enzyme name so that the isoschizomers of cutters ** will be removed from the ** non-cutter list in the next bit. ** Remove duplicate prototype names. */ if(limit) { newlist = ajListstrNew(); remap_RenamePreferred(nocutlist, retable, newlist); ajListstrFreeData(&nocutlist); nocutlist = newlist; ajListSortUnique(nocutlist, remap_cmpcase, remap_strdel); } /* ** Iterate through the list of input enzymes removing those that are in ** the cutlist. */ ajDebug("Remove from the nocutlist all enzymes and isoschizomers " "that cut\n"); /* ** This steps down both lists at the same time, comparing names and ** iterating to the next name in whichever list whose name compares ** alphabetically before the other. Where a match is found, the ** nocutlist item is deleted. */ ajListSort(nocutlist, remap_cmpcase); ajListSort(cutlist, remap_cmpcase); citer = ajListIterNewread(cutlist); niter = ajListIterNew(nocutlist); /* while((cutname = (AjPStr)ajListIterGet(citer)) != NULL) ajDebug("dbg cutname = %S\n", cutname); */ nocutname = (AjPStr)ajListIterGet(niter); cutname = (AjPStr)ajListIterGet(citer); ajDebug("initial cutname, nocutname: '%S' '%S'\n", cutname, nocutname); while(nocutname != NULL && cutname != NULL) { i = ajStrCmpCaseS(cutname, nocutname); ajDebug("compare cutname, nocutname: %S %S ", cutname, nocutname); ajDebug("ajStrCmpCase=%d\n", i); if(i == 0) { /* match - so remove from nocutlist */ ajDebug("ajListstrRemove %S\n", nocutname); ajListstrIterRemove(niter); nocutname = (AjPStr)ajListIterGet(niter); /* ** Don't increment the cutname list pointer here ** - there may be more than one entry in the nocutname ** list with the same name because we have converted ** isoschizomers to their preferred name */ /* cutname = (AjPStr)ajListIterGet(citer); */ } else if(i == -1) /* cutlist name sorts before nocutlist name */ cutname = (AjPStr)ajListIterGet(citer); else if(i == 1) /* nocutlist name sorts before cutlist name */ nocutname = (AjPStr)ajListIterGet(niter); } ajListIterDel(&citer); ajListIterDel(&niter); ajListstrFreeData(&cutlist); /* Print the resulting list of those that do not cut*/ ajDebug("Print out the list\n"); /* print the title */ if(html) ajFmtPrintF(outfile, "<H2>"); ajFmtPrintF(outfile, "\n\n# Enzymes that do not cut\n\n"); if(html) ajFmtPrintF(outfile, "</H2>\n"); if(html) ajFmtPrintF(outfile, "<PRE>"); /* ajListSort(nocutlist, ajStrVcmp);*/ niter = ajListIterNewread(nocutlist); i = 0; while((nocutname = (AjPStr)ajListIterGet(niter)) != NULL) { ajFmtPrintF(outfile, "%-10S", nocutname); /* new line after every 7 names printed */ if(i++ == 7) { ajFmtPrintF(outfile, "\n"); i = 0; } } ajListIterDel(&niter); /* end the output */ ajFmtPrintF(outfile, "\n"); if(html) {ajFmtPrintF(outfile, "</PRE>\n");} /* ** Print the count of rejected enzymes ** N.B. This is the count of ALL rejected enzymes including all ** isoschizomers */ if(html) ajFmtPrintF(outfile, "<H2>"); ajFmtPrintF(outfile, "\n\n# No. of cutting enzymes which do not match the\n" "# SITELEN, BLUNT, STICKY, COMMERCIAL, AMBIGUOUS criteria\n\n"); if(html) ajFmtPrintF(outfile, "</H2>\n"); ajFmtPrintF(outfile, "%d\n", rejected_count); ajDebug("Tidy up\n"); ajListstrFreeData(&nocutlist); ajListstrFreeData(&cutlist); return; }
static void remap_RestrictPreferred(const AjPList l, const AjPTable t) { AjIList iter = NULL; EmbPMatMatch m = NULL; const AjPStr value = NULL; AjPStr newiso = NULL; AjBool found; /* name found in isoschizomer list */ /* for parsing value->iso string */ AjPStrTok tok = NULL; char tokens[] = " ,"; AjPStr code = NULL; iter = ajListIterNewread(l); while((m = (EmbPMatMatch)ajListIterGet(iter))) { found = ajFalse; /* get prototype name */ value = ajTableFetchS(t, m->cod); if(value) { ajStrAssignC(&newiso, ""); /* parse isoschizomer names from m->iso */ ajStrTokenDel(&tok); tok = ajStrTokenNewC(m->iso, tokens); while(ajStrTokenNextParseC(&tok, tokens, &code)) { if(ajStrGetLen(newiso) > 0) ajStrAppendC(&newiso, ","); /* found the prototype name? */ if(!ajStrCmpCaseS(code, value)) { ajStrAppendS(&newiso, m->cod); found = ajTrue; } else ajStrAppendS(&newiso, code); } ajStrTokenDel(&tok); /* if the name was not replaced, then add it in now */ if(!found) { if(ajStrGetLen(newiso) > 0) ajStrAppendC(&newiso, ","); ajStrAppendS(&newiso, m->cod); } ajDebug("RE: %S -> %S iso=%S newiso=%S\n", m->cod, value, m->iso, newiso); /* replace the old iso string with the new one */ ajStrAssignS(&m->iso, newiso); /* rename the enzyme to the prototype name */ ajStrAssignS(&m->cod, value); } } ajListIterDel(&iter); ajStrDel(&newiso); ajStrDel(&code); ajStrTokenDel(&tok); return; }
/* @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; }
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; }
static AjBool sigscanlig_SignatureAlignWriteBlock(AjPFile outf, AjPList hits) /* static AjBool sigscanlig_SignatureAlignWriteBlock(AjPFile outf, AjPList siglist, AjPList hits) */ { /* ** A line of the alignment (including accession number, a space and the ** sequence) in the output file is 70 characters long. An index number is ** also printed after this 70 character field. */ ajint wid1 = 0; /*Temp. width of Accession Number */ ajint mwid1 = 0; /* ** Max. width of Accession Number or the string ** "Number". ** This is the field width the accession numbers ** will be printed into */ ajint mwid2 = 0; /* Width of region to print sequence into */ ajint len = 0; /* Temp. length of sequence */ ajint mlen = 0; /* Max. length of sequence */ const char *ptrp = NULL; /* Pointer to sequence string */ const char *ptrs = NULL; /* Pointer to alignment string */ ajint idx = 0; /* Start position for printing */ ajint niter = 0; /* ** No. iterations of loop for printing out ** sequence blocks */ ajint fwid1 = 70; /* ** Including accession number, a space, 7 characters ** for the first index number, and the sequence */ ajint fwid2 = 7; /* Field width for the first index number */ ajint num = 0; /* Index number for alignment */ ajint y = 0; /* Loop counter */ AjIList iter = NULL; AjIList itersig = NULL; EmbPHit hit = NULL; ajint hitcnt=0; /* Counter for current hit */ AjPStr label = NULL; /* Check args */ /* if(!outf || !hits || !siglist) return ajFalse; */ if(!outf || !hits) return ajFalse; /* Cycle through hits to find longest width of accession number. */ len=0; mlen=0; wid1=0; mwid1=0; label = ajStrNew(); iter = ajListIterNew(hits); while((hit = (EmbPHit) ajListIterGet(iter))) { if((wid1=MAJSTRGETLEN(hit->Sig->Ligid))>mwid1) mwid1 = wid1; if((len=MAJSTRGETLEN(hit->Seq))>mlen) mlen = len; } ajListIterDel(&iter); ajListIterDel(&itersig); /* Assign field widths and number of iterations for printing. */ if((wid1 = strlen("SIGNATURE"))>mwid1) mwid1 = wid1; mwid1++; /* A space */ mwid1 += 8; /* 2 underscores + 2 integers in 3 char spacing each. */ mwid2 = fwid1-fwid2-mwid1; niter = (ajint)ceil( ((double)mlen/(double)mwid2)); /* Print header info and SCOP classification records of signature */ ajFmtPrintF(outf, "# DE Alignment of query sequence against library of " "signatures\n"); /* Main loop for printing alignment. */ iter = ajListIterNew(hits); while((hit = (EmbPHit) ajListIterGet(iter))) { /* Get pointer to sequence & alignment string. */ ptrp = ajStrGetPtr(hit->Seq); ptrs = ajStrGetPtr(hit->Alg); /* Print spacer */ ajFmtPrintF(outf, "# XX\n"); ajFmtPrintF(outf, "# "); /* if((!sigscanlig_WriteFastaHit(outf, siglist, hits, hitcnt, ajFalse))) ajFatal("Bad args to sigscanlig_WriteFasta"); */ if((!sigscanlig_WriteFastaHit(outf, hits, hitcnt, ajFalse))) ajFatal("Bad args to sigscanlig_WriteFasta"); ajFmtPrintF(outf, "\n# XX\n"); /* Loop for each protein in Hitlist. */ for(num=0, idx=0, y=0;y<niter;y++) { num+=mwid2; ajFmtPrintS(&label, "%S_%d_%d", hit->Sig->Ligid, hit->Sig->sn, hit->Sig->pn); /* There is some of the sequence left to print. */ if(idx<MAJSTRGETLEN(hit->Seq)) { ajFmtPrintF(outf,"%-*S%-*d%-*.*s %d\n", mwid1, hit->Acc, fwid2, (num-mwid2+1), mwid2, mwid2, ptrp+idx, num); ajFmtPrintF(outf,"%-*S%-*c%-*.*s\n", mwid1, label, fwid2, '-', mwid2, mwid2, ptrs+idx); } /* Printed all the sequence already. */ else { ajFmtPrintF(outf,"%-*S%-*d%-*.*s %d\n", mwid1, hit->Acc, fwid2, (num-mwid2+1), mwid2, mwid2, ".", num); ajFmtPrintF(outf,"%-*S%-*c%-*.*s\n", mwid1, label, fwid2, '-', mwid2, mwid2, "." ); } idx += mwid2; } hitcnt++; } ajListIterDel(&iter); ajListIterDel(&itersig); ajStrDel(&label); return ajTrue; }
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; }