0
|
1 /*****************************************************************************
|
|
2 multiIntersectBed.h
|
|
3
|
|
4 (c) 2010 - Aaron Quinlan, UVA
|
|
5 - Assaf Gordon, CSHL
|
|
6 Quinlan Laboratory
|
|
7 Department of Public Health Sciences
|
|
8 Center for Public Health Genomics
|
|
9 University of Virginia
|
|
10 aaronquinlan@gmail.com
|
|
11
|
|
12 Licenced under the GNU General Public License 2.0 license.
|
|
13 ******************************************************************************/
|
|
14 #ifndef MULTIINTERSECTBED_H
|
|
15 #define MULTIINTERSECTBED_H
|
|
16
|
|
17 #include <vector>
|
|
18 #include <string>
|
|
19 #include "bedFile.h"
|
|
20 #include "genomeFile.h"
|
|
21 #include "intervalItem.h"
|
|
22
|
|
23 class MultiIntersectBed
|
|
24 {
|
|
25 private:
|
|
26
|
|
27 vector<string> filenames;
|
|
28 vector<string> titles;
|
|
29
|
|
30 vector<BedFile*> input_files;
|
|
31 vector<int> current_depth;
|
|
32 vector<BED> current_item;
|
|
33
|
|
34 std::ostream &output;
|
|
35
|
|
36 INTERVALS_PRIORITY_QUEUE queue;
|
|
37 std::string current_chrom;
|
|
38 map<int, bool> files_with_coverage;
|
|
39 int current_non_zero_inputs;
|
|
40 bool print_empty_regions;
|
|
41 bool haveTitles;
|
|
42
|
|
43 GenomeFile* genome_sizes;
|
|
44
|
|
45 std::string no_coverage_value;
|
|
46
|
|
47 public:
|
|
48 MultiIntersectBed(std::ostream& _output,
|
|
49 const vector<string>& _filenames,
|
|
50 const vector<string>& _titles,
|
|
51 bool _print_empty_regions,
|
|
52 const std::string& _genomeFileName,
|
|
53 const std::string& _no_coverage_value);
|
|
54
|
|
55 virtual ~MultiIntersectBed();
|
|
56
|
|
57 // Combines all interval files
|
|
58 void MultiIntersect();
|
|
59
|
|
60 // Print the header line: chrom/start/end + name of each bedgraph file.
|
|
61 void PrintHeader();
|
|
62
|
|
63
|
|
64 private:
|
|
65
|
|
66 // Open all input files, initialize "current_XXX" vectors
|
|
67 void OpenFiles();
|
|
68
|
|
69 // Close the input files.
|
|
70 void CloseFiles();
|
|
71
|
|
72 /*
|
|
73 Add an interval from BedGraph file 'index' into the queue.
|
|
74 will only be added if it belongs to the current chromosome.
|
|
75
|
|
76 If the interval was added (=consumed), the next interval will be read from the file
|
|
77 using 'LoadNextItem'
|
|
78 */
|
|
79 void AddInterval(int index);
|
|
80
|
|
81 /*
|
|
82 Loads the next interval from Bed file 'index'.
|
|
83 Stores it in 'current_bed_item' vector.
|
|
84 */
|
|
85 void LoadNextItem(int index);
|
|
86
|
|
87 /*
|
|
88 Scans the 'current_bedgraph_item' vector,
|
|
89 find the 'first' chromosome to use (different BedGraph files can start with different chromosomes).
|
|
90 */
|
|
91 std::string DetermineNextChrom();
|
|
92
|
|
93 /*
|
|
94 Returns 'true' if ALL intervals from ALL BedGraph files were used
|
|
95 */
|
|
96 bool AllFilesDone();
|
|
97
|
|
98 /*
|
|
99 Extract the next coordinate from the queue, and updates the current coverage information.
|
|
100 If multiple interval share the same coordinate values, all of them are handled.
|
|
101 If an END coordinate is consumed, the next interval (from the corresponding file) is read.
|
|
102 */
|
|
103 CHRPOS ConsumeNextCoordinate();
|
|
104
|
|
105 /*
|
|
106 Updates the coverage information based on the given item.
|
|
107 Item can be a START coordinate or an END coordiante.
|
|
108 */
|
|
109 void UpdateInformation(const IntervalItem &item);
|
|
110
|
|
111 /*
|
|
112 prints chrom/start/end and the current depth coverage values of all the files.
|
|
113 */
|
|
114 void PrintCoverage(CHRPOS start, CHRPOS end);
|
|
115
|
|
116 /*
|
|
117 prints chrom/start/end and the ZERO depth coverage values of all the files.
|
|
118 */
|
|
119 void PrintEmptyCoverage(CHRPOS start, CHRPOS end);
|
|
120
|
|
121 void DebugPrintQueue();
|
|
122 };
|
|
123
|
|
124
|
|
125 #endif
|