3
// Author : Guillaume Deuchst
5
// Last modification : Tuesday August 21 2003
9
Copyright or © or Copr. CNRS, (November 17, 2004)
11
This software is a computer program whose purpose is to provide classes
12
for sequences analysis.
14
This software is governed by the CeCILL license under French law and
15
abiding by the rules of distribution of free software. You can use,
16
modify and/ or redistribute the software under the terms of the CeCILL
17
license as circulated by CEA, CNRS and INRIA at the following URL
18
"http://www.cecill.info".
20
As a counterpart to the access to the source code and rights to copy,
21
modify and redistribute granted by the license, users are provided only
22
with a limited warranty and the software's author, the holder of the
23
economic rights, and the successive licensors have only limited
26
In this respect, the user's attention is drawn to the risks associated
27
with loading, using, modifying and/or developing or reproducing the
28
software by the user in light of its specific status of free software,
29
that may mean that it is complicated to manipulate, and that also
30
therefore means that it is reserved for developers and experienced
31
professionals having in-depth computer knowledge. Users are therefore
32
encouraged to load and test the software's suitability as regards their
33
requirements in conditions enabling the security of their systems and/or
34
data to be ensured and, more generally, to use and operate it in the
35
same conditions as regards security.
37
The fact that you are presently reading this means that you have had
38
knowledge of the CeCILL license and that you accept its terms.
42
#include "../StringSequenceTools.h"
47
/****************************************************************************************/
49
void Mase::appendFromStream(std::istream& input, SequenceContainer& vsc) const throw (Exception)
51
if (!input) { throw IOException ("Mase::read : fail to open file"); }
54
Comments seqComments, fileComments;
55
string temp, name, sequence = "";
56
bool comments = false;
58
// Get current general comments is VectorSequenceContainer
59
fileComments = vsc.getGeneralComments();
61
// Main loop : for all file lines
64
getline(input, temp, '\n'); // Copy current line in temporary string
66
// If first character is ;
69
// If second character is also ;
72
// File comments isolation
73
temp.erase(0,2); // Characters ;; deletion
74
if(temp != "") fileComments.push_back(temp);
78
// If a name and a sequence were founded
79
if ((name != "") && (sequence != ""))
81
// New sequence creation, and addition in existing VectorSequenceContainer
82
vsc.addSequence(BasicSequence(name, sequence, seqComments, vsc.getAlphabet()), checkNames_);
88
// Sequence commentaries isolation
89
temp.erase(temp.begin()); // Character ; deletion
90
if (temp != "") seqComments.push_back(temp);
96
// If sequence commentaries were just isolated
99
// Sequence name isolation
103
else sequence += temp; // Sequence isolation
107
// Addition of the last sequence in file
108
if ((name != "") && (sequence != ""))
110
vsc.addSequence(BasicSequence(name, sequence, seqComments, vsc.getAlphabet()), checkNames_);
113
// Set new general comments in VectorSequenceContainer (old + new comments)
114
vsc.setGeneralComments(fileComments);
117
/****************************************************************************************/
119
void Mase::write(ostream& output, const SequenceContainer& sc) const throw (Exception)
121
// Checking the existence of specified file, and possibility to open it in write mode
122
if (!output) { throw IOException ("Mase::write : failed to open file"); }
124
Comments comments = sc.getGeneralComments();
126
// Writing all general commentaries in file
127
for (unsigned int i = 0 ; i < comments.size() ; i++)
129
output << ";;" << comments[i] << endl;
132
string seq, temp = ""; // Initialization
134
// Main loop : for all sequences
135
vector<string> names = sc.getSequencesNames();
136
for (unsigned int i = 0 ; i < names.size() ; i ++)
138
comments = sc.getComments(names[i]);
140
// Writing all sequence comments in file
141
// If no comments are associated with current sequence, an empy commentary line will be writed
142
if (comments.size() == 0)
144
output << ";" << endl;
148
for (unsigned int j = 0 ; j < comments.size() ; j++)
150
output << ";" << comments[j] << endl;
154
// Sequence name writing
155
output << names[i] << endl;
157
// Sequence cutting to specified characters number per line
158
seq = sc.toString(names[i]);
161
if (seq.size() > charsByLine_)
164
temp.erase(temp.begin() + charsByLine_ , temp.end());
165
output << temp << endl;
166
seq.erase(seq.begin(), seq.begin() + charsByLine_);
170
output << seq << endl;
177
/****************************************************************************************/