int PreClusterCommand::loadSeqs(map<string, string>& thisName, vector<Sequence>& thisSeqs, string group){ try { set<int> lengths; alignSeqs.clear(); map<string, string>::iterator it; bool error = false; map<string, int> thisCount; if (countfile != "") { thisCount = cparser->getCountTable(group); } for (int i = 0; i < thisSeqs.size(); i++) { if (m->control_pressed) { return 0; } if (namefile != "") { it = thisName.find(thisSeqs[i].getName()); //should never be true since parser checks for this if (it == thisName.end()) { m->mothurOut(thisSeqs[i].getName() + " is not in your names file, please correct."); m->mothurOutEndLine(); error = true; } else{ //get number of reps int numReps = 1; for(int j=0;j<(it->second).length();j++){ if((it->second)[j] == ','){ numReps++; } } seqPNode tempNode(numReps, thisSeqs[i], it->second); alignSeqs.push_back(tempNode); lengths.insert(thisSeqs[i].getAligned().length()); } }else { //no names file, you are identical to yourself int numRep = 1; if (countfile != "") { map<string, int>::iterator it2 = thisCount.find(thisSeqs[i].getName()); //should never be true since parser checks for this if (it2 == thisCount.end()) { m->mothurOut(thisSeqs[i].getName() + " is not in your count file, please correct."); m->mothurOutEndLine(); error = true; } else { numRep = it2->second; } } seqPNode tempNode(numRep, thisSeqs[i], thisSeqs[i].getName()); alignSeqs.push_back(tempNode); lengths.insert(thisSeqs[i].getAligned().length()); } } if (lengths.size() > 1) { error = true; m->mothurOut("[ERROR]: your sequences are not all the same length. pre.cluster requires sequences to be aligned."); m->mothurOutEndLine(); } else if (lengths.size() == 1) { length = *(lengths.begin()); } //sanity check if (error) { m->control_pressed = true; } thisSeqs.clear(); return alignSeqs.size(); } catch(exception& e) { m->errorOut(e, "PreClusterCommand", "loadSeqs"); exit(1); } }
int PreClusterCommand::readFASTA(){ try { //ifstream inNames; ifstream inFasta; m->openInputFile(fastafile, inFasta); set<int> lengths; while (!inFasta.eof()) { if (m->control_pressed) { inFasta.close(); return 0; } Sequence seq(inFasta); m->gobble(inFasta); if (seq.getName() != "") { //can get "" if commented line is at end of fasta file if (namefile != "") { itSize = sizes.find(seq.getName()); if (itSize == sizes.end()) { m->mothurOut(seq.getName() + " is not in your names file, please correct."); m->mothurOutEndLine(); exit(1); } else{ seqPNode tempNode(itSize->second, seq, names[seq.getName()]); alignSeqs.push_back(tempNode); lengths.insert(seq.getAligned().length()); } }else { //no names file, you are identical to yourself int numRep = 1; if (countfile != "") { numRep = ct.getNumSeqs(seq.getName()); } seqPNode tempNode(numRep, seq, seq.getName()); alignSeqs.push_back(tempNode); lengths.insert(seq.getAligned().length()); } } } inFasta.close(); if (lengths.size() > 1) { method = "unaligned"; } else if (lengths.size() == 1) { method = "aligned"; } length = *(lengths.begin()); return alignSeqs.size(); } catch(exception& e) { m->errorOut(e, "PreClusterCommand", "readFASTA"); exit(1); } }
ListNode * merge(ListNode *lhs, ListNode *rhs) { if (lhs == NULL && rhs == NULL) { return NULL; }else if (lhs == NULL) { return rhs; }else if (rhs == NULL) { return lhs; } ListNode tempNode(0); ListNode *p = &tempNode; while (lhs && rhs) { if (lhs->val < rhs->val) { p->next = lhs; lhs = lhs->next; }else { p->next = rhs; rhs = rhs->next; } p = p->next; } if (lhs) { p->next = lhs; } if (rhs) { p->next = rhs; } return tempNode.next; }
ListNode* reverseBetween(ListNode* head, int m, int n) { if (head == NULL) { return NULL; } ListNode tempNode(0); tempNode.next = head; ListNode *prev = &tempNode; //move to m-1 elements for (int i = 1; i < m; ++i) { prev = prev->next; } ListNode *pm = prev->next; //reverse m to n elements for (int i = m; i < n; ++i) { ListNode *pn = pm->next; pm->next = pn->next; pn->next = prev->next; prev->next = pn; } return tempNode.next; }