<commit_before>#ifndef KALLISTO_MINCOLLECTOR_H
#define KALLISTO_MINCOLLECTOR_H

#include "common.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <unordered_map>

#include "KmerIndex.h"
#include "weights.h"

const int MAX_FRAG_LEN = 1000;

struct MinCollector {

  MinCollector(KmerIndex& ind, const ProgramOptions& opt)
    :
      index(ind),
      counts(index.ecmap.size(), 0),
      flens(MAX_FRAG_LEN),
      bias3(4096),
      bias5(4096),
      min_range(opt.min_range),
      k(opt.k),
      mean_fl(0.0),
      has_mean_fl(false),
      mean_fl_trunc(MAX_FRAG_LEN, 0.0),
      has_mean_fl_trunc(false)
      // eff_len_cache(MAX_FRAG_LEN, 0.0)
       {
         if (opt.fld != 0.0) {
           mean_fl = opt.fld;
           has_mean_fl = true;
         }
       }

  int collect(std::vector<std::pair<KmerEntry,int>>& v1,
              std::vector<std::pair<KmerEntry,int>>& v2,
              bool nonpaired=false);

  int collect(std::vector<std::pair<KmerEntry,int>>& v1) {
    std::vector<std::pair<KmerEntry,int>> dummy;
    return collect(v1,dummy,true);

  }
  int increaseCount(const std::vector<int>& u);
  int decreaseCount(const int ec);

  std::vector<int> intersectECs(std::vector<std::pair<KmerEntry,int>>& v) const;

  void write(std::ostream& o) {
    for (int id = 0; id < counts.size(); id++) {
      o << id << "\t" << counts[id] << "\n";
    }
  }
  
  void write_nonzero(std::ostream& o) {
    for (int id = 0; id < counts.size(); id++) {
        if(counts[id]>0){
            o << id << "\t" << counts[id] << "\n";
        }
    }
  }
  void loadCounts(ProgramOptions& opt);

  bool countBias(const char *s1, const char *s2, const std::vector<std::pair<KmerEntry,int>> v1, const std::vector<std::pair<KmerEntry,int>> v2, bool paired);

  // DEPRECATED
  double get_mean_frag_len() const;

  // compute the conditional mean of each target given the FLD
  void get_mean_frag_lens_trunc() const;

  // this function should only be used for SE data
  void init_mean_fl_trunc(double mean, double sd);

  KmerIndex& index;
  std::vector<int> counts;
  std::vector<int> flens;
  std::vector<int> bias3, bias5;
  int min_range;<commit_msg>write nonzero<commit_after>#ifndef KALLISTO_MINCOLLECTOR_H
#define KALLISTO_MINCOLLECTOR_H

#include "common.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <unordered_map>

#include "KmerIndex.h"
#include "weights.h"

const int MAX_FRAG_LEN = 1000;

struct MinCollector {

  MinCollector(KmerIndex& ind, const ProgramOptions& opt)
    :
      index(ind),
      counts(index.ecmap.size(), 0),
      flens(MAX_FRAG_LEN),
      bias3(4096),
      bias5(4096),
      min_range(opt.min_range),
      k(opt.k),
      mean_fl(0.0),
      has_mean_fl(false),
      mean_fl_trunc(MAX_FRAG_LEN, 0.0),
      has_mean_fl_trunc(false)
      // eff_len_cache(MAX_FRAG_LEN, 0.0)
       {
         if (opt.fld != 0.0) {
           mean_fl = opt.fld;
           has_mean_fl = true;
         }
       }

  int collect(std::vector<std::pair<KmerEntry,int>>& v1,
              std::vector<std::pair<KmerEntry,int>>& v2,
              bool nonpaired=false);

  int collect(std::vector<std::pair<KmerEntry,int>>& v1) {
    std::vector<std::pair<KmerEntry,int>> dummy;
    return collect(v1,dummy,true);

  }
  int increaseCount(const std::vector<int>& u);
  int decreaseCount(const int ec);

  std::vector<int> intersectECs(std::vector<std::pair<KmerEntry,int>>& v) const;

  void write(std::ostream& o) {
    for (int id = 0; id < counts.size(); id++) {
      o << id << "\t" << counts[id] << "\n";
    }
  }
  
  void write_nonzero(std::ostream& o, const int num_of_real_ec) {
    for (int id = 0; id < counts.size(); id++) {
        if(counts[id]>0){
            if(id<num_of_real_ec){
                o << id << "\t" << counts[id] << "\n";}
            else{
                
                
            std::stringstream result;
            std::copy(index.ecmap[id].begin(), index.ecmap[id].end(), std::ostream_iterator<int>(result, ","));           
            o << result.str() << "\t" << counts[id] << "\n";
                
        }
        }
    }
  }
  void loadCounts(ProgramOptions& opt);

  bool countBias(const char *s1, const char *s2, const std::vector<std::pair<KmerEntry,int>> v1, const std::vector<std::pair<KmerEntry,int>> v2, bool paired);

  // DEPRECATED
  double get_mean_frag_len() const;

  // compute the conditional mean of each target given the FLD
  void get_mean_frag_lens_trunc() const;

  // this function should only be used for SE data
  void init_mean_fl_trunc(double mean, double sd);

  KmerIndex& index;
  std::vector<int> counts;
  std::vector<int> flens;
  std::vector<int> bias3, bias5;
  int min_range;
{'fraction_non_alphanumeric': 0.15258855585831063, 'fraction_numerical': 0.015091175854118634, 'mean_word_length': 2.996649916247906, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 54, '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': '5044367', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1726, 'n_words': 355}