Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
1300 lines (1094 loc) · 40.2 KB
/
Copy pathmain.cpp
File metadata and controls
1300 lines (1094 loc) · 40.2 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "struct.h"
#include "PairsFilter.h"
#include "seq.h"
#include "LinearSuffixSort.h"
#include "PBS.h"
#include "CallPsScan.h"
#include "Timing.h"
#include "regex.h"
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <set>
using namespace std;
//global variable define
int Dmin = 1000;
int Dmax = 20000;
int Lmin = 100;
int Lmax = 3500;
int Lex = 20; //exact match pair len
int MaxGap = 50; //maxgap between pairs
float JoinThreshold = 0.7;
float SplitThreshold = 0.9;
int TSRmin = 4;
int TSRmax = 6;
int PBS_region = 100;
int PPT_region = 100;
int PPT_window = 15;
int PBS_minLen = 14;
int max_sub_rt_gap=2;
int min_sub_rt_count=4;
int CHECK_PAIRS = 0;
float minOutScore = 6.0;
int wrought = 0;
float LowerSharpness = 0.40;
float HigherSharpness = 0.40;
float minMatchSim = 0;
int outAlignLen = 40;
char *fig_file = NULL;
bool edge_signal = false;
bool showPairNum = false;
bool checkCentriole = false;
char transDNA[128];
char transAA[128];
char* Filter = NULL;
//5'TG 5'CA 3'TG 3'CA TSR PBS PPT RTdomain Core C-Term
// 1 1 1 1 1 1 1 1 1 1
// 1111111111B
int SignalNum = 10;
int FModule = (1 << (SignalNum + 1)) - 1; //module
int M5TG = 1 << 10; //10000000000b;
int M5CA = 1 << 9; //01000000000b;
int M3TG = 1 << 8; //00100000000b;
int M3CA = 1 << 7; //00010000000b;
int MTSR = 1 << 6; //00001000000b;
int MPBS = 1 << 5; //00000100000b;
int MPPT = 1 << 4; //00000010000b;
int MRT = 1 << 3; //00000001000b;
int MCORE = 1 << 2;
int MCT = 1 << 1;
int MRH = 1;
string matrix2domain(const string& m)
{
// if(m.find("PS50878") != string::npos)
// {
// return "RT Domain";
// }
// else
if (m.find("PS50994") != string::npos)
{
return "IN (core)";
}
else if (m.find("PS51027") != string::npos)
{
return "IN (c-term)";
}
else if (m.find("PS50879") != string::npos)
{
return "RNase H";
}
else
{
return m;
}
}
int matrix2modul(string& m)
{
if (m.find("RT") != string::npos)
{
return MRT;
}
else if (m.find("PS50994") != string::npos)
{
return MCORE;
}
else if (m.find("PS51027") != string::npos)
{
return MCT;
}
else if (m.find("PS50879") != string::npos)
{
return MRH;
}
else
{
return 0;
}
}
void CountScore(stick& st)
{
string PBS_name, PBS_str, f_out, r_out;
int PBS_begin, PBS_end, PPT_begin, PPT_count;
char buf[10240]; //2014-07-30, increase buf size to prvent segmentation fault, by Zhao
//try to output foward strand
int f_score = 0;
int f_dscore = 0;
int f_status = 0;
int f_pp_match = 0; //PBS and PPT match base count
int a_begin = st.end1 + 1;
int a_end = st.pos2 - 1;
if (st.pp.PBS)
{
f_score++;
f_status = f_status | MPBS;
// sprintf(buf,"PBS : [%s] %d - %d Len: %d\n",st.pp.PBS_name.c_str(),
// st.pp.PBS_begin+1,st.pp.PBS_end+1,
// st.pp.PBS_match);
sprintf(buf, "PBS : [%d/%d] %d - %d (%s)\n", st.pp.PBS_match,
st.pp.PBS_end - st.pp.PBS_begin + 1,
st.pp.PBS_begin + 1, st.pp.PBS_end + 1, st.pp.PBS_name.c_str());
f_out += buf;
a_begin = st.pp.PBS_end + 1;
for (int i = 0;i < st.pp.pbs_str.length();++i)
{
if (st.pp.pbs_str[i] == '|')
++f_pp_match;
}
}
if (st.pp.PPT)
{
f_score++;
f_status = f_status | MPPT;
sprintf(buf, "PPT : [%d/%d] %d - %d\n", st.pp.PPT_count, PPT_window,
st.pp.PPT_begin + 1, st.pp.PPT_begin + PPT_window);
f_out += buf;
a_end = st.pp.PPT_begin - 1;
f_pp_match += st.pp.PPT_count;
}
for (int j = 0;j < st.motif.size();++j)
{
if (st.motif[j].forward)
{
int p_begin = st.motif[j].p_begin[0]; //ORF: from * to *
int p_end = st.motif[j].p_end[st.motif[j].p_end.size() - 1];
// int p_begin=st.motif[j].begin;
// int p_end=st.motif[j].end;
// for(int k=0;k<st.motif[j].p_begin.size();++k)
// {
// if(st.motif[j].p_begin[k]>=a_begin &&
// st.motif[j].p_begin[k]<=a_end)
// {
// p_begin=st.motif[j].p_begin[k];
// break;
// }
// }
// for(int k=(int)st.motif[j].p_end.size()-1;k>=0;--k)
// {
// if(st.motif[j].p_end[k]>=a_begin &&
// st.motif[j].p_end[k]<=a_end)
// {
// p_end=st.motif[j].p_end[k];
// break;
// }
// }
sprintf(buf, "Domain: %d - %d [possible ORF:%d-%d, (%s)]\n",
st.motif[j].begin + 1, st.motif[j].end + 1, p_begin + 1, p_end + 1,
matrix2domain(st.motif[j].name).c_str());
f_out += buf;
f_score++;
f_dscore++;
f_status = f_status | matrix2modul(st.motif[j].name);
}
}
//try to output reverse strand
int r_score = 0;
int r_dscore = 0;
int r_status = 0;
int r_pp_match = 0;
a_begin = st.end1 + 1;
a_end = st.pos2 - 1;
if (st.pp._PBS)
{
r_score++;
r_status = r_status | MPBS;
// sprintf(buf,"PBS : [%s] %d - %d Len: %d\n",st.pp._PBS_name.c_str(),
// st.pp._PBS_begin+1,st.pp._PBS_end+1,
// st.pp._PBS_match);
sprintf(buf, "PBS : [%d/%d] %d - %d (%s)\n", st.pp._PBS_match,
st.pp._PBS_end - st.pp._PBS_begin + 1,
st.pp._PBS_begin + 1, st.pp._PBS_end + 1, st.pp._PBS_name.c_str());
r_out += buf;
a_end = st.pp._PBS_begin - 1;
for (int i = 0;i < st.pp._pbs_str.length();++i)
{
if (st.pp._pbs_str[i] == '|')
++r_pp_match;
}
}
if (st.pp._PPT)
{
r_score++;
r_status = r_status | MPPT;
sprintf(buf, "PPT : [%d/%d] %d - %d\n", st.pp._PPT_count, PPT_window,
st.pp._PPT_begin + 1, st.pp._PPT_begin + PPT_window);
r_out += buf;
a_begin = st.pp._PPT_begin + st.pp._PPT_count;
r_pp_match += st.pp._PPT_count;
}
for (int j = 0;j < st.motif.size();++j)
{
if (!st.motif[j].forward)
{
int p_begin = st.motif[j].p_begin[0];
int p_end = st.motif[j].p_end[st.motif[j].p_end.size() - 1];
// int p_begin=st.motif[j].begin;
// int p_end=st.motif[j].end;
// for(int k=0;k<st.motif[j].p_begin.size();++k)
// {
// if(st.motif[j].p_begin[k]>=a_begin &&
// st.motif[j].p_begin[k]<=a_end)
// {
// p_begin=st.motif[j].p_begin[k];
// break;
// }
// }
// for(int k=(int)st.motif[j].p_end.size()-1;k>=0;--k)
// {
// if(st.motif[j].p_end[k]>=a_begin &&
// st.motif[j].p_end[k]<=a_end)
// {
// p_end=st.motif[j].p_end[k];
// break;
// }
// }
sprintf(buf, "Domain: %d - %d [possible ORF:%d-%d, (%s)]\n",
st.motif[j].begin + 1, st.motif[j].end + 1, p_begin + 1, p_end + 1,
matrix2domain(st.motif[j].name).c_str());
r_out += buf;
r_score++;
r_dscore++;
r_status = r_status | matrix2modul(st.motif[j].name);
}
}
/* //I think this program should not output TWO STRAND LTR
if( (f_score>=3 && r_score>=3) ||
(f_score==r_score && f_score>0) )
{
st.score+=f_score;
st.status = st.status | f_status;
st.strand_str+="BOTH STRANDS ARE POSSIBLE:\n";
st.strand_str+="Strand + :\n";
st.strand_str+=f_out;
st.strand_str+="Strand - :\n";
st.strand_str+=r_out;
st.strand=3;//two
}
else */
if (f_score > r_score ||
((f_score == r_score) && (f_pp_match >= r_pp_match) && (f_score > 0)))
{
st.score += f_score;
st.domain_score = f_dscore;
st.status = st.status | f_status;
st.strand_str += "Strand + :\n";
st.strand_str += f_out;
st.strand = 1; //+
}
else if (f_score < r_score ||
((f_score == r_score) && (f_pp_match < r_pp_match) && (r_score > 0)))
{
st.score += r_score;
st.domain_score = r_dscore;
st.status = st.status | r_status;
st.strand_str += "Strand - :\n";
st.strand_str += r_out;
st.strand = 2; //-
}
else
{
st.strand_str += "NO EVIDENCE FOR STRAND\n";
st.strand = 0; //no
}
}
string dec2bin(int dec)
{
string ret;
for (int i = SignalNum;i >= 0;--i)
{
if ( dec & (1 << i) )
ret += "1";
else
ret += "0";
}
return ret;
}
int InitFilter(char* f)
{
if (f == 0)
return FModule;
int ret = f[0] - '0';
for (int i = 1;i < strlen(f);++i)
{
ret = ret << 1;
ret += f[i] - '0';
}
return ~ret & FModule;
}
void TableOutputMotif(vector<MOTIF>& motif, string name, bool forward)
{
bool has = false;
for (int j = 0;j < motif.size();++j)
{
if (motif[j].forward == forward)
{
if (motif[j].name == name)
{
cout << motif[j].begin + 1 << "-" << motif[j].end + 1 << "\t";
has = true;
break;
}
}
}
if (!has)
cout << "N-N\t";
}
bool FigOutputMotif(vector<MOTIF>& motif, string name, bool forward, ofstream& fig, string id)
{
bool has = false;
for (int j = 0;j < motif.size();++j)
{
if (motif[j].forward == forward)
{
if (motif[j].name == name)
{
fig << motif[j].begin + 1 << "," << motif[j].end + 1 << "," << id << ";";
has = true;
//break;
}
}
}
return has;
}
int OutPutResult(char* name, char* myString, int stringLength, vector < stick >& sticks, ofstream& fig)
{
int result_count = 0;
FourPos fp;
set
< FourPos > used_ltr;
int filter = InitFilter(Filter);
if (fig.good())
{
fig << ">" << name << "\n";
}
cout << ">Sequence: " << name << " Len:" << stringLength << endl;
if (wrought == 2)
cout << "index\tSeqID\tLocation\tLTR len\tInserted element len\tTSR\tPBS\tPPT\tRT\tIN (core)\tIN (c-term)\tRH\tStrand\tScore\tSharpness\tSimilarity\n";
// I think we should not del overlap by hand, let judge it later
// And, if we del these kind of overlap, we should check each two of them,
// not only the neighbored.
// //del overlap
// for(int i=0;i<(int)sticks.size()-1 && Sensitive<0.001;++i)
// {
// cerr<<"check :"<<sticks[i].pos1+1<<"-"<<sticks[i].end2+1<<" "
// <<sticks[i+1].pos1+1<<"-"<<sticks[i+1].end2+1<<endl;
// if(sticks[i].end2<sticks[i+1].pos1)
// continue;//no overlap
// int l_len=0;
// int r_len=0;
// int m_len=0;
// if(sticks[i].end1>sticks[i+1].pos1 &&
// sticks[i].pos1<sticks[i+1].end1 )
// {
// int max = sticks[i].end1>sticks[i+1].end1?sticks[i].end1:sticks[i+1].end1;
// int min = sticks[i].pos1<sticks[i+1].pos1?sticks[i].pos1:sticks[i+1].pos1;
// l_len=max-min;
// int min_ltr = sticks[i].len1<sticks[i+1].len1?sticks[i].len1:sticks[i+1].len1;
// if( (float)l_len/min_ltr < 0.9)
// l_len=0;//this should not regard as overlap
// }
// if(sticks[i].end2>sticks[i+1].pos2 &&
// sticks[i].pos2<sticks[i+1].end2)
// {
// int max = sticks[i].end2>sticks[i+1].end2?sticks[i].end2:sticks[i+1].end2;
// int min = sticks[i].pos2<sticks[i+1].pos2?sticks[i].pos2:sticks[i+1].pos2;
// r_len=max-min;
// int min_ltr = sticks[i].len2<sticks[i+1].len2?sticks[i].len2:sticks[i+1].len2;
// if( (float)r_len/min_ltr < 0.9)
// r_len=0;//this should not regard as overlap
// }
// if(sticks[i].end2>sticks[i+1].pos1 &&
// sticks[i].pos2<sticks[i+1].end1)
// {
// int max = sticks[i].end2>sticks[i+1].end1?sticks[i].end2:sticks[i+1].end1;
// int min = sticks[i].pos2<sticks[i+1].pos1?sticks[i].pos2:sticks[i+1].pos1;
// m_len=max-min;
// int min_ltr = sticks[i].len2<sticks[i+1].len1?sticks[i].len2:sticks[i+1].len1;
// if( (float)m_len/min_ltr < 0.9)
// m_len=0;//this should not regard as overlap
// }
// if(l_len>0 && r_len>0)//both LTR overlap
// {
// if(sticks[i].score < sticks[i+1].score)
// sticks[i].score = 0;//del the lower score, if they are same, no one deleted
// else if(sticks[i].score > sticks[i+1].score)
// sticks[i+1].score = 0;
// }
// else if(l_len>0 || r_len>0)//only one side same
// {
// cerr<<" one side equal, domain:"<<sticks[i].motif.size()<<" "<<sticks[i+1].motif.size()<<endl;
// //should del too more aa one, or no aa one
// if(sticks[i].motif.size()>0 && sticks[i].motif == sticks[i+1].motif)//domain same
// {
// cerr<<"motif same\n";
// if(sticks[i].score < sticks[i+1].score)
// sticks[i].score = 0;//del the lower score, if they are same, no one deleted
// else if(sticks[i].score > sticks[i+1].score)
// sticks[i+1].score = 0;
// }
//
// }
// else if(m_len>0)//first 3'LTR overlap with second 5'LTR
// {
// if(sticks[i].domain_score>0 && sticks[i+1].domain_score<=0)//one has no domain
// sticks[i+1].score=0;//del
// else if(sticks[i].domain_score<=0 && sticks[i+1].domain_score>0)//one has no domain
// sticks[i].score=0;//del
// }
// }
for (int i = 0; i < sticks.size (); ++i)
{
stick st = sticks[i];
if ( (!CHECK_PAIRS && st.score < minOutScore) || (CHECK_PAIRS && st.score < 0))
continue; //
fp.a = st.pos1;
fp.b = st.end1;
fp.c = st.pos2;
fp.d = st.end2;
if ( used_ltr.count( fp ) )
continue;
else
used_ltr.insert( fp );
//recheck condicitons
if (st.len1 < Lmin || st.len1 > Lmax ||
st.len2 < Lmin || st.len2 > Lmax ||
(st.pos2 - st.end1) < Dmin || (st.pos2 - st.end1) > Dmax)
{
//cout<<"filter, this one:"<<st.pos1<<"-"<<st.end2<<endl;
continue;
}
//check sharpness
if (st.sharpness5 < LowerSharpness || st.sharpness3 < LowerSharpness)
continue;
if (st.sharpness5 < HigherSharpness && st.sharpness3 < HigherSharpness)
continue;
//if(st.match_score<0.83)
// continue;
//check Filter
if ( FModule != (st.status | filter))
{
//cout<<st.status<<" filter:"<<filter<<endl;
//cout<<"ans: "<<(st.status|filter)<<" M:"<<FModule<<endl;
continue;
}
if (st.match_score < minMatchSim)
continue;
if (edge_signal) //check edge signal
{
if (st.strand == 1)
{
if (st.pp.PBS + st.pp.PPT + (st.tsr_len > 0) < 2)
continue;
}
else if (st.strand == 2)
{
if (st.pp._PBS + st.pp._PPT + (st.tsr_len > 0) < 2)
continue;
}
else
continue; //no strand? not output
}
result_count++;
if (fig.good())
{
fig << st.pos1 + 1 << "," << st.end1 + 1 << ";" << st.pos2 + 1 << "," << st.end2 + 1 << "\t";
fig << setprecision(3);
fig << "[" << result_count << "]LTR(" << " +-?"[st.strand] << ") score:" << st.score << "(" << st.match_score << ")\t";
FigOutputMotif(st.motif, "RT", st.strand == 1, fig, "RT"); //RT
FigOutputMotif(st.motif, "PS50994", st.strand == 1, fig, "IN(core)"); //IN Core
FigOutputMotif(st.motif, "PS51027", st.strand == 1, fig, "IN(c-term)"); //IN C term
FigOutputMotif(st.motif, "PS50879", st.strand == 1, fig, "RH"); //RNaseH
if (st.strand == 1 && st.pp.PBS)
fig << st.pp.PBS_begin + 1 << "," << st.pp.PBS_end + 1 << ",PBS;";
else if (st.strand == 2 && st.pp._PBS)
fig << st.pp._PBS_begin + 1 << "," << st.pp._PBS_end + 1 << ",PBS;";
if (st.strand == 1 && st.pp.PPT)
fig << st.pp.PPT_begin + 1 << "," << st.pp.PPT_begin + PPT_window << ",PPT;";
else if (st.strand == 2 && st.pp._PPT)
fig << st.pp._PPT_begin + 1 << "," << st.pp._PPT_begin + PPT_window << ",PPT;";
/* output flank bases
int begin=st.pos1-5;
int end=st.pos1-1;
if(begin<0) begin=0;
if(end>strlen(myString)) end=strlen(myString)-1;
fig<<begin+1<<","<<end+1<<",";
for(int k=begin;k<=end;++k)
fig<<myString[k];
fig<<"|"<<myString[st.pos1]<<myString[st.pos1+1];
fig<<";";
begin=st.end2+1;
end=st.end2+5;
if(begin<0) begin=0;
if(end>strlen(myString)) end=strlen(myString)-1;
fig<<begin+1<<","<<end+1<<",";
fig<<myString[st.end2-1]<<myString[st.end2]<<"|";
for(int k=begin;k<=end;++k)
fig<<myString[k];
fig<<";";
*/
//output TSR
if (st.tsr_len)
{
fig << st.pos1 - st.tsr_len + 1 << "," << st.pos1 - 1 + 1 << ",TSR;";
fig << st.end2 + 1 + 1 << "," << st.end2 + st.tsr_len + 1 << ",TSR;";
}
fig << endl;
}
if (wrought == 2) //table output
{
string TSR = "N";
if (st.tsr_len)
{
TSR = "";
for (int i = st.tsr_pos1;i < st.tsr_pos1 + st.tsr_len;++i)
TSR += myString[i];
}
char buf[1024];
//index,name,LTR region,LTR len,TG,CA,TSR,Score
sprintf(buf, "[%2d]\t%s\t%d-%d\t%d,%d\t%d\t%s\t",
result_count, name, st.pos1 + 1, st.end2 + 1, st.len1, st.len2, st.end2 - st.pos1 + 1,
TSR.c_str());
cout << buf;
if (st.strand == 1) //forward strand
{
if (st.pp.PBS)
cout << st.pp.PBS_begin + 1 << "-" << st.pp.PBS_end + 1 << "\t";
else
cout << "N-N\t";
if (st.pp.PPT)
cout << st.pp.PPT_begin + 1 << "-" << st.pp.PPT_begin + PPT_window << "\t";
else
cout << "N-N\t";
}
else if (st.strand == 2)
{
if (st.pp._PBS)
cout << st.pp._PBS_begin + 1 << "-" << st.pp._PBS_end + 1 << "\t";
else
cout << "N-N\t";
if (st.pp._PPT)
cout << st.pp._PPT_begin + 1 << "-" << st.pp._PPT_begin + PPT_window << "\t";
else
cout << "N-N\t";
}
else
{
cout << "N-N\tN-N\t";
}
TableOutputMotif(st.motif, "RT", st.strand == 1); //RT
TableOutputMotif(st.motif, "PS50994", st.strand == 1); //IN Core
TableOutputMotif(st.motif, "PS51027", st.strand == 1); //IN C term
TableOutputMotif(st.motif, "PS50879", st.strand == 1); //RNaseH
if (st.strand == 1)
cout << "+\t";
else if (st.strand == 2)
cout << "-\t";
else
cout << "?\t";
cout << setprecision(3);
cout << st.score << "\t" << st.sharpness5 << "," << st.sharpness3;
cout << setprecision(3);
cout << "\t" << st.match_score;
cout << endl;
continue;
}
cout << "[" << result_count << "] " << name << " Len:" << stringLength << endl;
cout << "Location : " << st.pos1 + 1 << " - " << st.end2 + 1 << " Len: " << st.end2 - st.pos1 + 1 << " Strand:";
if (st.strand == 1)
cout << "+" << endl;
else if (st.strand == 2)
cout << "-" << endl;
else if (st.strand == 3)
cout << "+/-" << endl;
else
cout << "?" << endl;
cout << setprecision(3);
cout << "Score : " << st.score << " [LTR region similarity:" << st.match_score << "]" << endl;
cout << "Status : " << dec2bin(st.status) << endl;
cout << "5'-LTR : " << st.pos1 + 1 << " - " << st.end1 + 1 << " Len: " << st.len1 << endl;
cout << "3'-LTR : " << st.pos2 + 1 << " - " << st.end2 + 1 << " Len: " << st.len2 << endl;
if (st.tg_pos1 >= 0)
{
cout << "5'-TG : " << myString[st.tg_pos1] << myString[st.tg_pos1 + 1] << " , "
<< myString[st.tg_pos2] << myString[st.tg_pos2 + 1] << endl;
}
else
cout << "5'-TG : NOT FOUND\n";
if (st.ca_pos2 >= 0)
{
cout << "3'-CA : " << myString[st.ca_pos1] << myString[st.ca_pos1 + 1] << " , "
<< myString[st.ca_pos2] << myString[st.ca_pos2 + 1] << endl;
}
else
cout << "3'-CA : NOT FOUND\n";
if (st.tsr_len)
{
cout << "TSR : " << st.tsr_pos1 + 1 << " - "
<< st.tsr_pos1 + st.tsr_len << " , "
<< st.tsr_pos2 + 1 << " - "
<< st.tsr_pos2 + st.tsr_len //<<" Len:"<<st.tsr_len<<endl;
<< " [";
outstr(myString, st.tsr_pos1, st.tsr_len);
cout << "]" << endl;
}
else
{
cout << "TSR : NOT FOUND" << endl;
}
cout << setprecision(3);
cout << "Sharpness: " << st.sharpness5 << "," << st.sharpness3 << endl;
cout << st.strand_str << endl;
if (wrought)
continue;
//output pairs
cout << "Details of exact match pairs:\n";
for (int j = 0;j < st.candi.size();++j)
{
if (j > 0)
cout << " (" << st.candi[j].pos2 - (st.candi[j - 1].pos2 + st.candi[j - 1].len) << ") ";
cout << st.candi[j].pos2 + 1 << "-" << st.candi[j].pos2 + st.candi[j].len << "[" << st.candi[j].len << "]";
}
cout << endl;
for (int j = 0;j < st.candi.size();++j)
{
if (j > 0)
cout << " (" << st.candi[j].pos1 - (st.candi[j - 1].pos1 + st.candi[j - 1].len) << ") ";
cout << st.candi[j].pos1 + 1 << "-" << st.candi[j].pos1 + st.candi[j].len << "[" << st.candi[j].len << "]";
}
cout << endl << endl;
//output detail
cout << "Details of the LTR alignment(5'-end):" << endl;
cout << st.LTR5;
cout << "Details of the LTR alignment(3'-end):" << endl;
cout << st.LTR3;
if (st.strand & 1) //1 or 3
{
if (st.pp.PBS)
{
cout << "Details of the PBS alignment(+):" << endl;
cout << "tRNA type: " << st.pp.PBS_name << endl;
cout << st.pp.pbs_str << endl;
cout << "|" << st.pp.PBS_begin + 1 << endl << endl;
}
if (st.pp.PPT)
{
cout << "Details of PPT(+):\n";
outstr(myString, st.pp.PPT_begin, PPT_window);
cout << endl;
cout << "|" << st.pp.PPT_begin + 1 << endl << endl;
}
}
if (st.strand & 2) //1 or 3
{
if (st.pp._PBS)
{
cout << "Details of the PBS alignment(-):" << endl;
cout << "tRNA type: " << st.pp._PBS_name << endl;
cout << st.pp._pbs_str << endl;
cout << "|" << st.pp._PBS_begin + 1 << endl << endl;
}
if (st.pp._PPT)
{
cout << "Details of PPT(-):\n";
outstr(myString, st.pp._PPT_begin, PPT_window);
cout << endl;
cout << "|" << st.pp._PPT_begin + 1 << endl << endl;
}
}
//cout<<endl;
}
if (result_count == 0)
cout << "No LTR Retrotransposons Found\n";
return result_count;
}
int main (int argc, char *argv[])
{
char *myString;
int stringLength;
int i;
string namePattern = "";
char *version = "1.06";
bool display_usage = false;
char c;
CPSSCAN ps_scan;
PBS pbs;
PPT ppt(PPT_window, 4);
char *tRNA_file = NULL;
char *ps_dir = NULL;
bool ishtml = false;
struct re_pattern_buffer id_filter;
id_filter.allocated = 0;
id_filter.buffer = 0;
id_filter.fastmap = 0;
id_filter.translate = 0;
Timing timehere;
Timing timeall;
timeall.markbeg();
while ((c = getopt (argc, argv, "ho:t:e:m:u:D:d:L:l:p:s:cw:S:a:P:g:F:B:b:J:j:O:r:M:f:xEiCG:T:")) > 0)
{
switch (c)
{
case 'h':
display_usage = true;
break;
case 'o':
gap_open = atoi (optarg);
break;
case 't':
gap_ext = atoi (optarg);
break;
case 'e':
gap_end = atoi (optarg);
break;
case 'm':
score_match = atoi (optarg);
break;
case 'u':
score_mismatch = atoi (optarg);
break;
case 'D':
Dmax = atoi (optarg);
break;
case 'd':
Dmin = atoi (optarg);
break;
case 'L':
Lmax = atoi (optarg);
break;
case 'l':
Lmin = atoi (optarg);
break;
case 'p':
Lex = atoi (optarg);
break;
case 'c':
CHECK_PAIRS = 1;
break;
case 'x':
ishtml = true;
break;
case 'E':
edge_signal = true;
break;
case 'i':
showPairNum = true;
break;
case 'w':
wrought = atoi(optarg);
break;
case 'P':
namePattern = optarg;
break;
case 'F':
Filter = optarg;
break;
case 'g':
MaxGap = atoi(optarg);
break;
case 'O':
outAlignLen = atoi(optarg);
break;
case 'G':
max_sub_rt_gap = atoi(optarg);
break;
case 'T':
min_sub_rt_count = atoi(optarg);
break;
case 'r':
PBS_minLen = atoi(optarg);
break;
case 'j':
JoinThreshold = atof(optarg);
break;
case 'J':
SplitThreshold = atof(optarg);
break;
case 'S':
minOutScore = atof(optarg);
break;
case 'B':
HigherSharpness = atof(optarg);
break;
case 'b':
LowerSharpness = atof(optarg);
break;
case 'M':
minMatchSim = atof(optarg);
break;
case 's':
tRNA_file = optarg;
break;
case 'a':
ps_dir = optarg;
break;
case 'f':
fig_file = optarg;
break;
case 'C':
checkCentriole = true;
break;
default:
display_usage = true;
// case 'm': show_score_matrix(); break;
}
}
if (optind >= argc || display_usage)
{
fprintf (stderr, "ltr_finder v%s\n", version);
fprintf (stderr, "Usage : [options] <INPUT_FASTA_FILE>\n");
// fprintf (stderr, "Options: -b NUM bandwidth, default is %d\n",
// band_width);
fprintf (stderr,
" -o NUM gap open penalty, default is %d\n",
gap_open);
fprintf (stderr,
" -t NUM gap extension penalty, default is %d\n",
gap_ext);
fprintf (stderr,
" -e NUM gap end penalty, default is %d\n",
gap_end);
fprintf (stderr, " -m NUM match score, default is %d\n",