Commit f1179c96 authored by Mathieu Giraud's avatar Mathieu Giraud

core/lazy_msa.cpp: refactor code, no change

Factor a code that what called 4 times.
parent eb73d5bb
Pipeline #39793 passed with stages
in 41 minutes and 24 seconds
......@@ -6,6 +6,28 @@
using namespace std;
string format_seq_align(string seq, unsigned int n, int *gaps)
{
ostringstream stream;
for (unsigned int i=0; i<n; i++){
for (int j=0; j<gaps[i] ; j++){
stream << "-";
}
stream << seq[i];
}
// gaps after the last position
for (int j=0; j<gaps[n] ; j++){
stream << "-";
}
return stream.str();
}
LazyMsa::LazyMsa(int max, string reference)
{
sizeMax=max;
......@@ -59,35 +81,8 @@ void LazyMsa::add(string sequence){
}
void LazyMsa::alignOne(string *align, int one){
ostringstream stream;
for (unsigned int i=0; i<ref.size(); i++){
for (int j=0; j<gapRef[one][i] ; j++){
stream <<"-";
}
stream<<ref[i];
}
for (int j=0; j<gapRef[one][ref.size()] ; j++){
stream <<"-";
}
align[0]=stream.str();
ostringstream stream2;
for (unsigned int i=0; i<sequences[one].size(); i++){
for (int j=0; j<gapSeq[one][i] ; j++){
stream2 <<"-";
}
stream2<<sequences[one][i];
}
for (int j=0; j<gapSeq[one][sequences[one].size()] ; j++){
stream2 <<"-";
}
align[1]=stream2.str();
align[0] = format_seq_align(ref, ref.size(), gapRef[one]);
align[1] = format_seq_align(sequences[one], sequences[one].size(), gapSeq[one]);
}
void LazyMsa::align(string *align){
......@@ -105,25 +100,11 @@ void LazyMsa::align(string *align){
}
}
// Build the output
ostringstream stream;
// Reference sequence
for (unsigned int i=0; i<ref.size(); i++){
for (int j=0; j<maxGap[i] ; j++){
stream <<"-";
}
stream<<ref[i];
}
for (int j=0; j<maxGap[ref.size()] ; j++){
stream <<"-";
}
align[0]=stream.str();
align[0] = format_seq_align(ref, ref.size(), maxGap);
// Other sequences
for (int i=0; i<sizeUsed+1; i++){
ostringstream stream2;
// Update gapSeq
for (unsigned int j = 0; j< ref.size()+1; j++){
......@@ -131,17 +112,7 @@ void LazyMsa::align(string *align){
}
// Build output
for (unsigned int j=0; j<sequences[i].size(); j++){
for (int k=0; k<gapSeq[i][j] ; k++){
stream2 <<"-";
}
stream2<<sequences[i][j];
}
for (int k=0; k<gapSeq[i][sequences[i].size()] ; k++){
stream2 <<"-";
}
align[i+1]=stream2.str();
align[i+1] = format_seq_align(sequences[i], sequences[i].size(), gapSeq[i]);
}
delete [] maxGap;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment