-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwigToBed.cpp
More file actions
executable file
·56 lines (46 loc) · 1.41 KB
/
wigToBed.cpp
File metadata and controls
executable file
·56 lines (46 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include "wigreader.h"
#include <fstream>
#include <string>
#include <sstream>
#include <math.h>
#include <cstdlib>
#include "functions.h"
#include <cstring>
#include <map>
using namespace std;
string outputfileName(string wig_file) {
string output_filename = file_complete_prefix(basename(wig_file));
output_filename.append(".bed");
cout << "Output: " << output_filename << endl;
return output_filename;
}
int main(int argc, char* argv[]) {
if(argc != 2) {
cout << endl;
cout << "Usage: wigToBed sample.wig => sample.bed" << cout;
cout << endl;
exit(1);
}
string wig_file = argv[1];
string output_file = outputfileName(wig_file);
WigReader reader(wig_file);
reader.Read();
ofstream output_stream;
output_stream.open (output_file.c_str());
std::vector<string> chromosomes = reader.chromosomes();
int width = reader.getStep();
/* Iterate over the chromosomes */
int i = 0;
for (std::vector<string>::iterator chr_it = chromosomes.begin(); chr_it != chromosomes.end(); ++chr_it) {
/* Iterate over the chromosome length in steps according to $width */
int s = reader.startForChromosome((*chr_it));
int e = reader.endForChromosome((*chr_it));
for(int pos = s; (pos+width) < e; pos += width) {
i++;
output_stream << *chr_it << "\t" << pos << "\t" << pos + width << "\tbin-" << i<< "\t" << reader.rpkm(*chr_it,pos,pos+width) << endl;
}
}
output_stream.close();
return 0;
}