+/***************************************************************************************************************/
+//ccode algo says it does this to "Removes the initial and final gaps to avoid biases due to incomplete sequences."
+void Ccode::trimSequences() {
+ try {
+
+ int frontPos = 0; //should contain first position in all seqs that is not a gap character
+ int rearPos = querySeqs[0]->getAligned().length();
+
+ //********find first position in all seqs that is a non gap character***********//
+ //find first position all query seqs that is a non gap character
+ for (int i = 0; i < querySeqs.size(); i++) {
+
+ string aligned = querySeqs[i]->getAligned();
+ int pos = 0;
+
+ //find first spot in this seq
+ for (int j = 0; j < aligned.length(); j++) {
+ if (isalpha(aligned[j])) {
+ pos = j;
+ break;
+ }
+ }
+
+ //save this spot if it is the farthest
+ if (pos > frontPos) { frontPos = pos; }
+ }
+
+ //find first position all template seqs that is a non gap character
+ for (int i = 0; i < templateSeqs.size(); i++) {
+
+ string aligned = templateSeqs[i]->getAligned();
+ int pos = 0;
+
+ //find first spot in this seq
+ for (int j = 0; j < aligned.length(); j++) {
+ if (isalpha(aligned[j])) {
+ pos = j;
+ break;
+ }
+ }
+
+ //save this spot if it is the farthest
+ if (pos > frontPos) { frontPos = pos; }
+ }
+
+
+ //********find last position in all seqs that is a non gap character***********//
+ //find last position all query seqs that is a non gap character
+ for (int i = 0; i < querySeqs.size(); i++) {
+
+ string aligned = querySeqs[i]->getAligned();
+ int pos = aligned.length();
+
+ //find first spot in this seq
+ for (int j = aligned.length()-1; j >= 0; j--) {
+ if (isalpha(aligned[j])) {
+ pos = j;
+ break;
+ }
+ }
+
+ //save this spot if it is the farthest
+ if (pos < rearPos) { rearPos = pos; }
+ }
+
+ //find last position all template seqs that is a non gap character
+ for (int i = 0; i < templateSeqs.size(); i++) {
+
+ string aligned = templateSeqs[i]->getAligned();
+ int pos = aligned.length();
+
+ //find first spot in this seq
+ for (int j = aligned.length()-1; j >= 0; j--) {
+ if (isalpha(aligned[j])) {
+ pos = j;
+ break;
+ }
+ }
+
+ //save this spot if it is the farthest
+ if (pos < rearPos) { rearPos = pos; }
+ }
+
+
+ //check to make sure that is not whole seq
+ if ((rearPos - frontPos - 1) <= 0) { mothurOut("Error, when I trim your sequences, the entire sequence is trimmed."); mothurOutEndLine(); exit(1); }
+
+ //***********trim all seqs to that position***************//
+ for (int i = 0; i < querySeqs.size(); i++) {
+
+ string aligned = querySeqs[i]->getAligned();
+
+ //between the two points
+ aligned = aligned.substr(frontPos, (rearPos-frontPos-1));
+
+ querySeqs[i]->setAligned(aligned);
+ }
+
+ for (int i = 0; i < templateSeqs.size(); i++) {
+
+ string aligned = templateSeqs[i]->getAligned();
+
+ //between the two points
+ aligned = aligned.substr(frontPos, (rearPos-frontPos-1));
+
+ templateSeqs[i]->setAligned(aligned);
+ }
+
+ }
+ catch(exception& e) {
+ errorOut(e, "Ccode", "trimSequences");
+ exit(1);
+ }
+
+}
+/***************************************************************************************************************/