36 #include <boost/filesystem.hpp>    42   main(boost::program_options::variables_map args) {
    44     namespace b_fs = boost::filesystem;
    45     namespace b_po = boost::program_options;
    48                                   << 
"    trajectory from: " << args[
"states"].as<std::string>()
    51     std::vector<std::size_t> states_without_noise;
    52     std::copy(states.begin(), states.end(), std::back_inserter(states_without_noise));
    53     std::set<std::size_t> state_names(states.begin(), states.end());
    54     std::size_t n_frames = states.size();
    56     float cmin = 0.01*args[
"cmin"].as<
float>();
    57     std::string basename = args[
"basename"].as<std::string>();
    61     std::string header_comment = args[
"header"].as<std::string>();
    62     std::map<std::string,float> commentsMap = args[
"commentsMap"].as<std::map<std::string,float>>();
    65     commentsMap[
"cmin"] = cmin;
    67     auto lowestState = std::min_element(states.begin(), states.end());
    68     std::size_t noiseState = *lowestState-1;
    70     if (args.count(
"output") || args.count(
"cores")) {
    73       std::vector<std::size_t> concat_limits;
    74       if (args.count(
"concat-limits")) {
    76                                       << args[
"concat-limits"].as<std::string>() << std::endl;
    78       } 
else if (args.count(
"concat-nframes")) {
    79         std::size_t n_frames_per_subtraj = args[
"concat-nframes"].as<std::size_t>();
    80         for (std::size_t i=n_frames_per_subtraj; i <= n_frames; i += n_frames_per_subtraj) {
    81           concat_limits.push_back(i);
    84         concat_limits = {n_frames};
    89       b_fs::path cwd(b_fs::current_path());
    91       typedef std::vector<b_fs::path> vec;             
    94       std::copy(b_fs::directory_iterator(cwd), b_fs::directory_iterator(), std::back_inserter(v));
    96       std::sort(v.begin(), v.end());             
   101       std::string clust_filename;
   103       for (vec::reverse_iterator it(v.rbegin()), it_end(v.rend()); it != it_end; ++it)
   105         std::ostringstream oss;
   107         std::string file_str = oss.str();
   109         found = file_str.rfind(basename);
   110         if (found!=std::string::npos) {
   111           clust_filename = file_str.substr(found,file_str.length()-found-1);
   116       if (found == std::string::npos) {
   117         std::cerr << 
"\n" << 
"error (noise): cluster file of type " << basename << 
" not found\n\n";
   123                             "# used for highest cluster file: %s\n", clust_filename.c_str()));
   127       if (n_frames != clust.size()) {
   128         std::cerr << 
"\n" << 
"error (noise): clust file is not of same length as state trajectory." << 
"\n\n";
   133       for (std::size_t i=0; i < n_frames; ++i) {
   134         CounterClustMap::iterator it(counts.find(clust[i]));
   135         if (it != counts.end()){
   138           counts[clust[i]] = 1;
   142       std::size_t noise_frames = 0;
   144       for (std::size_t i=0; i < n_frames; ++i) {
   145         if (counts[clust[i]] < cmin*n_frames){
   146           states[i] = noiseState;
   150       float noise_frames_per = 100.*noise_frames / n_frames;
   152                                     << 
"% of frames were identified as noise" << std::endl;
   154                             "% of frames were identified as noise\n");
   158       std::vector<std::size_t> noise_traj(n_frames);
   159       std::size_t current_core = states[0];
   160       std::vector<long> cores(n_frames);
   161       std::size_t changed_frames = 0;
   163       std::size_t last_limit = 0;
   164       for (std::size_t next_limit: concat_limits) {
   165         std::size_t next_limit_corrected = std::min(next_limit, n_frames);
   166         for (std::size_t i=last_limit; i < next_limit_corrected; ++i) {
   167           if (states[i] != noiseState) {
   168             current_core = states[i];
   172         for (std::size_t i=last_limit; i < next_limit_corrected; ++i) {
   174           if (states[i] != noiseState) {
   175             current_core = states[i];
   176             cores[i] = current_core;
   180           if (current_core != states_without_noise[i]) {
   183           noise_traj[i] = current_core;
   185         last_limit = next_limit_corrected;
   187       float changed_frames_per = 100.*changed_frames / n_frames;
   189                                     << 
"% of frames were reassigned\n"   190                                     << 
"    store result in: " << args[
"output"].as<std::string>()
   193                             "% of frames were reassigned\n");
   195       if (args.count(
"output")) {
   202       if (args.count(
"cores")) {
   204         Clustering::Tools::write_single_column<long>(args[
"cores"].as<std::string>(),
   210       std::cerr << 
"\n" << 
"error (noise): nothing to do! please define '--output' or '--cores'" << 
"\n\n";
 
bool verbose
global flag: use verbose output? 
general namespace for clustering package 
std::ostream & logger(std::ostream &s)
std::map< int, unsigned int > CounterClustMap
map for sorting clusters by population 
void main(boost::program_options::variables_map args)
controlling function and user interface for noise assignment