Skip to content

Commit 890dcda

Browse files
James BarbettiJames Barbetti
James Barbetti
authored and
James Barbetti
committed
Suppressing some warnings and adding some explanatory comments
1. readFirstLineOfPhylipSequenceFile() hived off from Sequences::loadSequencesFromPhylip() (to avoid a warning from Lizard) 2. Deleted FakeMatrix's copy constructor (It's a local class, that is used only in SequenceLoader::writeDistanceMatrixToFile) 3. Added some missing initializations to UPGMA_Matrix's ctor.
1 parent 92d999b commit 890dcda

File tree

5 files changed

+65
-18
lines changed

5 files changed

+65
-18
lines changed

bionj.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,13 @@ public StartTree::BuilderInterface {
860860
//enclosing parentheses and a trailing semi-colon
861861
//is not supported.
862862
}
863+
863864
/**
864-
* @brief
865+
* @brief Given the path of a (possibly compressed) file that contains a
866+
* distance matrix in phylip format (square, upper or lower triangle),
867+
* and the path of an output file to write it to, infer a phylogenetic
868+
* tree, and write a representation of the tree (in Newick format) to
869+
* the output file.
865870
*
866871
* @param distanceMatrixFilePath - the path of the input phylip format file
867872
* @param newickTreeFilePath - the path to which the output newick format

distancematrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ template <class T=double> class Matrix
177177
* divisible by MATRIX_ALIGNMENT.
178178
*/
179179
void setDimensions(size_t r, size_t c) {
180-
clear();
180+
actual_clear();
181181
if (0==c || 0==r) {
182182
return;
183183
}

nj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ template <class T=NJFloat> class BIONJMatrix : public NJMatrix<T> {
542542
* using it with SUPER=UPGMAMatrix<T>!), because
543543
* that has a rather different getRowMinima().
544544
* There's a separate class for vectorizing that.
545+
* Nor can it vectorize FancyNJMatrix.
545546
*/
546547
template <class T=NJFloat, class SUPER=BIONJMatrix<T>,
547548
class V=FloatVector, class VB=FloatBoolVector>

sequence.cpp

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,52 @@ bool Sequences::loadSequencesFromFasta(const std::string& fastaFilePath,
405405
return true;
406406
}
407407

408+
/**
409+
* @brief Read the first line of a Phylip Alignment file (which is the number of sequences,
410+
* white space, and the length of all the sequences)
411+
*
412+
* @tparam S the stream type
413+
* @param in the stream itself
414+
* @param num_sequences reference - will have the number of sequences
415+
* in the alignment assigned to it (on success)
416+
* @param sequence_length reference - will have the length of the sequences
417+
* (every sequence must have the same length)
418+
* assigned to it (on success)
419+
* @return true on success
420+
* @return false on failure (an error message will have been written
421+
* to standard output).
422+
*
423+
* @note it is assumed that failbit is not already set on the stream when this
424+
* function is called.
425+
*/
426+
template <class S> bool readFirstLineOfPhylipAlignmentFile(S& in, size_t& num_sequences, size_t& sequence_length) {
427+
if (in.eof()) {
428+
std::cerr << "Sequence file was empty.";
429+
return false;
430+
}
431+
std::string line;
432+
safeGetLine(in, line);
433+
//Read the header line
434+
std::stringstream linestream(line);
435+
linestream >> num_sequences;
436+
if (in.fail()) {
437+
std::cerr << "Could not read number of sequences.";
438+
return false;
439+
}
440+
linestream >> sequence_length;
441+
if (in.fail()) {
442+
std::cerr << "Could not read sequence length.";
443+
return false;
444+
}
445+
if (num_sequences < 1 || sequence_length < 1 ) {
446+
std::cerr << "Number of sequences " << num_sequences
447+
<< " or Sequence length " << sequence_length
448+
<< " was invalid.";
449+
return false;
450+
}
451+
return true;
452+
}
453+
408454
/**
409455
* @brief Load a sequence alignment from a phylip format file
410456
* @param phylipFilePath - the path to the file
@@ -443,27 +489,19 @@ bool Sequences::loadSequencesFromPhylip(const std::string& phylipFilePath,
443489
}
444490
size_t num_sequences = 0;
445491
size_t sequence_length = 0;
492+
if (!readFirstLineOfPhylipAlignmentFile(in, num_sequences, sequence_length))
493+
{
494+
in.close();
495+
return false;
496+
}
497+
446498
bool have_read_names = 0;
447499
size_t name_length = 0; //Number of characters to use for sequence name
448500
size_t sequence_num = 0; //Ordinal sequence # to read next
449501

450502
for (; !in.eof(); ++line_num) {
451503
std::string line;
452504
safeGetLine(in, line);
453-
if (line_num == 1) {
454-
//Read the header line
455-
std::stringstream linestream(line);
456-
linestream >> num_sequences;
457-
linestream >> sequence_length;
458-
if (num_sequences < 1 || sequence_length < 1 ) {
459-
in.close();
460-
std::cerr << "Number of sequences " << num_sequences
461-
<< " or Sequence length " << sequence_length
462-
<< " was invalid.";
463-
return false;
464-
}
465-
continue;
466-
}
467505
if (line == "") {
468506
if (sequence_num!=0 && sequence_num!=num_sequences) {
469507
in.close();
@@ -817,7 +855,7 @@ SequenceLoader::SequenceLoader(char unknown, bool isDNA,
817855
, is_site_variant(site_variant)
818856
, report_progress(report_progress_while_loading), unkLen(0)
819857
, buffer(nullptr), sequence_data(nullptr)
820-
, unk_buffer(nullptr), unknown_data(nullptr) {
858+
, unk_buffer(nullptr), unknown_data(nullptr), num_states(4) {
821859
rank = sequences.size();
822860
rawSeqLen = sequences.front().sequenceLength();
823861
seqLen = 0;
@@ -982,6 +1020,7 @@ bool SequenceLoader::writeDistanceMatrixToFile(bool numbered_names,
9821020
progress_display& show_progress;
9831021
public:
9841022
typedef FlatMatrix super;
1023+
FakeMatrix(const FakeMatrix& rhs) = delete;
9851024
FakeMatrix(SequenceLoader& my_owner, progress_display& progress_bar)
9861025
: super(), owner(my_owner), show_progress(progress_bar) {}
9871026
virtual void setSize(intptr_t rows) { rowCount=rows;}

upgma.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ template <class T=NJFloat> class UPGMA_Matrix: public SquareMatrix<T> {
180180
bool subtreeOnly;
181181
public:
182182
UPGMA_Matrix(): super(), silent(false)
183-
, isOutputToBeZipped(false), isRooted(false)
183+
, isOutputToBeZipped(false)
184+
, isOutputToBeAppended(false)
185+
, isRooted(false)
184186
, subtreeOnly(false) {
185187
}
186188
/**

0 commit comments

Comments
 (0)