get_common_consensus.cpp
#include<iostream>
#include<iterator>
#include<sstream>
#include<vector>
#include<fstream>
const uint32_t MAX_SIZE = 100000;
bool check_if_equal(char** n, int n_size, std::ifstream *f){
if(*n[0] == '\n' || *n[0] == '\0' || *n[0]==EOF || f[0].eof())
return false;
for(int i = 1; i < n_size;i++){
if(*n[i] != *n[0] || *n[i] == '\0' || *n[i] == '\n' || *n[0]==EOF || f[i].eof())
return false;
}
return true;
}
int compare_consensus(char** f, int n_string, std::string out){
std::ifstream *cns = new std::ifstream[n_string];
std::ofstream o(out+".fa");
o << ">Common_Consensus" << std::endl;
int i, j;
char** l = new char*[n_string];
for(i = 0; i < n_string;i++){
std::cout << f[i+1] << std::endl;
l[i] = new char;
cns[i].open(f[i + 1]);
cns[i].read(l[i], 1);
if(*l[i]!='>'){
std::cout << "Error " << f[i] << " is not a fasta file." << std::endl;
return 0;
}
while(*l[i] !='\n'){
cns[i].read(l[i], 1);
}
cns[i].read(l[i], 1); // Read next character after \n
}
// Get to beginning of matching substring
while(!check_if_equal(l, n_string, cns)){
for(j = 0; j<n_string;j++){
cns[j].read(l[j], 1);
}
}
for(j = 0; j < n_string; j++)
if(*l[j] == EOF){
std::cout << "Warning: No common regions between consensus sequences" << std::endl;
return 0;
}
while(check_if_equal(l, n_string, cns)){
o << *l[0];
for(j = 0; j<n_string;j++){
cns[j].read(l[j], 1);
}
}
for(i = 0; i < n_string; i++){
cns[i].close();
}
o.close();
delete[] cns;
delete[] l;
return 0;
}
int main(int argv, char** argc){
compare_consensus(argc, argv - 1, "test");
}
main
int main(int argc, char *argv[])
Definition: ivar.cpp:144