return the_seqs;
}
-string
+void
Mussa::load_mupa_file(string para_file_path)
{
ifstream para_file;
bool parsing_path;
string::size_type new_index, dir_index;
-
// initialize values
clear();
cout << "nway mupa: analysis_name = " << analysis_name
<< " window = " << window
<< " threshold = " << threshold << endl;
-
- return "";
}
-
// no file was loaded, signal error
else
{
- err_msg = "Config File: " + para_file_path + " not found";
- return err_msg;
+ throw mussa_load_error("Config File: " + para_file_path + " not found");
}
}
}
t1 = time(NULL);
- try {
- load_sequence_data();
- } catch(sequence_load_error e) {
- cerr << "Unable to load sequence" << endl;
- cerr << e.what() << endl;
- }
+ load_sequence_data();
if (the_seqs.size() < 2) {
throw mussa_analysis_error("you need to have at least 2 sequences to "
the_paths.save(save_path);
}
-string
+void
Mussa::load(string ana_file)
{
int i, i2;
parsing_path = true;
end_index = ana_path.size()-1;
if (ana_path[end_index] == '/') {
- cout << "found trailing /" << endl;
--end_index;
}
start_index = ana_path.rfind('/', end_index);
}
analysis_name = ana_path.substr(start_index, end_index-start_index+1);
cout << " ana_name " << analysis_name << endl;
- file_path_base = ana_path.substr(0, start_index) + analysis_name +"/" + analysis_name;
+ file_path_base = ana_path.substr(0, start_index) + analysis_name
+ + "/" + analysis_name;
a_file_path = file_path_base + ".muway";
cout << " loading museq: " << a_file_path << endl;
- err_msg = the_paths.load(a_file_path);
-
- if (err_msg == "")
- {
- int seq_num = the_paths.sequence_count();
+ the_paths.load(a_file_path);
- cout << "No BAM " << seq_num << endl; ;
+ int seq_num = the_paths.sequence_count();
- a_file_path = file_path_base + ".museq";
+ a_file_path = file_path_base + ".museq";
- // this is a bit of a hack due to C++ not acting like it should with files
- for (i = 1; i <= seq_num; i++)
- {
- tmp_seq.clear();
- cout << "mussa_class: loading museq frag... " << a_file_path << endl;
- tmp_seq.load_museq(a_file_path, i);
- the_seqs.push_back(tmp_seq);
- }
-
- empty_FLP_vector.clear();
- for(i = 0; i < seq_num; i++)
- {
- all_comps.push_back(empty_FLP_vector);
- for(i2 = 0; i2 < seq_num; i2++)
- all_comps[i].push_back(dummy_comp);
- }
-
- for(i = 0; i < seq_num; i++)
+ // this is a bit of a hack due to C++ not acting like it should with files
+ for (i = 1; i <= seq_num; i++)
+ {
+ tmp_seq.clear();
+ cout << "mussa_class: loading museq frag... " << a_file_path << endl;
+ tmp_seq.load_museq(a_file_path, i);
+ the_seqs.push_back(tmp_seq);
+ }
+
+ empty_FLP_vector.clear();
+ for(i = 0; i < seq_num; i++)
+ {
+ all_comps.push_back(empty_FLP_vector);
+ for(i2 = 0; i2 < seq_num; i2++)
+ all_comps[i].push_back(dummy_comp);
+ }
+
+ for(i = 0; i < seq_num; i++)
+ {
+ for(i2 = i+1; i2 < seq_num; i2++)
{
- for(i2 = i+1; i2 < seq_num; i2++)
- {
- append_info.str("");
- append_info << "_sp_" << i << "v" << i2;
- cout << append_info.str() << endl;
- a_file_path = file_path_base + append_info.str() + ".flp";
- all_comps[i][i2].load(a_file_path);
- cout << "real size = " << all_comps[i][i2].size() << endl;
- }
+ append_info.str("");
+ append_info << "_sp_" << i << "v" << i2;
+ cout << append_info.str() << endl;
+ a_file_path = file_path_base + append_info.str() + ".flp";
+ all_comps[i][i2].load(a_file_path);
+ cout << "real size = " << all_comps[i][i2].size() << endl;
}
- return "";
}
- else
- return err_msg;
}
-/*
- cout << "fee\n";
- cout << "fie\n";
- cout << "foe\n";
- cout << "fum\n";
-*/
-
-
void
Mussa::save_old()
void save();
void save_muway(std::string save_path);
- std::string load(std::string ana_file);
+ //! load a saved analysis directory
+ void load(std::string ana_path);
//! clear parameters and initialize data lists
void clear();
// set parameters from a file - 'mupa' ~ mussa parameters
- std::string load_mupa_file(std::string para_file_path);
+ void load_mupa_file(std::string para_file_path);
// set parameters individually (eg from user input into gui classes)
//! set analysis name
#include "alg/nway_paths.hh"
#include "alg/conserved_path.h"
+#include "mussa_exceptions.hh"
#include <fstream>
#include <iostream>
{
fstream save_file;
list<ExtendedConservedPath >::iterator path_i, paths_end;
- unsigned int i;
save_file.open(save_file_path.c_str(), ios::out);
//cout << a_path.size() << endl;
//first entry is the window length of the windows in the path
save_file << a_path.window_size << ":";
- for(i = 0; i != sequence_count(); ++i)
+ for(size_t i = 0; i != sequence_count(); ++i)
{
save_file << a_path[i];
if (i != sequence_count())
}
-int
+size_t
NwayPaths::sequence_count()
{
if (refined_pathz.begin() == refined_pathz.end() )
}
-string
+void
NwayPaths::load(string load_file_path)
{
fstream load_file;
string file_data_line, header_data, data, path_node, path_width;
- int i, space_split_i, equal_split_i, comma_split_i, colon_split_i;
+ int space_split_i, equal_split_i, comma_split_i, colon_split_i;
vector<int> loaded_path;
- string err_msg;
load_file.open(load_file_path.c_str(), ios::in);
if (!load_file)
{
- err_msg = "Sequence File: " + load_file_path + " not found";
- cout << "BAM!!!!\n";
- return err_msg;
+ throw mussa_load_error("Sequence File: " + load_file_path + " not found");
}
else
{
// whats our window size?
path_width = file_data_line.substr(0,colon_split_i);
file_data_line = file_data_line.substr(colon_split_i+1);
- for(i = 0; i < species_num; i++)
+ for(size_t i = 0; i < species_num; i++)
{
comma_split_i = file_data_line.find(",");
path_node = file_data_line.substr(0, comma_split_i);
getline(load_file,file_data_line);
}
load_file.close();
-
- return "";
}
}
void simple_refine();
void save(std::string save_file_path);
- std::string load(std::string load_file_path);
+ //! load a muway file, \throws mussa_load_error
+ void load(std::string load_file_path);
void add_path(int threshold, std::vector<int>& loaded_path);
void add_path(ConservedPath loaded_path);
//! how many sequences are in our comparison
- int sequence_count();
+ size_t sequence_count();
void find_paths(std::vector<std::vector<FLPs> > all_comparisons);
void refine();
// running trumps viewing.
if (vm.count("run-analysis")) {
m->load_mupa_file( vm["run-analysis"].as< std::string >() );
+ std::cout << "I apologize for blocking the gui while running the analysis"
+ << std::endl;
+ m->analyze();
}
else if (vm.count("view-analysis")) {
m->load( vm["view-analysis"].as< std::string >() );
if (!data_file)
{
- throw sequence_load_error("Sequence File: " + file_path + " not found");
+ throw mussa_load_error("Sequence File: " + file_path + " not found");
}
// if file opened okay, read it
else
if (!data_file)
{
- throw sequence_load_error("Sequence File: " + file_path + " not found");
+ throw mussa_load_error("Sequence File: " + file_path + " not found");
}
// if file opened okay, read it
else
//! assignment to constant sequences
//Sequence &operator=(const Sequence&);
//! load sequence AGCT from fasta file
- //! throws sequence_load_error if something goes wrong
+ //! throws mussa_load_error if something goes wrong
void load_fasta(const std::string file_path, int seq_num=1,
int start_index=0, int end_index=0);
//! load sequence annotations
- //! throws sequence_load_error if something goes wrong
+ //! throws mussa_load_error if something goes wrong
void load_annot(const std::string file_path, int start_index, int end_index);
const std::list<annot> annotations() const;
void set_seq(const std::string& a_seq);
{
Sequence s;
// there should be errors when we try to load something that doesn't exist
- BOOST_CHECK_THROW( s.load_fasta("alkejralk", 1, 0, 0), sequence_load_error);
- BOOST_CHECK_THROW( s.load_annot("alkejralk", 0, 0), sequence_load_error);
+ BOOST_CHECK_THROW( s.load_fasta("alkejralk", 1, 0, 0), mussa_load_error);
+ BOOST_CHECK_THROW( s.load_annot("alkejralk", 0, 0), mussa_load_error);
}
//! Do simple operations work correctly?
// load the analysis
an_analysis = new Mussa();
- err_msg = an_analysis->load(a_file_path);
+ try {
+ an_analysis->load(a_file_path);
+ } catch (mussa_load_error e) {
+ fl_alert(e.what());
+ return;
+ }
//.substr(0,a_file_path.find(".mu")));
- if (err_msg == "")
- {
- // relabel window with the analysis name
- window_name = "Mussa: " + an_analysis->get_name();
- label((const char*)window_name.c_str());
- // show the user the analysis
- conn_box->setup(an_analysis->get_name(), an_analysis->size(),
- an_analysis->get_window(), &(an_analysis->the_seqs),
- &(an_analysis->the_paths));
- conn_box->scale_paths();
- }
- else
- {
- fl_alert(err_msg.c_str());
- cout << err_msg << endl;
- }
+ // relabel window with the analysis name
+ window_name = "Mussa: " + an_analysis->get_name();
+ label((const char*)window_name.c_str());
+ // show the user the analysis
+ conn_box->setup(an_analysis->get_name(), an_analysis->size(),
+ an_analysis->get_window(), &(an_analysis->the_seqs),
+ &(an_analysis->the_paths));
+ conn_box->scale_paths();
}
}
a_file_path = picked_file;
an_analysis = new Mussa();
- err_msg = an_analysis->load_mupa_file(a_file_path);
+ try {
+ an_analysis->load_mupa_file(a_file_path);
+ } catch (mussa_load_error e) {
+ fl_alert(e.what());
+ return;
+ }
try {
an_analysis->analyze(0, 0, Mussa::TransitiveNway, 0.0);
{
if ((run_mode == 'f') || (run_mode == 'n'))
{
- err_msg = an_analysis.load_mupa_file(a_file_path);
+ an_analysis.load_mupa_file(a_file_path);
an_analysis.analyze(window, threshold, ana_mode, ent_thres);
//an_overlord.do_analysis();
}
if (run_mode == 'v')
- err_msg = an_analysis.load(a_file_path);
+ an_analysis.load(a_file_path);
//an_overlord.get_analysis();
// no longer needed, but still semi-useful reality check...
explicit cmdline_error(const std::string& msg): std::runtime_error(msg) {};
};
-//! Error loading sequence information
-class sequence_load_error : public std::runtime_error
+//! Error loading information
+class mussa_load_error : public std::runtime_error
{
public:
- explicit sequence_load_error(const std::string& msg) :
+ explicit mussa_load_error(const std::string& msg) :
std::runtime_error(msg) {};
};
#include <QDir>
#include <QFileDialog>
+#include <QMessageBox>
#include <QMouseEvent>
#include <QRubberBand>
#include <QRect>
else
{
mussaAnalysis = analysis;
- updateAnalysis();
}
+ updateScene();
}
QSize PathScene::sizeHint() const
caption,
QDir::currentPath(),
filter);
- mussaAnalysis->load_mupa_file(mupa_path.toStdString());
- updateAnalysis();
+ // user hit cancel?
+ if (mupa_path.isNull())
+ return;
+ // try to load safely
+ try {
+ Mussa *m = new Mussa;
+ m->load_mupa_file(mupa_path.toStdString());
+ m->analyze(0, 0, Mussa::TransitiveNway, 0.0);
+ // only switch mussas if we loaded without error
+ delete mussaAnalysis;
+ mussaAnalysis = m;
+ updateScene();
+ } catch (mussa_load_error e) {
+ QString msg("Unable to load ");
+ msg += mupa_path;
+ msg += "\n";
+ msg += e.what();
+ QMessageBox::warning(this, "Load Parameter", msg);
+ }
+ assert (mussaAnalysis != 0);
}
void PathScene::loadSavedAnalysis()
{
QString caption("Load a previously run analysis");
- QString muway_path = QFileDialog::getExistingDirectory(this,
- caption,
- QDir::currentPath());
- mussaAnalysis->load(muway_path.toStdString());
- updateAnalysis();
+ QString muway_dir = QFileDialog::getExistingDirectory(this,
+ caption,
+ QDir::currentPath());
+ // user hit cancel?
+ if (muway_dir.isNull())
+ return;
+ // try to safely load
+ try {
+ Mussa *m = new Mussa;
+ m->load(muway_dir.toStdString());
+ // only switch mussas if we loaded without error
+ delete mussaAnalysis;
+ mussaAnalysis = m;
+ updateScene();
+ } catch (mussa_load_error e) {
+ QString msg("Unable to load ");
+ msg += muway_dir;
+ msg += "\n";
+ msg += e.what();
+ QMessageBox::warning(this, "Load Parameter", msg);
+ }
+ assert (mussaAnalysis != 0);
}
void PathScene::setSoftThreshold(int threshold)
glFlush();
}
-void PathScene::updateAnalysis()
+void PathScene::updateScene()
{
// Delete old glsequences
// FIXME: does this actually free the memory from the new'ed GlSequences?
tracks.clear();
- // Run analysis
- cout << "updateA:" << mussaAnalysis->size() //<< mussaAnalysis->paths().size()
- << endl;
- if (mussaAnalysis->size() >= 2)
+ // save a reference to our GlSequences
+ GlSequence *gl_seq;
+ float y = mussaAnalysis->sequences().size() * 100 ;
+ float max_base_pairs = 0;
+ typedef vector<Sequence>::const_iterator seqs_itor_t;
+ for(seqs_itor_t seq_itor = mussaAnalysis->sequences().begin();
+ seq_itor != mussaAnalysis->sequences().end();
+ ++seq_itor)
{
- mussaAnalysis->analyze(0, 0, Mussa::TransitiveNway, 0.0);
-
- // save a reference to our GlSequences
- GlSequence *gl_seq;
- float y = mussaAnalysis->sequences().size() * 100 ;
- float max_base_pairs = 0;
- typedef vector<Sequence>::const_iterator seqs_itor_t;
- for(seqs_itor_t seq_itor = mussaAnalysis->sequences().begin();
- seq_itor != mussaAnalysis->sequences().end();
- ++seq_itor)
- {
- y = y - 100;
- gl_seq = new GlSequence(*seq_itor);
- gl_seq->setX(0);
- gl_seq->setY(y);
- if (gl_seq->width() > max_base_pairs ) max_base_pairs = gl_seq->width();
- tracks.push_back( *gl_seq );
- }
- maxOrtho2d.setWidth(max_base_pairs + 100.0);
- maxOrtho2d.setHeight((mussaAnalysis->sequences().size()) * 100 );
- curOrtho2d = maxOrtho2d;
+ y = y - 100;
+ gl_seq = new GlSequence(*seq_itor);
+ gl_seq->setX(0);
+ gl_seq->setY(y);
+ if (gl_seq->width() > max_base_pairs ) max_base_pairs = gl_seq->width();
+ tracks.push_back( *gl_seq );
}
+ maxOrtho2d.setWidth(max_base_pairs + 100.0);
+ maxOrtho2d.setHeight((mussaAnalysis->sequences().size()) * 100 );
+ curOrtho2d = maxOrtho2d;
}
static void processHits(GLint hits, GLuint buffer[])
void loadSavedAnalysis();
//! set the soft threshold used by the Nway_Path algorithm
void setSoftThreshold(int thres);
- //! called when we've changed the analysis
- void updateAnalysis();
+ //! indicate that we should update our scene
+ void updateScene();
signals:
//! emitted when our analysis has changed