header_counter++;
}
- header = file_data_line.substr(1);
+ if (header_counter > 0) {
+ header = file_data_line.substr(1);
- sequence_raw = "";
+ sequence_raw = "";
- while ( !data_file.eof() && read_seq )
- {
- getline(data_file,file_data_line);
- if (file_data_line.substr(0,1) == ">")
- read_seq = false;
- else sequence_raw += file_data_line;
- }
-
- data_file.close();
+ while ( !data_file.eof() && read_seq ) {
+ getline(data_file,file_data_line);
+ if (file_data_line.substr(0,1) == ">")
+ read_seq = false;
+ else sequence_raw += file_data_line;
+ }
- // Lastly, if subselection of the sequence was specified we keep cut out
- // and only keep that part
- // end_index = 0 means no end was specified, so cut to the end
- if (end_index == 0)
- end_index = sequence_raw.size();
+ // Lastly, if subselection of the sequence was specified we keep cut out
+ // and only keep that part
+ // end_index = 0 means no end was specified, so cut to the end
+ if (end_index == 0)
+ end_index = sequence_raw.size();
- // sequence filtering for upcasing agctn and convert non AGCTN to N
- set_filtered_sequence(sequence_raw, start_index, end_index-start_index);
+ // sequence filtering for upcasing agctn and convert non AGCTN to N
+ set_filtered_sequence(sequence_raw, start_index, end_index-start_index);
+ } else {
+ throw mussa_load_error("%s did not have a fasta header");
+ }
+ data_file.close();
}
}
"5' flank");
}
+// ticket:83 when you try to load a sequence from a file that doesn't
+// have fasta headers it crashes.
+BOOST_AUTO_TEST_CASE( sequence_past_end )
+{
+ fs::path seq_path(fs::path(EXAMPLE_DIR)/ "seq" );
+ seq_path /= "misformated_seq.fa";
+ Sequence s;
+ BOOST_CHECK_THROW( s.load_fasta(seq_path), mussa_load_error );
+}
+
BOOST_AUTO_TEST_CASE ( sequence_empty )
{
Sequence s;
--- /dev/null
+GGATCCTTCCTCCTTGGCCTCCCAAAGTGCTGGGATTACAGGTGTGAGCCACTGCACCTGGCCTATTACC
+CTTCTCAGGCTCTGGAGTCCATCCTTCTGCTCTGTCTCCCTCAGTTCAATTGTTTTTTGTTTTTTGTTTT
+TTTTTTAGACACAGTCTCGCTCTGTCACCAAGGCTGGAGTGCAGCAGTGCGATCACAGCTCACCGCAGCC
+TCACCTCCCAGGCTCAAGTGATCCTCCCATCTCGGCCTCTGAGTAGCTGAGACTATAGGTGTGTCCACAT
+GTCCGGCTAATTTTTGTATTTTTAGTAGAGACAGGGTTTCACCGCGTTGGCCAGGGTGGTCTTGAACTCC
+TGAGCTCAAGCAATCCTCCTGCCTCAGCCTCCTTGTTTTGATTTTTAGATCCCACAAATAACTTGTGATG