5 * Created by Pat Schloss on 12/15/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
12 #include "sequence.hpp"
14 /***********************************************************************/
16 Sequence::Sequence() {}
18 /***********************************************************************/
20 Sequence::Sequence(string newName, string sequence) {
22 if(sequence.find_first_of('-') != string::npos) {
25 setUnaligned(sequence);
27 //********************************************************************************************************************
29 Sequence::Sequence(ifstream& fastaFile){
31 string accession; // provided a file handle to a fasta-formatted sequence file, read in the next
32 fastaFile >> accession; // accession number and sequence we find...
39 letter= fastaFile.get();
41 fastaFile.putback(letter);
44 else if(isprint(letter)){
45 letter = toupper(letter);
46 if(letter == 'U'){letter = 'T';}
52 if(sequence.find_first_of('-') != string::npos){ // if there are any gaps in the sequence, assume that it is
53 setAligned(sequence); // an alignment file
55 setUnaligned(sequence); // also set the unaligned sequence file
58 //********************************************************************************************************************
60 string Sequence::convert2ints() {
62 if(unaligned == "") { /* need to throw an error */ }
66 for(int i=0;i<unaligned.length();i++) {
67 if(toupper(unaligned[i]) == 'A') { processed += '0'; }
68 else if(toupper(unaligned[i]) == 'C') { processed += '1'; }
69 else if(toupper(unaligned[i]) == 'G') { processed += '2'; }
70 else if(toupper(unaligned[i]) == 'T') { processed += '3'; }
71 else if(toupper(unaligned[i]) == 'U') { processed += '3'; }
72 else { processed += '4'; }
77 //********************************************************************************************************************
79 void Sequence::setName(string seqName) {
80 if(seqName[0] == '>') { name = seqName.substr(1); }
81 else { name = seqName; }
84 //********************************************************************************************************************
86 void Sequence::setUnaligned(string sequence){
88 if(sequence.find_first_of('-') != string::npos) {
90 for(int j=0;j<sequence.length();j++) {
91 if(isalpha(sequence[j])) { temp += sequence[j]; }
101 //********************************************************************************************************************
103 void Sequence::setAligned(string sequence){
107 //********************************************************************************************************************
109 void Sequence::setPairwise(string sequence){
113 //********************************************************************************************************************
115 string Sequence::getName(){
119 //********************************************************************************************************************
121 string Sequence::getAligned(){
125 //********************************************************************************************************************
127 string Sequence::getPairwise(){
131 //********************************************************************************************************************
133 string Sequence::getUnaligned(){
137 //********************************************************************************************************************
139 int Sequence::getLength(){
140 if(unaligned.length() > aligned.length())
141 return unaligned.length();
142 return aligned.length();
145 //********************************************************************************************************************
147 void Sequence::printSequence(ostream& out){
148 string toPrint = unaligned;
149 if(aligned.length() > unaligned.length())
151 out << ">" << name << "\n" << toPrint << "\n";
154 //********************************************************************************************************************
156 int Sequence::getUnalignLength(){
157 return unaligned.length();
160 //********************************************************************************************************************
162 int Sequence::getAlignLength(){
163 return aligned.length();
166 //********************************************************************************************************************