ticket:151
seqcomp gets really grumpy when it trys to analyze a sequence that
is shorter than the window sequence. So instead of letting it try
to malloc all of your memory, throw a more useful exception.
Also I updated the SubanalysisWindow to catch the exception and
report it to the user.
+ typedef size_t size_type;
+
FLPs();
FLPs(const FLPs& );
//! Setup a FLP and reserve space for the match lists
FLPs();
FLPs(const FLPs& );
//! Setup a FLP and reserve space for the match lists
/*! this is mostly so seqcomp can use operator[]
*/
void alloc_matches(std::string::size_type len1=0);
/*! this is mostly so seqcomp can use operator[]
*/
void alloc_matches(std::string::size_type len1=0);
+
+ //! make sure that a sequence is acceptable to seqcomp
+ void validate_sequence(const Sequence&) const;
+
//! current loop index
int seqcomp_i;
//! end seqcomp index (when terminating, seqcomp_i == seqcomp_end.
//! current loop index
int seqcomp_i;
//! end seqcomp index (when terminating, seqcomp_i == seqcomp_end.
+void FLPs::validate_sequence(const Sequence& seq) const
+{
+ if (seq.size() < window_size) {
+ ostringstream msg;
+ msg << "Sequence " << seq.get_name() << " of length " << seq.size()
+ << " must be longer than window size " << window_size;
+ throw seqcomp_error(msg.str());
+ }
+}
void
FLPs::seqcomp(const Sequence& sseq1, const Sequence& sseq2, bool is_RC)
void
FLPs::seqcomp(const Sequence& sseq1, const Sequence& sseq2, bool is_RC)
const char *seq1 = sseq1.c_str();
const char *seq2 = sseq2.c_str();
const char *seq1 = sseq1.c_str();
const char *seq2 = sseq2.c_str();
- int seq1_win_num = sseq1.size() - window_size + 1;
- int seq2_win_num = sseq2.size() - window_size + 1;
+ validate_sequence(sseq1);
+ validate_sequence(sseq2);
+
+ size_type seq1_win_num = sseq1.size() - window_size + 1;
+ size_type seq2_win_num = sseq2.size() - window_size + 1;
alloc_matches(sseq1.size());
if (seq1_win_num != size()) {
ostringstream msg;
alloc_matches(sseq1.size());
if (seq1_win_num != size()) {
ostringstream msg;
throw mussa_analysis_error("you need to have at least 2 sequences to "
"do an analysis.");
}
throw mussa_analysis_error("you need to have at least 2 sequences to "
"do an analysis.");
}
- //cout << "nway ana: seq_num = " << the_seqs.size() << endl;
-
seqcomp();
the_paths.setup(window, threshold);
nway();
seqcomp();
the_paths.setup(window, threshold);
nway();
#include "alg/sequence_location.hpp"
#include "alg/sequence_location.hpp"
SequenceLocation::SequenceLocation(
const boost::shared_ptr<Sequence> s,
SequenceLocation::SequenceLocation(
const boost::shared_ptr<Sequence> s,
int SequenceLocation::getCount() const
{
int SequenceLocation::getCount() const
{
+ return std::max(right - left, 0);
}
void SequenceLocation::setRight(int r)
}
void SequenceLocation::setRight(int r)
+BOOST_AUTO_TEST_CASE( mussa_window_larger_than_sequence )
+{
+ string s0("AGCAGGG");
+ string s1("CAGCGGG");
+
+ Mussa analysis;
+ analysis.append_sequence(s0);
+ analysis.append_sequence(s1);
+ analysis.set_threshold(23);
+ analysis.set_window(30);
+ BOOST_CHECK_THROW(analysis.analyze(), seqcomp_error);
+}
+
BOOST_AUTO_TEST_CASE( subanalysis )
{
Sequence s1("AATGAAGATTTTAATGCTTTAATTTTGTTTTGTAAACTTCGAATTTCCAAAATTTGAAA");
BOOST_AUTO_TEST_CASE( subanalysis )
{
Sequence s1("AATGAAGATTTTAATGCTTTAATTTTGTTTTGTAAACTTCGAATTTCCAAAATTTGAAA");
+//! failure running seqcomp
+class seqcomp_error : public mussa_analysis_error
+{
+public:
+ explicit seqcomp_error(const std::string& msg) :
+ mussa_analysis_error(msg) {};
+};
+
//! couldn't normalize a motif
/*
class motif_normalize_error : public mussa_error
//! couldn't normalize a motif
/*
class motif_normalize_error : public mussa_error
#include "mussa_exceptions.hpp"
#include "alg/mussa.hpp"
#include "mussa_exceptions.hpp"
#include "alg/mussa.hpp"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
m->append_sequence(itor->getSelectedSequence());
}
m->append_sequence(itor->getSelectedSequence());
}
- m->set_window(window->value());
- m->set_threshold(threshold->value());
- m->analyze();
- MussaWindow *mw = new MussaWindow(m);
- mw->show();
- model.clear();
- hide();
+ try {
+ m->set_window(window->value());
+ m->set_threshold(threshold->value());
+ m->analyze();
+ MussaWindow *mw = new MussaWindow(m);
+ mw->show();
+ model.clear();
+ hide();
+ } catch(mussa_error e) {
+ QMessageBox::critical(this,
+ "Mussa Subanalysis Error",
+ QString(e.what()),
+ QMessageBox::Ok, 0, 0);
+ }
}
void SubanalysisWindow::modelUpdated(const QModelIndex&, int, int )
}
void SubanalysisWindow::modelUpdated(const QModelIndex&, int, int )