windowExtractor.h 3.83 KB
Newer Older
Mathieu Giraud's avatar
Mathieu Giraud committed
1
2
3
4
#ifndef WINDOW_EXTRACTOR_H
#define WINDOW_EXTRACTOR_H

#include <iostream>
5
6
#include <string>
#include <map>
Mathieu Giraud's avatar
Mathieu Giraud committed
7
#include "segment.h"
8
#include "germline.h"
Mathieu Giraud's avatar
Mathieu Giraud committed
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "kmerstore.h"
#include "kmeraffect.h"
#include "windows.h"

using namespace std;

/**
 * This takes an OnlineFasta reader as input and extract windows from the
 * sequences given in the input.
 */
class WindowExtractor {
 private:
  size_t nb_reads;
22
  map<string, size_t> nb_reads_germline;
Mathieu Giraud's avatar
Mathieu Giraud committed
23
24
25

  ostream *out_segmented;
  ostream *out_unsegmented;
26
  ostream *out_affects;
Mathieu Giraud's avatar
Mathieu Giraud committed
27

28
  Stats stats[STATS_SIZE];
29
  size_t max_reads_per_window;
Mathieu Giraud's avatar
Mathieu Giraud committed
30
31
32
33
34
35
36
37
38
 public:

  WindowExtractor();

  /**
   * Extract windows from the collection of input reads.
   * If (un)segmented sequences must be output, the functions 
   * set(Un)SegmentedOutput() must be called before.
   * @param reads: the collection of input reads
39
   * @param multigermline: the multigermline
Mathieu Giraud's avatar
Mathieu Giraud committed
40
41
   * @param w: length of the window
   * @param windows_labels: Windows that must be kept and registered as such.
42
   * @param only_labeled_windows: remember only windows from windows_labels
43
   * @param nb_expected: maximal e-value of the segmentation
44
   * @param nb_reads_for_evalue: number of reads, used for e-value computation. Can be approximate or faked.
Mathieu Giraud's avatar
Mathieu Giraud committed
45
46
47
48
49
   * @return a pointer to a WindowsStorage that will contain all the windows.
   *         It is a pointer so that the WindowsStorage is not duplicated.
   * @post Statistics on segmentation will be provided through the getSegmentationStats() methods
   *       and getAverageSegmentationLength().
   */
50
51
  WindowsStorage *extract(OnlineFasta *reads, MultiGermline *multigermline,
                          size_t w,
52
                          map<string, string> &windows_labels, bool only_labeled_windows=false,
53
                          int stop_after=-1, int only_nth_reads=1, bool keep_unsegmented_as_clone=false,
54
                          double nb_expected = THRESHOLD_NB_EXPECTED, int nb_reads_for_evalue = 1);
Mathieu Giraud's avatar
Mathieu Giraud committed
55
56
57
58
59
60
61
62

  /**
   * @return the average length of sequences whose segmentation has been classified as seg
   * @param seg: one of the segmentation available in the enum SEGMENTED 
   * @pre extract() must have been launched.
   */
  float getAverageSegmentationLength(SEGMENTED seg);

63
64
65
66
67
  /**
   * cf. WindowsStorage::getMaximalNbReadsPerWindow()
   */
  size_t getMaximalNbReadsPerWindow();

Mathieu Giraud's avatar
Mathieu Giraud committed
68
69
70
71
72
73
74
75
76
77
78
79
  /**
   * @return Total number of processed reads by the previous call to extract()
   */
  size_t getNbReads();

  /**
   * @return the number of sequences whose segmentation has been classified as seg
   * @param seg: one of the segmentation available in the enum SEGMENTED 
   * @pre extract() must have been launched.
   */
  size_t getNbSegmented(SEGMENTED seg);

80
81
82
83
84
85
   /**
   * @return the number of reads segmented from germline
   * @param germline_code: one of the germline code in multigermline
   * @pre extract() must have been launched.
   */
  size_t getNbReadsGermline(string germline_code);
86
87
88
89
90
91

  /**
   * cf. WindowsStorage::setMaximalNbReadsPerWindow()
   */
  void setMaximalNbReadsPerWindow(size_t max_reads);

Mathieu Giraud's avatar
Mathieu Giraud committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  /**
   * Defines the output stream where the segmented sequences will be output.
   * Otherwise no output will be given.
   * @param out: The output stream
   */
  void setSegmentedOutput(ostream *out);

  /**
   * Defines the output stream where the unsegmented sequences will be output.
   * Otherwise no output will be given.
   * @param out: The output stream
   */
  void setUnsegmentedOutput(ostream *out);

106
107
108
109
110
111
112
  /**
   * Defines the output stream where the detailed affects will be output.
   * Otherwise no output will be given.
   * @param out: The output stream
   */
  void setAffectsOutput(ostream *out);

113
114
115
116
117
118
  /**
   * Output the segmentation stats
   * @param out: The output stream
   */
  void out_stats(ostream &out);

Mathieu Giraud's avatar
Mathieu Giraud committed
119
120
121
122
123
124
125
126
 private:
  /**
   * Initialize the statistics (put 0 everywhere).
   */
  void init_stats();
};

#endif