Skip to content

Commit

Permalink
fixed bug in sn handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Buote Xu authored and Buote Xu committed Jun 24, 2012
1 parent b6912cb commit e4864c6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 36 deletions.
16 changes: 8 additions & 8 deletions examples/centroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
struct Centroid
{
double mz_;
unsigned int sn_;
int sn_;
double rt_;
Centroid(const double& mz, const unsigned int & sn, const double & rt)
Centroid(const double& mz, const int & sn, const double & rt)
: mz_(mz), sn_(sn), rt_(rt){}
};

namespace fbi {

template<>
struct Traits<Centroid> : mpl::TraitsGenerator<float, float> {};
struct Traits<Centroid> : mpl::TraitsGenerator<float, int> {};

} //end namespace fbi

Expand All @@ -30,18 +30,18 @@ struct CentroidBoxGenerator
double mzWindowPpm_;
double rtOffset_;
double rtWindow_;
float snWindow_;
int snWindow_;

CentroidBoxGenerator(double mzWindowPpm, float snWindow)
CentroidBoxGenerator(double mzWindowPpm, int snWindow)
: mzOffset_(0.0), mzWindowPpm_(mzWindowPpm), snWindow_(snWindow)
{}
CentroidBoxGenerator(double mzWindowPpm, double rtWindow, unsigned int snWindow)
CentroidBoxGenerator(double mzWindowPpm, double rtWindow, int snWindow)
: mzOffset_(0.0), mzWindowPpm_(mzWindowPpm),
rtOffset_(0.0), rtWindow_(rtWindow), snWindow_(snWindow)
{}

CentroidBoxGenerator(double mzOffset, double mzWindowPpm,
double rtOffset, double rtWindow, unsigned int snWindow)
double rtOffset, double rtWindow, int snWindow)
: mzOffset_(mzOffset), mzWindowPpm_(mzWindowPpm),
rtOffset_(rtOffset), rtWindow_(rtWindow), snWindow_(snWindow)
{}
Expand All @@ -61,7 +61,7 @@ CentroidBoxGenerator::get<0>(const Centroid & centroid) const


template <>
std::pair<float, float>
std::pair<int, int>
CentroidBoxGenerator::get<1>(const Centroid & centroid) const
{
return std::make_pair(
Expand Down
2 changes: 1 addition & 1 deletion examples/example-bruker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main(int argc, char * argv[]) {

SNSplitter<SetType> splitter(options);

CentroidBoxGenerator gen(10,0.51);
CentroidBoxGenerator gen(10,1);
//ResultType (*intersectFunctor)
//(std::vector<Centroid>, CentroidBoxGenerator, CentroidBoxGenerator);

Expand Down
41 changes: 14 additions & 27 deletions examples/splitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ SNSplitter {
typedef unsigned int LabelType;
SNSplitter(const ProgramOptions& options) : options_(options) {
overlap_ = options_.minClusterSize_ * options_.snWindowSize_ - 1;
std::cout << overlap_ << "overlap";
adjListCounter_ = 0;
}
unsigned int
parseString(const std::string & str, std::deque<Centroid> & centroids, unsigned int sn) {
parseString(const std::string & str, std::deque<Centroid> & centroids, int sn) {
float mz=0, massrange_lo=0, massrange_hi=0, rt=0;
char pol=0;
char mode[101];
Expand All @@ -99,7 +98,6 @@ SNSplitter {
int unknown=0, numentries=0, intensity=0;
typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
boost::char_separator<char> sep(",");
sn = 1;

Tokenizer tokens(str, sep);
Tokenizer::iterator it = tokens.begin();
Expand All @@ -117,52 +115,44 @@ SNSplitter {
}
ResultType
filterAdjList(ResultType & adjList) {
ResultType filteredAdjList;
std::vector<LabelType> labels;
LabelType nComponents = findConnectedComponents(adjList, labels);
std::vector<unsigned int> counter(nComponents, 0);
for (std::vector<LabelType>::size_type i = 0; i < labels.size(); ++i) {
++counter[labels[i] - 1];
}
//std::cout << "Counter" << counter;
filteredAdjList.resize(adjList.size());
typedef typename ResultType::value_type InnerType;
for (std::vector<LabelType>::size_type i = 0; i < labels.size(); ++i) {
if (counter[labels[i]-1] >= options_.minClusterSize_) {
adjList[i].swap(filteredAdjList[i]);
if (counter[labels[i]-1] < options_.minClusterSize_) {
InnerType().swap(adjList[i]);
//std::copy(adjList[i].begin(), adjList[i].end(), std::back_inserter(filteredAdjList[i]));
}
}
return filteredAdjList;
return adjList;
}
ResultType
joinAdjLists(const ResultType & filteredAdjList, ResultType & fullAdjList, typename ResultType::size_type offset) {
joinAdjLists(ResultType & filteredAdjList, ResultType & fullAdjList, typename ResultType::size_type offset) {
fullAdjList.resize(filteredAdjList.size() + offset);
std::cout << "OFFSET" << offset << std::endl;
typename ResultType::size_type index;
typedef typename ResultType::value_type InnerType;
typename ResultType::value_type::const_iterator it1;
for (index = 0; index < filteredAdjList.size(); ++index) {
for (it1 = filteredAdjList[index].begin(); it1 != filteredAdjList[index].end(); ++it1) {
fullAdjList[index + offset].insert(fullAdjList[index + offset].end(), typename ResultType::value_type::value_type(*it1 + offset));

}
InnerType().swap(filteredAdjList[index]);
}
//std::cout << adjListCounter_ << "adjCounter" << std::endl;
return fullAdjList;
}
ResultType
createShortAdjList(boost::function<ResultType(std::deque<Centroid>)> & intersectFunctor, const std::deque<Centroid> & centroids) {
//ResultType shortAdjList = intersectFunctor(centroids);
ResultType shortAdjList = SetType::intersect(centroids, CentroidBoxGenerator(10,0.51),CentroidBoxGenerator(10,0.51));
ResultType shortAdjList = intersectFunctor(centroids);

ResultType filteredAdjList = filterAdjList(shortAdjList);
for (int i = 0; i < 10; ++i) {
//std::cout << shortAdjList[i] << std::endl;
}
//std::cout << "FUBLA" << std::endl;
for (int i = 0; i < 10; ++i) {
//std::cout << filteredAdjList[i] << std::endl;
}
filterAdjList(shortAdjList);

return filteredAdjList;
return shortAdjList;
}

ResultType & makeUnique(ResultType & resultVector) {
Expand Down Expand Up @@ -192,7 +182,6 @@ SNSplitter {
unsigned int numEntries = parseString(str, centroids, segmentCounter);
segmentCounter++;
centroidCounter += numEntries;

if (segmentCounter % options_.segmentSize_ == 0) {
nextCentroidCounter = centroidCounter;
}
Expand All @@ -212,16 +201,14 @@ SNSplitter {
centroids.erase(centroids.begin(), centroids.begin() + numNewCentroids);


std::cout << "pong" << std::endl;
}

}
std::cout << "beep" << std::endl;
ifs.close();
ResultType filteredAdjList = createShortAdjList(intersectFunctor, centroids);
std::cout << "boop" << std::endl;
joinAdjLists(filteredAdjList, fullAdjList, oldCentroidCounter);

fullAdjList = makeUnique(fullAdjList);

return fullAdjList;
}

Expand Down

0 comments on commit e4864c6

Please sign in to comment.