Commit 2cb2d703 authored by Mathieu Giraud's avatar Mathieu Giraud

core/fasta.{h,cpp}: adds (verbose=true) optional argument to some Fasta methods

parent 637bae63
...@@ -39,31 +39,34 @@ Fasta::Fasta(int extract_field, string extract_separator) ...@@ -39,31 +39,34 @@ Fasta::Fasta(int extract_field, string extract_separator)
} }
Fasta::Fasta(const string &input, Fasta::Fasta(const string &input,
int extract_field, string extract_separator) int extract_field, string extract_separator,
bool verbose)
{ {
init(extract_field, extract_separator); init(extract_field, extract_separator);
if (!input.size()) // Do not open empty filenames (D germline if not segmentD) if (!input.size()) // Do not open empty filenames (D germline if not segmentD)
return ; return ;
add(input); add(input, verbose);
} }
void Fasta::add(istream &in) { void Fasta::add(istream &in, bool verbose) {
in >> *this; in >> *this;
if (verbose)
cout << "\t" << setw(6) << total_size << " bp in " << setw(3) << size() << " sequences" << endl ; cout << "\t" << setw(6) << total_size << " bp in " << setw(3) << size() << " sequences" << endl ;
} }
void Fasta::add(const string &filename) { void Fasta::add(const string &filename, bool verbose) {
ifstream is(filename.c_str()); ifstream is(filename.c_str());
if (is.fail()) if (is.fail())
{ {
throw invalid_argument(" !! Error in opening file: "+ filename); throw invalid_argument(" !! Error in opening file: "+ filename);
} }
if (verbose)
cout << " <== " << filename ; cout << " <== " << filename ;
add(is); add(is, verbose);
is.close(); is.close();
} }
......
...@@ -47,7 +47,8 @@ public: ...@@ -47,7 +47,8 @@ public:
* valid * valid
*/ */
Fasta(const string &input, Fasta(const string &input,
int extract_field=0, string extract_separator="|"); int extract_field=0, string extract_separator="|",
bool verbose=true);
int size() const; int size() const;
/** /**
...@@ -63,13 +64,13 @@ public: ...@@ -63,13 +64,13 @@ public:
/** /**
* Add the content of the stream to the current object * Add the content of the stream to the current object
*/ */
void add(istream &in); void add(istream &in, bool verbose=true);
/** /**
* Add the content of the file to the current object * Add the content of the file to the current object
* @throws invalid_argument if the file cannot be opened or * @throws invalid_argument if the file cannot be opened or
* if the content is not valid * if the content is not valid
*/ */
void add(const string &filename); void add(const string &filename, bool verbose=true);
friend istream& operator>>(istream&, Fasta&); friend istream& operator>>(istream&, Fasta&);
}; };
......
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