-
Notifications
You must be signed in to change notification settings - Fork 0
/
gene_shellinput.cpp
116 lines (101 loc) · 1.92 KB
/
gene_shellinput.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* gene.cpp
*
* Created on: 2018/03/09
* Author: user
*/
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
int main(int argc, char** argv)
{
std::string buff, bufftext, type;
int i, j, start, stop, genecount, genelength;
i = j = start = stop = genecount = genelength = 0;
buff = "";
bufftext = "gene";
type = "";
std::ifstream geneFile;
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " <Path of input file> <Path of output file>" <<std::endl;
}
geneFile.open(argv[1]);
if (!geneFile)
{
std::cerr << "Can't open input file." << std::endl;
exit(1);
}
while (std::getline(geneFile, buff))
{
std::stringstream fulltext(buff);
if(buff.find_first_of('\t') != std::string::npos)
{
i= 1;
while (std::getline(fulltext, buff, '\t'))
{
switch(i)
{
case 1:
i++;
break;
case 2:
i++;
break;
case 3:
if(!buff.compare(bufftext))
{
genecount++;
type = bufftext;
}
i++;
break;
case 4:
if(!type.compare(bufftext))
{
start = stoi(buff);
}
i++;
break;
case 5:
if(!type.compare(bufftext))
{
stop = stoi(buff);
genelength += stop - start + 1;
j++;
type = "";
}
i++;
break;
case 6:
i++;
break;
case 7:
i++;
break;
case 8:
i++;
break;
case 9:
i++;
break;
default:
i = 1;
}
}
}
}
geneFile.close();
std::ofstream geneOut;
geneOut.open(argv[2]);
if (!geneOut)
{
std::cerr << "Can't open output file." << std::endl;
exit(1);
}
geneOut << "Total gene count = " << genecount << std::endl;
geneOut << "Total length of gene regions = " << genelength << std::endl;
geneOut.close();
return 0;
}