Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Dowsey committed Dec 4, 2014
1 parent 4116526 commit 1c9a18c
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 24 deletions.
5 changes: 0 additions & 5 deletions cmake-vs10.bat

This file was deleted.

5 changes: 5 additions & 0 deletions cmake_vs10_intel14_x64.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@pushd "%~dp0"
@mkdir build
@cd build
@cmake -G"Visual Studio 10 2010 Win64" -T"Intel C++ Compiler XE 14.0" -C"..\..\seamass-windeps\build.cmake" %* ..
@popd.
7 changes: 5 additions & 2 deletions seamass/BasisFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ BasisResampleMZ(vector<Basis*>& bases,
nnz.resize(cm.n[1], 0);

// find min and max m/z across spectra
double mz_min = DBL_MAX;
double mz_max = 0.0;
mz_min = DBL_MAX;
mz_max = 0.0;
for (ii j = 0; j < cm.n[1]; j++)
{
m[j] = (ii) (is[j+1] - is[j]);
Expand Down Expand Up @@ -286,6 +286,9 @@ BasisResampleRT(vector<Basis*>& bases,
{
double rc = pow(2.0, (double) rci);
double sp = 1.0 / rc;

rt_min = rts.front();
rt_max = rts.back();

// create A as a temporary COO matrix
m = js.size();
Expand Down
10 changes: 10 additions & 0 deletions seamass/BasisFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class BasisResampleMZ : public Basis
vector< vector<ii> > ia, ja;
//vector< vector<fp> > at;
//vector< vector<ii> > iat, jat;

double mz_min, mz_max;

public:
BasisResampleMZ(vector<Basis*>& bases,
Expand All @@ -102,6 +104,9 @@ class BasisResampleMZ : public Basis
void synthesis(vector<fp>& fs, const vector<fp>& cs, bool accum = true);
void analysis(vector<fp>& es, const vector<fp>& fs);
void l2norm(vector<fp>& es, const vector<fp>& fs);

double get_min() const { return mz_min; }
double get_max() const { return mz_max; }
};


Expand All @@ -113,6 +118,8 @@ class BasisResampleRT : public Basis
protected:
ii nnz; ii m; vector<fp> a; vector<ii> ia, ja; // CSR sparse A basis matrix
vector<fp> at; vector<ii> iat, jat;

double rt_min, rt_max;

public:
BasisResampleRT(vector<Basis*>& bases,
Expand All @@ -128,6 +135,9 @@ class BasisResampleRT : public Basis
void synthesis(vector<fp>& fs, const vector<fp>& cs, bool accum = true);
void analysis(vector<fp>& es, const vector<fp>& fs);
void l2norm(vector<fp>& es, const vector<fp>& fs);

double get_min() const { return rt_min; }
double get_max() const { return rt_max; }
};


Expand Down
46 changes: 46 additions & 0 deletions seamass/OptimiserASRL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,52 @@ step(ii iteration, double shrinkage)
}


fp
OptimiserASRL::
compute_norm_max_counts(ii n_core_bases)
{
// synthesis except root
fp max_counts = 0.0;
vector< vector<fp> > ts(bases.size());
for (ii j = (ii) bases.size() - 1; j >= n_core_bases; j--)
{
ii pj = bases[j]->get_parent()->get_index();
if (ts[pj].size() == 0)
if (bases[pj]->is_transient())
{
ts[pj].resize(bases[pj]->get_cm().size(), 0.0);
}
else
{
ts[pj].resize(bases[pj]->get_cm().size());
for (ii i = 0; i < (ii) bases[pj]->get_cm().size(); i++) ts[pj][i] = cs[pj][i];
}

if (ts[j].size() == 0)
{
bases[j]->synthesis(ts[pj], cs[j]);
}
else
{
bases[j]->synthesis(ts[pj], ts[j]);

}
vector<fp>().swap(ts[j]);

if (j == n_core_bases)
{
for (ii i = 0; i < ts[pj].size(); ++i)
{
max_counts = max_counts > ts[pj][i] ? max_counts : ts[pj][i];
}
max_counts *= pow(2.0, bases[j]->get_cm().l[0]) * pow(2.0, bases[j]->get_cm().l[1]);
break;
}
}
return max_counts;
}


void
OptimiserASRL::
write_h5(const SMOWriter& file, const string& datafilename, const vector<ii>& scale_bases,
Expand Down
2 changes: 2 additions & 0 deletions seamass/OptimiserASRL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class OptimiserASRL
double step(ii iteration, double strength);
void threshold(double threshold);
vector< vector<fp> >& get_cs() { return cs; }

fp compute_norm_max_counts(ii n_core_bases = 0);

void write_h5(const SMOWriter& file, const string& datafilename,
const vector<ii>& scale_bases, const vector<li>& is, const vector<ii>& js);
Expand Down
39 changes: 25 additions & 14 deletions seamass/SMVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@


using namespace SpatialIndex;
using namespace boost;

class MyDataStream : public IDataStream
{
Expand Down Expand Up @@ -120,17 +121,17 @@ SMVWriter::
SMVWriter(const string& _directory) :
directory(_directory)
{
boost::filesystem::path viz_path(directory);
if (boost::filesystem::exists(viz_path))
filesystem::path viz_path(directory);
if (filesystem::exists(viz_path))
{
for (boost::filesystem::directory_iterator end_dir_it, it(viz_path); it!=end_dir_it; ++it)
for (filesystem::directory_iterator end_dir_it, it(viz_path); it!=end_dir_it; ++it)
{
boost::filesystem::remove_all(it->path());
filesystem::remove_all(it->path());
}
}
else
{
boost::filesystem::create_directories(viz_path);
filesystem::create_directories(viz_path);
}
}

Expand All @@ -144,16 +145,25 @@ SMVWriter::
// only supports cm with dimension 2 at present
void
SMVWriter::
write_cs(const string& basename, vector<Basis*>& bases, ii n_core_bases, vector< vector<fp> >& cs) const
write_cs(const string& basename, vector<Basis*>& bases, ii n_core_bases, vector< vector<fp> >& cs,
double mz_min, double mz_max, double rt_min, double rt_max, double max_intensity) const
{
cout << "Writing " << directory << "/" << basename << ".txt" << endl;

boost::filesystem::path txt_path(directory);
ostringstream oss; oss << basename << ".txt";
txt_path /= oss.str();
ofstream ofs(txt_path.string().c_str());
ofs << mz_min << " " << mz_max << " " << rt_min << " " << rt_max << " " << max_intensity;

cout << "Writing " << directory << "/" << basename << ".idx" << endl;
cout << "Writing " << directory << "/" << basename << ".dat" << endl;

// Create a new storage manager with the provided base name and a 4K page size.
boost::filesystem::path viz_dir(directory);
viz_dir /= basename;
string viz_path = viz_dir.string();
SpatialIndex::IStorageManager* diskfile = StorageManager::createNewDiskStorageManager(viz_path, 4096);
boost::filesystem::path viz_path(directory);
viz_path /= basename;
string vp = viz_path.string();
SpatialIndex::IStorageManager* diskfile = StorageManager::createNewDiskStorageManager(vp, 4096);

SpatialIndex::StorageManager::IBuffer* file = StorageManager::createNewRandomEvictionsBuffer(*diskfile, 10, false);
// applies a main memory random buffer on top of the persistent storage manager
Expand All @@ -166,13 +176,14 @@ write_cs(const string& basename, vector<Basis*>& bases, ii n_core_bases, vector<
id_type indexIdentifier;
ISpatialIndex* tree = RTree::createAndBulkLoadNewRTree(RTree::BLM_STR, stream, *file, 0.7, 100, 100, 3, SpatialIndex::RTree::RV_RSTAR, indexIdentifier);

cout << "Max Intensity: " << max_intensity << endl;
cout << *tree;
cout << "Buffer hits: " << file->getHits() << std::endl;
cout << "Index ID: " << indexIdentifier << std::endl;
cout << "Buffer hits: " << file->getHits() << endl;
cout << "Index ID: " << indexIdentifier << endl;

bool ret = tree->isIndexValid();
if (ret == false) cout << "ERROR: Structure is invalid!" << std::endl;
else cout << "The stucture seems O.K." << std::endl;
if (ret == false) cout << "ERROR: Structure is invalid!" << endl;
else cout << "The stucture seems O.K." << endl;

delete tree;
delete file;
Expand Down
5 changes: 4 additions & 1 deletion seamass/SMVWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ class SMVWriter
void write_cs(const string& basename,
vector<Basis*>& _bases,
ii _n_core_bases,
vector< vector<fp> >& _cs) const;
vector< vector<fp> >& _cs,
double mz_min, double mz_max,
double rt_min, double rt_max,
double max_intensity) const;
};


Expand Down
10 changes: 8 additions & 2 deletions seamass/seamass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ void process(const std::string& id,
// Construct BasisResampleMZ root node
cout << endl << "Spectrometry rc_mz=" << rc0_mz << ":" << rc_mz << endl;
BasisResampleMZ* bResampleMZ = new BasisResampleMZ(bases, mzs, gs, is, js, rc0_mz, order);
double mz_min = bResampleMZ->get_min();
double mz_max = bResampleMZ->get_max();
for (ii j = 0; j < (ii) mzs.size(); j++) vector<double>().swap(mzs[j]);
while (bases.back()->get_cm().n[0] > order + 1)
{
Expand All @@ -120,6 +122,8 @@ void process(const std::string& id,
// BasisResampleRT
vector<ii> scale_bases(1, n_core_bases);
BasisResampleRT* bResampleRT = new BasisResampleRT(bases, bResampleMZ, rts, js, rcr, order);
double rt_min = bResampleRT->get_min();
double rt_max = bResampleRT->get_max();
while (bases.back()->get_cm().n[0] > order + 1)
{
new BasisDyadicScale(bases, bases.back(), 0, order);
Expand Down Expand Up @@ -223,18 +227,20 @@ void process(const std::string& id,

//////////////////////////////////////////////////////////////////////////////////
// OUTPUT

// write smo
if (debug)
{
ostringstream oss;
oss << config_id << "/" << rc0_mz << "/" << rcr << "/" << shr << "/" << tol << "/";
optimiser->write_h5(*h5out, oss.str(), scale_bases, is, js);
}

// output viz r-tree
// write smv viz r-tree
start = omp_get_wtime();
ostringstream oss;
oss << config_id << "_" << rc0_mz << "_" << rcr << "_" << shr << "_" << tol;
vizout->write_cs(oss.str(), bases, n_core_bases, optimiser->get_cs());
vizout->write_cs(oss.str(), bases, n_core_bases, optimiser->get_cs(), mz_min, mz_max, rt_min, rt_max, optimiser->compute_norm_max_counts(n_core_bases));
cout << "Duration: " << (omp_get_wtime() - start)/60.0 << "mins" << endl;

//ostringstream oss2; oss2 << id << "_" << config_id << "_" << rc0_mz << "_" << rcr << "_" << shr << "_" << tol << ".error.csv";
Expand Down

0 comments on commit 1c9a18c

Please sign in to comment.