generated from timnat/TRate_rl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTR_trl.cpp
103 lines (83 loc) · 2.8 KB
/
TR_trl.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
#include <unistd.h>
#include <stdio.h>
#include <fstream>
#include <string>
#include <string.h>
#include <iostream>
#include <sstream>
#include <stdlib.h>
using namespace std;
int main( int argc , char** argv ) {
char fName[1000]="", fff[1000]="";
int L=300; //read length, should be provided as an input, default 150
if (optind >= argc) {
fprintf(stderr, "Expected area_file(*ra) read_length\n");
fprintf(stderr, "Usage: area_file(*ra) read_length\n");
exit(EXIT_FAILURE);
}
if (argc < 2) {
fprintf(stderr, "Expected area_file(*ra) and read_length\n");
fprintf(stderr, "Usage: area_file(*ra) read_length\n");
exit(EXIT_FAILURE);
}
//strncat(fname,"",0);
strncat(fName,argv[optind],strlen(argv[optind]));
//printf ("fName=%s argv[2] = %s\n",fName,argv[2]);
L=atoi(argv[2]);
printf("L=%d\n",L);
std::ifstream area_file( fName );
if (!area_file) {
fprintf(stderr, "Can't open input file %s\n",fName);
exit(EXIT_FAILURE);
}
std::string line;
string trans="", trans_pred="", areas, begs, ends;
int linecount=0, beg, end, beg1, end1, W=0;
float rate, area, area_sum=0, D;
sprintf(fff, "%se_trl", fName);
std::ofstream outfile(fff);
printf("out=%s",fff);
beg1=-1; end1=-1;
while ( getline( area_file , line ) ) {
//std::cout << linecount << ": " << line << '\n' ;//supposing '\n' to be line end
//linecount++ ;
stringstream ss(line);
getline(ss,trans, '\t');
// cout << "Transcript: " << trans << " trans_pred: "<<trans_pred<<endl;
getline(ss,areas, '\t');
area=atof(areas.c_str());
// cout << "area: " << area <<endl;
getline(ss,begs, '\t');
beg=atoi(begs.c_str());
// cout << "beg: " << beg <<endl;
getline(ss,ends, '\t');
end=atoi(ends.c_str());
// cout << "end: " << end <<endl;
if(trans_pred != trans)
{
D=(float)L*W/1000;
rate=area_sum/D;
//printf ("area_sum=%f D=%f W=%d rate=%f\n", area_sum, D, W,rate);
if(trans_pred!="") outfile << trans_pred << "\t" << rate << endl;
area_sum=area;
W=end-beg;
beg1=beg; end1=end;
}
else
{area_sum+=area;
if(beg!=beg1 && end!=end1)
{W+=(end-beg);
beg1=beg; end1=end;
}
}
trans_pred=trans;
}
//process last record
D=(float)L*W/1000;
rate=area_sum/D;
// printf ("area_sum=%f D=%f W=%d rate=%f\n", area_sum, D, W,rate);
outfile << trans_pred << "\t" << rate << endl;
outfile.close();
area_file.close();
cout << endl << "all transcripts are processed";
}