<commit_before>//
//  main.cpp
//  express
//
//  Created by <NAME> on 3/23/11.
//  Copyright 2011 <NAME>. All rights reserved.
//

//TODO: Update params between rounds

#include <boost/unordered_map.hpp>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <boost/thread.hpp>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "main.h"
#include "bundles.h"
#include "transcripts.h"
#include "fld.h"
#include "fragments.h"
#include "biascorrection.h"
#include "mismatchmodel.h"
#include "mapparser.h"
#include "threadsafety.h"

#ifndef WIN32
    #include "update_check.h"
#endif

using namespace std;
namespace po = boost::program_options;
namespace fs = boost::filesystem;

// the forgetting factor parameter controls the growth of the fragment mass
double ff_param = 0.85;

// the burn-in parameter determines how many reads are required before the 
// error and bias models are applied to probabilistic assignment 
size_t burn_in = 100000;
size_t burn_out = 5000000;
bool burned_out = false;

size_t stop_at = 0;

// file location parameters
string output_dir = ".";
string fasta_file_name = "";
string in_map_file_name = "";
string out_map_file_name = "";

// intial pseudo-count parameters (non-logged)
double expr_alpha = .1;
double fld_alpha = 1;
double bias_alpha = 1;
double mm_alpha = 1;

// fragment length parameters
int def_fl_max = 800;
int def_fl_mean = 200;
int def_fl_stddev = 80;

// option parameters
bool error_model = true;
bool bias_correct = true;
bool calc_covar = false;
bool vis = false;
bool output_alignments = false;
bool output_running_rounds = false;
bool output_running_reads = false;

// directional parameters
enum Direction{ BOTH, FR, RF };
Direction direction = BOTH;

bool running = true;

// used for multiple rounds of EM
bool first_round = true;
bool last_round = true;
bool batch_mode = false;
bool online_additional = false;
bool both = false;
size_t remaining_rounds = 0;

typedef boost::unordered_map<string, double> AlphaMap;
AlphaMap* expr_alpha_map = NULL;

AlphaMap* parse_priors(string in_file)
{
    ifstream ifs(in_file.c_str());
    if(!ifs.is_open())
    {
        cerr << "ERROR: Unable to open input priors file '" << in_file << "'.\n" ; 
        exit(1);
    }
    AlphaMap* alphas = new AlphaMap();
    
    string line;
    
    while(ifs.good())
    {
        getline(ifs,line);
        
        size_t idx = line.find_first_of("\t ");
        if (idx!=string::npos)
        {
            string name = line.substr(0,idx);
            string val = line.substr(idx+1);
            (*alphas)[name] = atof(val.c_str());
        }
    }
    return alphas;
};

bool parse_options(int ac, char ** av)
{
    po::options_description generic("Allowed options");
    generic.add_options()
    ("help,h", "produce help message")
    ("output-dir,o", po::value<string>(&output_dir)->default_value("."), "write all output files to this directory")
    ("frag-len-mean,m", po::value<int>(&def_fl_mean)->default_value(def_fl_mean), "prior estimate for average fragment length")
    ("frag-len-stddev,s", po::value<int>(&def_fl_stddev)->default_value(def_fl_stddev), "prior estimate for fragment length std deviation")
    ("additional-rounds,N", po::value<size_t>(&remaining_rounds)->default_value(remaining_rounds), "number of additional batch EM rounds after online round")
    ("output-align-prob", "output alignments (sam/bam) with probabilistic assignments")
    ("output-align-samp", "output alignments (sam/bam) with sampled assignments")
    ("fr-stranded", "accept only forward->reverse alignments (second-stranded protocols)")
    ("rf-stranded", "accept only reverse->forward alignments (first-stranded protocols)")
    ("calc-covar", "calculate and output covariance matrix")
    ("no-update-check", "disables automatic check for update via web")
    ;
    
    string prior_file = "";
    
    po::options_description hidden("Hidden options");
    hidden.add_options()
    ("no-bias-correct","")
    ("no-error-model","")
    ("single-round", "")
    ("visualizer-output,v","")
    ("output-running-rounds", "")    
    ("output-running-reads", "")
    ("batch-mode","")
    ("online-N","")
    ("both","")
    ("burn-out", po::value<double>(&burn_out)->default_value(burn_out), "")
    ("prior-params", po::value<string>(&prior_file)->default_value(""), "")
    ("forget-param,f", po::value<double>(&ff_param)->default_value(ff_param),"")
    ("expr-alpha", po::value<double>(&expr_alpha)->default_value(expr_alpha),"")
    ("stop-at", po::value<size_t>(&stop_at)->default_value(0),"")
    ("sam-file", po::value<string>(&in_map_file_name)->default_value(""),"")
    ("fasta-file", po::value<string>(&fasta_file_name)->default_value(""),"")
    ;
    
    po::positional_options_description positional;
    positional.add("fasta-file",1).add("sam-file",1);
    
    po::options_description cmdline_options;
    cmdline_options.add(generic).add(hidden);
    
    bool error = false;
    po::variables_map vm;<commit_msg>Added burn out hidden param<commit_after>//
//  main.cpp
//  express
//
//  Created by <NAME> on 3/23/11.
//  Copyright 2011 <NAME>. All rights reserved.
//

//TODO: Update params between rounds

#include <boost/unordered_map.hpp>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <boost/thread.hpp>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "main.h"
#include "bundles.h"
#include "transcripts.h"
#include "fld.h"
#include "fragments.h"
#include "biascorrection.h"
#include "mismatchmodel.h"
#include "mapparser.h"
#include "threadsafety.h"

#ifndef WIN32
    #include "update_check.h"
#endif

using namespace std;
namespace po = boost::program_options;
namespace fs = boost::filesystem;

// the forgetting factor parameter controls the growth of the fragment mass
double ff_param = 0.85;

// the burn-in parameter determines how many reads are required before the 
// error and bias models are applied to probabilistic assignment 
size_t burn_in = 100000;
size_t burn_out = 5000000;
bool burned_out = false;

size_t stop_at = 0;

// file location parameters
string output_dir = ".";
string fasta_file_name = "";
string in_map_file_name = "";
string out_map_file_name = "";

// intial pseudo-count parameters (non-logged)
double expr_alpha = .1;
double fld_alpha = 1;
double bias_alpha = 1;
double mm_alpha = 1;

// fragment length parameters
int def_fl_max = 800;
int def_fl_mean = 200;
int def_fl_stddev = 80;

// option parameters
bool error_model = true;
bool bias_correct = true;
bool calc_covar = false;
bool vis = false;
bool output_alignments = false;
bool output_running_rounds = false;
bool output_running_reads = false;

// directional parameters
enum Direction{ BOTH, FR, RF };
Direction direction = BOTH;

bool running = true;

// used for multiple rounds of EM
bool first_round = true;
bool last_round = true;
bool batch_mode = false;
bool online_additional = false;
bool both = false;
size_t remaining_rounds = 0;

typedef boost::unordered_map<string, double> AlphaMap;
AlphaMap* expr_alpha_map = NULL;

AlphaMap* parse_priors(string in_file)
{
    ifstream ifs(in_file.c_str());
    if(!ifs.is_open())
    {
        cerr << "ERROR: Unable to open input priors file '" << in_file << "'.\n" ; 
        exit(1);
    }
    AlphaMap* alphas = new AlphaMap();
    
    string line;
    
    while(ifs.good())
    {
        getline(ifs,line);
        
        size_t idx = line.find_first_of("\t ");
        if (idx!=string::npos)
        {
            string name = line.substr(0,idx);
            string val = line.substr(idx+1);
            (*alphas)[name] = atof(val.c_str());
        }
    }
    return alphas;
};

bool parse_options(int ac, char ** av)
{
    po::options_description generic("Allowed options");
    generic.add_options()
    ("help,h", "produce help message")
    ("output-dir,o", po::value<string>(&output_dir)->default_value("."), "write all output files to this directory")
    ("frag-len-mean,m", po::value<int>(&def_fl_mean)->default_value(def_fl_mean), "prior estimate for average fragment length")
    ("frag-len-stddev,s", po::value<int>(&def_fl_stddev)->default_value(def_fl_stddev), "prior estimate for fragment length std deviation")
    ("additional-rounds,N", po::value<size_t>(&remaining_rounds)->default_value(remaining_rounds), "number of additional batch EM rounds after online round")
    ("output-align-prob", "output alignments (sam/bam) with probabilistic assignments")
    ("output-align-samp", "output alignments (sam/bam) with sampled assignments")
    ("fr-stranded", "accept only forward->reverse alignments (second-stranded protocols)")
    ("rf-stranded", "accept only reverse->forward alignments (first-stranded protocols)")
    ("calc-covar", "calculate and output covariance matrix")
    ("no-update-check", "disables automatic check for update via web")
    ;
    
    string prior_file = "";
    
    po::options_description hidden("Hidden options");
    hidden.add_options()
    ("no-bias-correct","")
    ("no-error-model","")
    ("single-round", "")
    ("visualizer-output,v","")
    ("output-running-rounds", "")    
    ("output-running-reads", "")
    ("batch-mode","")
    ("online-N","")
    ("both","")
    ("burn-out", po::value<size_t>(&burn_out)->default_value(burn_out), "")
    ("prior-params", po::value<string>(&prior_file)->default_value(""), "")
    ("forget-param,f", po::value<double>(&ff_param)->default_value(ff_param),"")
    ("expr-alpha", po::value<double>(&expr_alpha)->default_value(expr_alpha),"")
    ("stop-at", po::value<size_t>(&stop_at)->default_value(0),"")
    ("sam-file", po::value<string>(&in_map_file_name)->default_value(""),"")
    ("fasta-file", po::value<string>(&fasta_file_name)->default_value(""),"")
    ;
    
    po::positional_options_description positional;
    positional.add("fasta-file",1).add("sam-file",1);
    
    po::options_description cmdline_options;
    cmdline_options.add(generic).add(hidden);
    
    bool error = false;
    po::variables_map vm;
{'fraction_non_alphanumeric': 0.15366383567055106, 'fraction_numerical': 0.009283033774442031, 'mean_word_length': 4.1432199085830375, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6558980', 'n_tokens_mistral': 3433, 'n_tokens_neox': 3271, 'n_words': 789}