using namespace std;
+void callback(const std::string& desc, int cur, int end)
+{
+ std::cout << "analysis:" << desc << " " << cur << "/" << end << std::endl;
+}
+
Mussa::Mussa()
{
clear();
ana_mode(m.ana_mode),
win_append(m.win_append),
thres_append(m.thres_append),
+ analysis_cb(m.analysis_cb),
motif_sequences(m.motif_sequences),
color_mapper(m.color_mapper)
{
soft_thres = 0;
win_append = false;
thres_append = false;
+ analysis_cb = callback;
motif_sequences.clear();
color_mapper.clear();
}
return 0;
}
+
+void Mussa::set_analysis_callback(analysis_callback cb)
+{
+ analysis_cb = cb;
+}
+
+analysis_callback Mussa::get_analysis_calback() const
+{
+ return analysis_cb;
+}
+
void
Mussa::set_window(int a_window)
{
void
-Mussa::analyze(int w, int t, enum Mussa::analysis_modes the_ana_mode, double new_ent_thres)
+Mussa::analyze()
{
time_t t1, t2, begin, end;
double seqloadtime, seqcomptime, nwaytime, savetime, totaltime;
begin = time(NULL);
- ana_mode = the_ana_mode;
- ent_thres = new_ent_thres;
- if (w > 0)
- window = w;
- if (t > 0)
- {
- threshold = t;
- soft_thres = t;
- }
-
t1 = time(NULL);
if (the_seqs.size() < 2) {
t2 = time(NULL);
seqcomptime = difftime(t2, t1);
-
t1 = time(NULL);
the_paths.setup(window, threshold);
nway();
for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
seq_lens.push_back(the_seqs[i].size());
+ int seqcomps_done = 0;
+ int seqcomps_todo = (the_seqs.size() * (the_seqs.size()-1)) / 2;
+
for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
for(vector<Sequence>::size_type i2 = i+1; i2 < the_seqs.size(); i2++)
{
all_comps[i][i2].setup(window, threshold);
all_comps[i][i2].seqcomp(the_seqs[i].get_seq(), the_seqs[i2].get_seq(), false);
all_comps[i][i2].seqcomp(the_seqs[i].get_seq(),the_seqs[i2].rev_comp(),true);
+ ++seqcomps_done;
+ if (analysis_cb) {
+ analysis_cb("seqcomp", seqcomps_done, seqcomps_todo);
+ }
}
}
vector<string> some_Seqs;
the_paths.set_soft_threshold(soft_thres);
+ the_paths.set_progress_callback(analysis_cb);
if (ana_mode == TransitiveNway) {
the_paths.trans_path_search(all_comps);
#include <istream>
#include "alg/annotation_colors.hpp"
+#include "alg/mussa_callback.hpp"
#include "alg/nway_paths.hpp"
#include "alg/sequence.hpp"
class Mussa
{
- friend class ConnWindow;
public:
enum analysis_modes { TransitiveNway, RadialNway, EntropyNway,
RecursiveNway };
* (silly delayed loading of sequence data)
*/
int size() const;
+
+ void set_analysis_callback(analysis_callback cb);
+ analysis_callback get_analysis_calback() const;
+
//! set number of bases for this window size
void set_window(int a_window);
//! get number of bases for the sliding window
//! run seqcomp and the nway filtering algorithm.
/*!analyze will run seqcomp and then the nway algorithm
* on whatever sequences have been loaded into this mussa instance.
- * w & t are for command line override functionality, set to 0 to ignore
* \throws mussa_analysis_error
*/
- void analyze(int w=0, int t=0,
- enum analysis_modes ana_mode=TransitiveNway,
- double ent_thres=0.0);
+ void analyze();
/*! Run the nway filtering algorithm,
* this might be used when changing the soft threshhold?
*/
bool win_append;
//! should we append _t<threshold> to the saved analysis
bool thres_append;
+ //! callback, periodically called as we run an analysis
+ analysis_callback analysis_cb;
//! sequence data
std::vector<Sequence> the_seqs;
AnnotationColors color_mapper;
// Private methods
- //! loads sequence and annotations from fasta and annotation file
+ //! runs all the seqcomps needed to support the nway comparison
void seqcomp();
};
--- /dev/null
+#ifndef _MUSSA_CALLBACK_HPP
+#define _MUSSA_CALLBACK_HPP
+
+typedef void (*analysis_callback)(const std::string& name, int step, int max_step);
+
+#endif /* _MUSSA_CALLBACK_HPP */
all_matches);
}
}
+ if (progress_cb) {
+ progress_cb("transitive refinement", win_i, window_num);
+ }
}
//clog << "pathz=" << pathz.size()
// << " all_cmp=" << all_comparisons.size();
#include <boost/filesystem/fstream.hpp>
namespace fs = boost::filesystem;
+#include "alg/mussa_callback.hpp"
#include "alg/nway_paths.hpp"
#include "alg/conserved_path.hpp"
#include "mussa_exceptions.hpp"
using namespace std;
NwayPaths::NwayPaths()
+ : progress_cb(0)
{
}
threshold = t;
soft_thres = threshold;
win_size = w;
+ progress_cb = 0;
pathz.clear();
//cout << "nway: thres = " << threshold
return win_size;
}
+void NwayPaths::set_progress_callback(analysis_callback cb)
+{
+ progress_cb = cb;
+}
+
+analysis_callback NwayPaths::get_progress_callback() const
+{
+ return progress_cb;
+}
+
// dumbly goes thru and combines path windows exactly adjacent (ie + 1 index)
// doesn't deal with interleaved adjacency
void
//cout << "path number is: " << pathz.size() << endl;
pathz_i = pathz.begin();
+ int path_count = 0;
// only try to extend when pathz isn't empty.
if (pathz_i != pathz.end())
{
ext_path = *pathz_i;
+ ++path_count;
while(pathz_i != pathz.end())
{
// keep track of current path and advance to next path
cur_path = pathz_i;
++pathz_i;
+ ++path_count;
if (pathz_i == pathz.end()) {
end = true;
ext_path = *next_path;
}
}
+ if (progress_cb) {
+ progress_cb("refine", path_count-1, pathz.size());
+ }
}
}
//cout << "r_path number is: " << refined_pathz.size() << endl;
#include <string>
#include <vector>
-#include "alg/flp.hpp"
#include "alg/conserved_path.hpp"
+#include "alg/flp.hpp"
+#include "alg/mussa_callback.hpp"
class NwayPaths
{
double ent_thres;
std::vector<char *> c_sequences; //used by entropy_path_search
+ analysis_callback progress_cb;
public:
NwayPaths();
int get_threshold() const;
//! return window size used for this analysis
int get_window() const;
+ //! set analysis progress callback
+ void set_progress_callback(analysis_callback cb);
+ //! get analysis progress callback
+ analysis_callback get_progress_callback() const;
void radiate_path_search(std::vector<std::vector<FLPs> > all_comparisons);
void trans_path_search(std::vector<std::vector<FLPs> > all_comparisons);
}
opts.analysis = new Mussa();
+
// currently we can only have one analysis loaded, so
// running trumps viewing.
if (vm.count("run-analysis")) {
Mussa m1;
m1.load_mupa_file( mupa_path );
- m1.analyze(0, 0);
+ m1.analyze();
BOOST_CHECK_EQUAL( m1.get_name(), std::string("mck3test") );
BOOST_CHECK( m1.size() > 0 );
Mussa m1;
fs::path full_path(fs::path(EXAMPLE_DIR) / "mck3test.mupa");
m1.load_mupa_file( full_path );
- m1.analyze(0, 0);
+ m1.analyze();
BOOST_CHECK( m1.size() > 0);
BOOST_CHECK_EQUAL( m1.get_window(), 30 );
fs::path example_dir(EXAMPLE_DIR);
Mussa m1;
m1.load_mupa_file( example_dir / "mck3test.mupa" );
- m1.analyze(0, 0);
+ m1.analyze();
Mussa m2;
m2.load( fs::initial_path() / "mck3test_w30_t20");
Mussa analysis;
analysis.add_a_seq(s0);
analysis.add_a_seq(s1);
- analysis.analyze(4,3);
+ analysis.set_threshold(3);
+ analysis.set_window(4);
+ analysis.analyze();
NwayPaths npath = analysis.paths();
list<ConservedPath::path_type> result;
list<vector<bool> > reversed;
analysis.add_a_seq(s0);
analysis.add_a_seq(s1);
analysis.add_a_seq(s2);
- analysis.analyze(4,3);
+ analysis.set_window(4);
+ analysis.set_threshold(3);
+ analysis.analyze();
NwayPaths npath = analysis.paths();
// there should be no paths for these sequences
for (std::list<ConservedPath >::iterator pathz_i = npath.pathz.begin();
Mussa analysis;
analysis.add_a_seq(s0);
analysis.add_a_seq(s1);
- analysis.analyze(4,3);
+ analysis.set_window(4);
+ analysis.set_threshold(3);
+ analysis.analyze();
NwayPaths npath = analysis.paths();
for (std::list<ConservedPath >::iterator pathz_i = npath.pathz.begin();
pathz_i != npath.pathz.end();
mupa_path /= "mck3test.mupa";
Mussa m1;
m1.load_mupa_file( mupa_path );
- m1.analyze(0, 0);
+ m1.analyze();
const NwayPaths& npath = m1.paths();
BOOST_CHECK_EQUAL (npath.path_size(), npath.refined_path_size());
size_t first_refined_size = npath.refined_path_size();
m1.add_a_seq(seq2);
m1.add_a_seq(seq3);
- m1.analyze(10, 8);
+ m1.set_window(10);
+ m1.set_threshold(8);
+ m1.analyze();
m1.set_soft_threshold(10);
m1.nway();
}
import mussa
m = mussa.Mussa()
#m.load_mupa("examples/mck3test.mupa")
-#m.analyze(0, 0, mussa.analysis_modes.TransitiveNway, 0)
+#m.analyze()
m.load("../../mussa_analyses/land/myogenin_w30_t21")
path = m.paths()
void export_mussa()
{
void (Mussa::*load_mupa_string)(std::string) = &Mussa::load_mupa_file;
+
class_<Mussa>("Mussa")
.def("save", &Mussa::save)
.def("load", &Mussa::load, "Load previous run analysis")
Mussa *m = new Mussa;
fs::path converted_path(mupa_path.toStdString(), fs::native);
m->load_mupa_file(converted_path);
- m->analyze(0, 0, Mussa::TransitiveNway, 0.0);
+ m->analyze();
setAnalysis(m);
setWindowTitle(converted_path.native_file_string().c_str());
} catch (mussa_load_error e) {
if (win_size == 0 or threshold == 0) {
throw mussa_load_error("must set analysis parameters");
} else {
- mussa->analyze(win_size, threshold, Mussa::TransitiveNway, 0.0);
+ mussa->set_window(win_size);
+ mussa->set_threshold(threshold);
+ mussa->set_analysis_mode(Mussa::TransitiveNway);
+ //mussa->set_entropy(0); // might want to add this at some point
+ mussa->analyze();
}
return mussa;