Mussagl now as several ways to load an analysis.
There are now two command-line arguments, run-analysis and view-analysis
which will load a parameter file and an analysis directory respectively.
The menu items in mussagl are also connected to slots in PathScene to
handle loading.
When something is loaded PathScene::updateAnalysis will (if the
analysis actually has some contents) run the analysis.
However there's some bug where the loading the previously saved analysis
is choaking on some assertion.
int
Mussa::size() const
{
- return the_seqs.size();
+ if (the_seqs.size() > 0)
+ return the_seqs.size();
+ else if (seq_files.size() > 0)
+ return seq_files.size();
+ else
+ return 0;
}
void
bool seq_params, did_seq;
string err_msg;
bool parsing_path;
- int new_index, dir_index;
+ string::size_type new_index, dir_index;
// initialize values
while (parsing_path)
{
new_index = (para_file_path.substr(dir_index)).find("/");
- //cout << "mu class: "<< new_index << endl;
- if (new_index > 0)
- dir_index += new_index + 1;
+ if (new_index != string::npos)
+ dir_index += new_index + 1;
else
- parsing_path = false;
+ parsing_path = false;
}
file_path_base = para_file_path.substr(0,dir_index);
- cout << "mu class: mupa base path = " << file_path_base << endl;
// setup loop by getting file's first line
getline(para_file,file_data_line);
else if (param == "SEQUENCE")
{
seq_files.push_back(file_path_base + value);
+ cout << "seq_file_name " << seq_files.back() << endl;
fasta_index = 1;
annot_file = "";
sub_seq_start = 0;
string
Mussa::load(string ana_file)
{
- int i, i2, new_index, dir_index;
+ int i, i2;
+ string::size_type start_index, end_index;
string file_path_base, a_file_path, ana_path;
bool parsing_path;
Sequence tmp_seq;
vector<FLPs> empty_FLP_vector;
FLPs dummy_comp;
+ cout << "ana_file name " << ana_file << endl;
ana_path = ana_file;
parsing_path = true;
- dir_index = 0;
- while (parsing_path)
- {
- new_index = (ana_path.substr(dir_index)).find("/");
- //cout << "mu class: "<< new_index << endl;
- if (new_index > 0)
- dir_index += new_index + 1;
- else
- parsing_path = false;
+ end_index = ana_path.size()-1;
+ if (ana_path[end_index] == '/') {
+ cout << "found trailing /" << endl;
+ --end_index;
}
-
- analysis_name = ana_path.substr(dir_index);
- cout << "mu class: analysis_name = " << analysis_name << endl;
- file_path_base = ana_path + "/" + ana_path.substr(dir_index);
+ start_index = ana_path.rfind('/', end_index);
+ if (start_index == string::npos) {
+ // no / to be found
+ start_index = 0;
+ } else {
+ // skip the / we found
+ ++start_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;
a_file_path = file_path_base + ".muway";
+ cout << " loading museq: " << a_file_path << endl;
err_msg = the_paths.load(a_file_path);
- cout << "there is no safe distance\n";
if (err_msg == "")
{
for (i = 1; i <= seq_num; i++)
{
tmp_seq.clear();
- cout << "mussa_class: loading museq frag...\n";
+ cout << "mussa_class: loading museq frag... " << a_file_path << endl;
tmp_seq.load_museq(a_file_path, i);
the_seqs.push_back(tmp_seq);
}
std::string get_name();
//! return number of sequences in this analyzis
+ /*! this returns either the_seqs.size() or seq_files.size()
+ * depending on which has data loaded in
+ * (silly delayed loading of sequence data)
+ */
int size() const;
//! set number of bases for this window size
void set_window(int a_window);
getline(load_file,file_data_line);
while ( (!load_file.eof()) && (file_data_line != "</Mussa>") )
{
- cout << "fdl: " << file_data_line << endl;
if (file_data_line != "")
{
loaded_path.clear();
--- /dev/null
+#include <boost/program_options.hpp>
+namespace po = boost::program_options;
+
+#include <string>
+#include <iostream>
+
+#include "alg/mussa_class.hh"
+#include "alg/parse_options.h"
+
+Mussa *initialize_mussa(int argc, char **argv)
+{
+ po::options_description options("Mussa options");
+ po::positional_options_description pos_options;
+ pos_options.add("run-analysis", -1);
+
+ options.add_options()
+ ("help", "help message")
+ ("run-analysis,p", po::value<std::string>(),
+ "run an analysis defined by the mussa parameter file")
+ ("view-analysis", po::value<std::string>(),
+ "load a previously run analysis")
+ ;
+
+ po::variables_map vm;
+ po::store(po::command_line_parser(argc, argv).options(options).positional(pos_options).run(), vm);
+ po::notify(vm);
+
+ if (vm.count("help")) {
+ std::cout << options << std::endl;
+ return 0;
+ }
+
+ Mussa *m = new Mussa();
+ // currently we can only have one analysis loaded, so
+ // running trumps viewing.
+ if (vm.count("run-analysis")) {
+ m->load_mupa_file( vm["run-analysis"].as< std::string >() );
+ }
+ else if (vm.count("view-analysis")) {
+ m->load( vm["view-analysis"].as< std::string >() );
+ }
+ return m;
+}
+
--- /dev/null
+#ifndef _PARSE_OPTIONS_H_
+#define _PARSE_OPTIONS_H_
+
+class Mussa;
+
+//! initialize a mussa analysis from command line arguments
+Mussa *initialize_mussa(int argc, char** argv);
+#endif
+
BOOST_CHECK_EQUAL( m2.get_name(), saved_analysis_path );
BOOST_CHECK_EQUAL( m1.size(), m2.size() );
+
+}
+
+BOOST_AUTO_TEST_CASE( mussa_load_full_path )
+{
+ Mussa m1;
+ chdir( "examples" );
+ const int bufsize = 1024;
+ char path_buf[bufsize];
+ getcwd(path_buf, bufsize);
+ std::string path(path_buf);
+ chdir( ".." );
+ path += "/mck3test.mupa";
+ m1.load_mupa_file( path );
+ m1.analyze(0, 0);
+
+ BOOST_CHECK( m1.size() > 0);
}
#include <QApplication>
#include "qui/PathWindow.h"
+#include "alg/parse_options.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
+ Mussa *analysis = initialize_mussa(argc, argv);
- PathWindow win;
+ if (analysis == 0) {
+ return 1;
+ }
+
+ PathWindow win(analysis);
win.show();
app.exec();
}
alg/flp.hh \
alg/mussa_class.hh \
alg/nway_paths.hh \
+ alg/parse_options.h \
alg/sequence.hh
SOURCES += mussagl.cxx \
qui/GlSequence.cxx \
alg/nway_entropy.cxx \
alg/nway_other.cxx \
alg/nway_paths.cxx \
+ alg/parse_options.cxx \
# alg/nway_refine.cxx \
alg/sequence.cxx
# test/test_flp.cxx \
# test/test_nway.cxx \
# test/test_sequence.cxx
-LIBS += -lm
+LIBS += -lm -lboost_program_options
QT += opengl
#include "PathScene.h"
+#include <QDir>
+#include <QFileDialog>
#include <QMouseEvent>
#include <QRubberBand>
#include <QRect>
+#include <QString>
#include <iostream>
#include <GL/gl.h>
using namespace std;
-PathScene::PathScene(int frags, int len, QWidget *parent) :
+PathScene::PathScene(Mussa* analysis, QWidget *parent) :
QGLWidget(parent),
X(0),
clipZ(30.0),
zoom(0),
maxOrtho2d(-50.0, -50, 3000000.0, 300.0),
curOrtho2d(maxOrtho2d),
- fragsize(frags),
- length(len),
rubberBand(0),
debugBand(true),
drawingBand(false)
{
- // Hack in loading an analysis
- mussaAnalysis.load_mupa_file( "examples/mck3test.mupa" );
- mussaAnalysis.analyze(0, 0, Mussa::TransitiveNway, 0.0);
- //mussaAnalysis.load("mck3test_w30_t20");
- updateAnalysis();
+ if (analysis == 0)
+ {
+ mussaAnalysis = new Mussa;
+ }
+ else
+ {
+ mussaAnalysis = analysis;
+ updateAnalysis();
+ }
}
QSize PathScene::sizeHint() const
}
}
+void PathScene::loadMupa()
+{
+ QString caption("Load a mussa parameter file");
+ QString filter("Mussa Parameters (*.mupa)");
+ QString mupa_path = QFileDialog::getOpenFileName(this,
+ caption,
+ QDir::currentPath(),
+ filter);
+ mussaAnalysis->load_mupa_file(mupa_path.toStdString());
+ updateAnalysis();
+}
+
+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();
+}
+
void PathScene::setSoftThreshold(int threshold)
{
- if (mussaAnalysis.get_threshold() != threshold) {
- mussaAnalysis.set_soft_thres(threshold);
- mussaAnalysis.nway();
+ if (mussaAnalysis->get_threshold() != threshold) {
+ mussaAnalysis->set_soft_thres(threshold);
+ mussaAnalysis->nway();
update();
}
}
+////////////////////
+// Rendering code
void PathScene::initializeGL()
{
glEnable(GL_DEPTH_TEST);
void PathScene::updateAnalysis()
{
- GlSequence *gl_seq;
- float y = mussaAnalysis.sequences().size() * 100 ;
- float max_base_pairs = 0;
// Delete old glsequences
// FIXME: does this actually free the memory from the new'ed GlSequences?
tracks.clear();
- // save a reference to our GlSequences
- for(vector<Sequence>::const_iterator seq_itor = mussaAnalysis.sequences().begin();
- seq_itor != mussaAnalysis.sequences().end();
- ++seq_itor)
+
+ // Run analysis
+ cout << "updateA:" << mussaAnalysis->size() //<< mussaAnalysis->paths().size()
+ << endl;
+ if (mussaAnalysis->size() >= 2)
{
- 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 );
+ 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;
}
- maxOrtho2d.setWidth(max_base_pairs + 100.0);
- maxOrtho2d.setHeight((mussaAnalysis.sequences().size()) * 100 );
- curOrtho2d = maxOrtho2d;
}
static void processHits(GLint hits, GLuint buffer[])
GLfloat y;
bool reversed = false;
bool prevReversed = false;
- const NwayPaths& nway = mussaAnalysis.paths();
+ const NwayPaths& nway = mussaAnalysis->paths();
glLineWidth(0.5);
vector<GlSequence>::const_iterator track_itor;
Q_OBJECT
public:
- PathScene(int fragsize, int length, QWidget *parent=0);
+ PathScene(Mussa *analysis=0, QWidget *parent=0);
QSize sizeHint() const;
- Mussa mussaAnalysis;
+ Mussa* mussaAnalysis;
std::vector<GlSequence> tracks;
public slots:
void setX(int x);
void setClipPlane(int z);
void setZoom(int);
+ //! load a mussa parameter file (which specifies an analysis to run)
+ void loadMupa( );
+ //! load a previously run analysis
+ void loadSavedAnalysis();
//! set the soft threshold used by the Nway_Path algorithm
void setSoftThreshold(int thres);
//! called when we've changed the analysis
int zoom;
QRectF maxOrtho2d;
QRectF curOrtho2d;
- int fragsize;
- int length;
void initializeGL();
void resizeGL(int width, int height);
#include <iostream>
-PathWindow::PathWindow(QWidget *) :
+PathWindow::PathWindow(Mussa *analysis, QWidget *) :
closeAction(0) // initialize one of the pointers to null as a saftey flag
{
+ scene = new PathScene(analysis, this);
+
setupActions();
setupMainMenu();
- scene = new PathScene(10000, 10, this);
//This next setWhatsThis function prevents
// a segfault when using WhatsThis feature with
// opengl widget.
loadMupaAction = new QAction(tr("Load Mussa Parameters"), this);
connect(loadMupaAction, SIGNAL(triggered()),
- this, SLOT(loadMupa()));
+ scene, SLOT(loadMupa()));
loadSavedAnalysisAction = new QAction(tr("Load &Analysis"), this);
connect(loadSavedAnalysisAction, SIGNAL(triggered()),
- this, SLOT(loadSavedAnalysis()));
+ scene, SLOT(loadSavedAnalysis()));
loadSavedAnalysisAction->setIcon(QIcon("icons/fileopen.png"));
saveMotifListAction = new QAction(tr("Save Motifs"), this);
NotImplementedBox();
}
-void PathWindow::loadMupa()
-{
- QString caption("Load a mussa parameter file");
- QString filter("Mussa Parameters (*.mupa)");
- QString mupa_path = QFileDialog::getOpenFileName(this,
- caption,
- QDir::currentPath(),
- filter);
- scene->mussaAnalysis.load_mupa_file(mupa_path.toStdString());
-}
-
-void PathWindow::loadSavedAnalysis()
-{
- NotImplementedBox();
-}
-
void PathWindow::saveMotifList()
{
NotImplementedBox();
class QAction;
class PathScene;
class ImageSaveDialog;
+class Mussa;
class PathWindow : public QMainWindow
{
Q_OBJECT
public:
- PathWindow(QWidget *parent=0);
+ PathWindow(Mussa* analysis=0, QWidget *parent=0);
public slots:
//! display an about box, contemplating the politics of the author list
void createNewAnalysis();
//! launch a sub analysis
void createSubAnalysis();
- //! load a mussa parameter file (which specifies an analysis to run)
- void loadMupa( );
- //! load a previously run analysis
- void loadSavedAnalysis();
//\@}
//! \defgroup MotifHandling Handling of motif lists