-
Notifications
You must be signed in to change notification settings - Fork 0
/
DivideBEDFile.cpp
57 lines (40 loc) · 1.38 KB
/
DivideBEDFile.cpp
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
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
using namespace std;
using namespace boost;
string chro_name[22] = {"chr1","chr2","chr3","chr4","chr5","chr6","chr7","chr8","chr9","chr10","chr11","chr12","chr13","chr14","chr15","chr16","chr17","chr18","chr19","chrX","chrY","chrM"};
int main (int argc, char **argv) {
cerr << "DivideBEDFile <input.bed> <directory>" << endl;
ifstream inf(argv[1]);
int record_num = 0;
for(int i = 0; i < 22; ++i){
char cmd_mkdir[1000];
sprintf(cmd_mkdir, "mkdir %s/annotation_%s", argv[2], chro_name[i].c_str());
system(cmd_mkdir);
}
while(inf){
string strInput;
getline(inf, strInput);
if(strInput.length() > 0){
vector<string> vec;
split(vec, strInput, is_any_of("\t"));
++record_num;
char outputfile[1000];
sprintf(outputfile, "%s/annotation_%s/%d.bed", argv[2], vec[0].c_str(), record_num);
//sprintf(outputfile, "%s/%d.bed", argv[2], record_num);
ofstream ouf(outputfile, ios::trunc);
ouf << strInput << endl;
ouf.close();
}
}
inf.close();
return 0;
}