Animator::Animator(Object* obj, int frames) { addObjs(obj); _anims.resize(_objs.size()); addSeq(frames); reset(); }
int GTree::addSequence(int *bid, int n, int L, int seqID) //adds all the L-subseqs { n = n-L+1; if (n<0) n=0; for(int i=0;i<n;i++) { addSeq(bid,L,bid, seqID, gMAXMM, 0); bid++; } return n; }
bool AceParser::loadContig(int ctgidx, fnLytSeq* seqfn, bool re_pos) { bool forgetCtg = false; if (ctgidx>=contigs.Count()) GError("LayoutParser: invalid contig index '%d'\n", ctgidx); LytCtgData* ctgdata=contigs[ctgidx]; if (re_pos && currentContig!=NULL) { //free previously loaded contig data currentContig->seqs.Clear(); // unless it was a parse() call seqinfo.Clear(); } currentContig=ctgdata; int ctg_numSeqs=ctgdata->numseqs; if (re_pos) { seek(ctgdata->fpos); //position right where the contig definition starts char *r = linebuf->getLine(f,f_pos); if (r==NULL) return false; } if (seqfn!=NULL) { //process the contig sequence! char* ctgseq=readSeq(); forgetCtg=(*seqfn)(numContigs, ctgdata, NULL, ctgseq); GFREE(ctgseq); //obviously the caller should have made a copy } //now look for all the component sequences if (fskipTo("AF ")<0) { GMessage("AceParser: error finding sequence offsets (AF)" " for contig '%s' (%d)\n", ctgdata->name, ctgdata->len); return false; } int numseqs=0; while (startsWith(linebuf->chars(), "AF ",3)) { if (addSeq(linebuf->chars(), ctgdata)==NULL) { GMessage("AceParser: error parsing AF entry:\n%s\n",linebuf->chars()); return false; } numseqs++; //read next line: linebuf->getLine(f,f_pos); } if (numseqs!=ctg_numSeqs) { GMessage("Invalid number of AF entries found (%d) for contig '%s' " "(length %d, numseqs %d)\n", numseqs, ctgdata->name, ctgdata->len, ctg_numSeqs); return false; } //now read each sequence entry off_t seqpos=fskipTo("RD "); numseqs=0; //count again, now the RD entries if (seqpos<0) { GMessage("AceParser: error locating first RD entry for contig '%s'\n", ctgdata->name); return false; } //int numseqs=0; //reading the actual component sequence details while (startsWith(linebuf->chars(), "RD ",3)) { char* s=linebuf->chars()+3; char* p=strchrs(s, " \t"); LytSeqInfo* seq; if (p==NULL) { GMessage("AceParser: Error parsing RD header line:\n%s\n", linebuf->chars()); return false; } *p='\0'; if ((seq=seqinfo.Find(s))==NULL) { GMessage("AceParser: unknown RD encountered: '%s'\n", s); return false; } p++; //now p is in linebuf after the RD name seq->fpos=seqpos; int len; if (sscanf(p, "%d", &len)!=1) { GMessage("AceParser: cannot parse RD length for '%s'\n", s); return false; } seq->setLength(len); //read the sequence data here if a callback fn was given: char* sseq=NULL; if (seqfn!=NULL) sseq=readSeq(seq); //read full sequence here if (fskipTo("QA ")<0) { GMessage("AceParser: Error finding QA entry for read %s! (fpos=%llu)\n", seq->name, (unsigned long long)f_pos); return false; } //parse QA entry: int tmpa, tmpb; if (sscanf(linebuf->chars()+3, "%d %d %d %d", &tmpa, &tmpb, &seq->left,&seq->right)!=4 || seq->left<=0 || seq->right<=0) { GMessage("AceParser: Error parsing QA entry.\n"); return false; } /* if (fskipTo("DS")<0) { GMessage("AceParser: Error closing RD entry ('DS' not found).\n"); return false; } */ seqpos=getFilePos()+1; bool forgetSeq=false; if (seqfn!=NULL) { forgetSeq=(*seqfn)(numContigs, ctgdata, seq, sseq); GFREE(sseq); } if (forgetSeq) { //parsing the whole stream -- aceconv) ctg_numSeqs--; seqinfo.Remove(seq->name); ctgdata->seqs.RemovePtr(seq); } numseqs++; if (numseqs<ctgdata->numseqs) seqpos=fskipTo("RD ", "CO "); //more sequences left to read } if (numseqs!=ctgdata->numseqs) { GMessage("Error: Invalid number of RD entries found (%d) for contig '%s' " "(length %d, numseqs %d)\n", numseqs, ctgdata->name, ctgdata->len, ctg_numSeqs); return false; } if (forgetCtg) { ctgIDs.Remove(ctgdata->name); ctgdata->seqs.Clear(); seqinfo.Clear(); contigs.RemovePtr(ctgdata); } return true; }
/* Load contig data; can be called by parse - and then no fseek is needed and the file position if right after parsing the contig summary data */ bool LayoutParser::loadContig(int ctgidx, fnLytSeq* seqfn, bool re_pos) { bool forgetCtg=false; char* r=NULL; if (ctgidx>=contigs.Count()) GError("LayoutParser: invalid contig index '%d'\n", ctgidx); LytCtgData* ctgdata=contigs[ctgidx]; if (re_pos && currentContig!=NULL) { //free previous contig data //unless it was a parse() call currentContig->seqs.Clear(); seqinfo.Clear(); } currentContig=ctgdata; if (re_pos) { seek(ctgdata->fpos); //position right where the contig definition starts r=linebuf->getLine(f,f_pos);//skip the first line if (r==NULL) return false; } if (seqfn!=NULL) forgetCtg=(*seqfn)(numContigs, ctgdata, NULL, NULL); int ctg_numSeqs=ctgdata->numseqs; int numseqs=0; while ((r=linebuf->getLine(f,f_pos))!=NULL) { if (linebuf->length()<4) continue; if (linebuf->chars()[0]=='>') { linebuf->pushBack(); break; //reached next contig } //sequence data parsing bool forgetSeq=false; LytSeqInfo* seq=NULL; if ((seq=addSeq(linebuf->chars(), ctgdata))==NULL) { GMessage("LayoutParser: error parsing sequence entry:\n%s\n",linebuf->chars()); return false; } /* // Weird -- why would I MODIFY the given clipping of a sequence? //-- bool ctg_clipping = (ctgdata->rpos>ctgdata->lpos); if (ctg_clipping) { if (ctgdata->lpos > seq->offs && ctgdata->lpos < seq->offs+seq->length()) seq->left = ctgdata->lpos - seq->offs+1; if (ctgdata->rpos < seq->offs+seq->length() && ctgdata->rpos>seq->offs ) seq->right = ctgdata->rpos-seq->offs+1; } */ if (seqfn!=NULL) forgetSeq=(*seqfn)(numContigs, ctgdata, seq, NULL); if (forgetSeq) { ctg_numSeqs--; seqinfo.Remove(seq->name); ctgdata->seqs.RemovePtr(seq); } else { numseqs++; } } //while sequences if (forgetCtg) { ctgIDs.Remove(ctgdata->name); contigs.RemovePtr(ctgdata); } if (numseqs!=ctg_numSeqs) { GMessage("Mismatching number of sequences found (%d) for contig '%s' " "(length %d, numseqs %d)\n", numseqs, ctgdata->name, ctgdata->len, ctg_numSeqs); return false; } return true; }
Animator::Animator(const std::vector<Object*>& objs, int frames) : _objs(objs) { _anims.resize(_objs.size()); addSeq(frames); reset(); }