-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnormalizeWig.cpp
More file actions
executable file
·61 lines (51 loc) · 1.67 KB
/
normalizeWig.cpp
File metadata and controls
executable file
·61 lines (51 loc) · 1.67 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
57
58
59
60
61
#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;
void *read(void *ptr );
void *read( void *ptr) {
WigReader *reader;
reader = (WigReader *) ptr;
(*reader).Read();
}
int main(int argc, char* argv[]) {
if(argc != 3 ){
cerr << "Purpose: To convert un-normalized wiggle files into normalized (to RPKM) wiggle files." << endl;
cerr << "Usage: normalizeWig 0.001203 example1.wig => example1.normalized.wig" << endl;
cerr << "The normalization factor should be calculated as 1,000,000/num_mapped_reads." << endl;
exit(1);
}
double normalization = atof(argv[1]); // e.g. 1000
WigReader reader(argv[2]);
ostringstream output_filename_ss;
output_filename_ss << argv[2] << ".normalized.wig";
string output_file = output_filename_ss.str();
cout << "Output file: " << output_file << endl;
reader.Read();
ofstream output_stream;
output_stream.open (output_file.c_str());
//output_stream.precision(10);
//output_stream.setf(0,ios::floatfield); /* Not fixed. */
/* Output data */
map<string, vector<DATAPOINT> >::const_iterator itr;
std::vector<string> chroms;
for (itr = reader.data.begin(); itr != reader.data.end(); ++itr) {
/* chr header */
output_stream << "variableStep chrom=" << (*itr).first << " " << "span=" << reader.getStep() << endl;
vector<DATAPOINT> v = (*itr).second;
for (vector<DATAPOINT>::iterator dp = v.begin(); dp!=v.end(); ++dp) {
if((*dp).rpkm > 0) {
output_stream << (*dp).start << "\t" << ((*dp).rpkm * normalization) << endl;
}
}
}
output_stream.close();
return 0;
}