-
Notifications
You must be signed in to change notification settings - Fork 2
/
TR_generate_v3.py
1835 lines (1691 loc) · 85.1 KB
/
TR_generate_v3.py
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
import sys
import os
import os.path
import re
import argparse
root_dir=os.getcwd()
##########################################################################
##########################################################################
#parse the arguments
parser = argparse.ArgumentParser(description="TR pipline v3.0")
parser.add_argument('--project',help='project name, maybe same with the name of root dir, which will be displayed in the final report title, [REQUIRED]',required=True)
parser.add_argument('--sample',help="sample names(sample1,sample2,...) warning: order sensitive!",required=True)
parser.add_argument('--fq',help="the original directory of the raw fastq reads, [REQUIRED]",default=None)
parser.add_argument('--mapfile',help="mapfile files (mapfile1,mapfile2.The first column of mapfile is the NH number ,the second column of mapfile is the sample name)",default=None)
parser.add_argument('--raw_dir',help="the original directory of the raw fastq reads keep order in line with mapfile files (raw_dir1,raw_dir2)",default=None)
parser.add_argument('--ad',help="the original directory of the adapter list, ",default=None)
parser.add_argument('--generate_adapter',help='whether to generate the adpepter list y or n',choices=['y','n'],default='n')
parser.add_argument('--index',help='the index number of the fastq files,if you want to generate the adapter list,the parameter will be necessary,diffrent samples split by ,warning: order sensitive!',default=None)
parser.add_argument('--ss',help="strand specific, [REQUIRED]",choices=['no','yes','reverse'],required=True)
parser.add_argument('--number',help="chromosome number, [REQUIRED for density plot]",required=True)
parser.add_argument('--length',help="the length of sequenced reads,[defalut=100]",default='100')
parser.add_argument('--fa',help="the reference FASTA file, [REQUIRED for mapping]",required=True)
parser.add_argument('--gtf',help="the annotation GTF file, [REQUIRED for mapping]",required=True)
parser.add_argument('--group',help="sample classification, e.g. sample1/sample2,sample3, [REQUIRED]",default=None)
parser.add_argument('--groupname',help="group names, [group1,group2,... ]",default=None)
parser.add_argument('--compare',help="group comparison strategy 1:2,1:3,..., [REQUIRED]",default=None)
parser.add_argument('--venn',help="venn and cluster mode, defult is all groups, 1:2_1:3,1:3_2:3,... ",default=None)
parser.add_argument('--goann',help="gene to GO annotations file, [REQUIRED]",default=None)
parser.add_argument('--species',help="abbreviation for species, for kegg pathway. (note: all species: /PUBLIC/database/RNA//kobas2.0-data-20120208/seq_pep_v2), [defalut=kaas]",default='kaas')
parser.add_argument('--ppi_number',help="species code, (ref file: /PUBLIC/database/RNA/string_ppi/species.v9.0.txt)",default=None)
parser.add_argument('--ppi_blast',help="whether to run blast to get the protein-protein interactions",choices=['y','n'],default=None)
parser.add_argument('--genenamefile',help="genenamefile, 1st col is geneID, 2nd col is genename",default=None)
parser.add_argument('--ex',help="the steps you do not wanna perform",default=None)
def checkSample(sample):
PatChar = r'^(CON|PRN|AUX|CLOCK\$|NUL|COM[1-9]|LPT1|[\W]+)$'
PatNum = r'^\d+'
MAXLEN = 8
message = '''can only use word/digit/underscore in sample, start with word.
Max length is 8, no windows reserved words like CON PRN...'''
if re.search(PatChar,sample) or re.search(PatNum,sample) or len(sample) > MAXLEN:
print '%s<==invalid name' % s
print message
exit()
argv = vars(parser.parse_args())
project=argv['project'].strip()
sample=argv['sample'].strip()
samples=sample.split(',')
samples_tmp=list(set(samples))
for s in samples:
checkSample(s)
assert len(samples)==len(samples_tmp)
#-----------------------------------------------------------------------
mapfiles=[each.strip() for each in argv['mapfile'].strip().split(',') if each.strip() != '']
mapfile=' '.join(mapfiles)
assert not os.system('cat %s |sort -u |sed \'/^$/d\' >%s' % (mapfile,root_dir+'/libraryID'))
if argv['fq']:
fq = argv['fq'].strip()
fq = os.path.abspath(fq)
else:
assert not os.system('mkdir raw_data')
assert not os.system('perl /PUBLIC/source/RNA/RefRNA/ln_raw_data.pl %s %s pe raw_data' %(argv['mapfile'],argv['raw_dir']))
fq = root_dir + '/raw_data'
for each in samples:
fq_tmp1=fq+'/'+each+'_1.fq.gz'
fq_tmp2=fq+'/'+each+'_2.fq.gz'
assert os.path.isfile(fq_tmp1)
assert os.path.isfile(fq_tmp2)
if argv['ad']:
ad = argv['ad'].strip()
ad = os.path.abspath(ad)
for each in samples:
ad_tmp1=ad+'/'+each+'_1.adapter.list.gz'
ad_tmp2=ad+'/'+each+'_2.adapter.list.gz'
assert os.path.isfile(ad_tmp1)
assert os.path.isfile(ad_tmp2)
if argv['generate_adapter']:
generate_adapter = argv['generate_adapter'].strip()
else:
generate_adapter = 'n'
if argv['index']:
index=argv['index'].strip()
indexes=index.split(',')
assert len(samples)==len(indexes)
if generate_adapter == 'y':
if argv['ad'] !=None:
print 'Error: the parameters --ad and --generate_adapter are not consensus!\n'
exit()
if argv['index']==None:
print 'Error: the parameters --index and --generate_adapter are not consensus!\n'
exit()
else:
if argv['index'] != None:
print 'Error: the parameters --index and --generate_adapter are not consensus!\n'
exit()
#-----------------------------------------------------------------------
all_content=set([1,2,3,4,5,6,7,8,9])
if argv['ex'] != None:
excludes=argv['ex'].strip().strip(',').strip().split(',')
excludes=[int(each.strip()) for each in excludes]
for each1 in excludes:
assert each1 in all_content
else:
excludes=[] #list
if argv['group'].find(':') == -1:
excludes.append(3)
if ( len(argv['group'].split(',') ) == 1) or (5 in excludes):
excludes.extend([7,8,9])
includes=all_content-set(excludes) #set
#-----------------------------------------------------------------------
ss = argv['ss'].strip()
number = argv['number'].strip()
if argv['length']:
length = argv['length'].strip()
else:
length = '100'
fa = argv['fa'].strip()
fa = os.path.abspath(fa)
suffix_fa=['.1.bt2','.2.bt2','.3.bt2','.4.bt2','.rev.1.bt2','.rev.2.bt2']
for each in suffix_fa:
fa_tmp=fa+each
assert os.path.isfile(fa_tmp)
gtf = argv['gtf'].strip()
gtf = os.path.abspath(gtf)
assert os.path.isfile(gtf)
#-----------------------------------------------------------------------
if (set([1]).issubset(includes)):
if argv['group'] == None:
groups=samples
groups_iter=samples
group=sample
flag_repeat=False
else:
groups_iter=[]
if ':' in argv['group'].strip(':'):
flag_repeat=True
groups=[each.strip().split(':') for each in argv['group'].strip().strip(':').split(',') if each.strip() != '']
for each in groups:
groups_iter+=each
group_iter_n=[]
for each in groups_iter:
if each not in group_iter_n:
group_iter_n.append(each)
groups_iter=group_iter_n
group=','.join([':'.join(each) for each in groups])
else:
flag_repeat=False
groups=[each.strip() for each in argv['group'].strip().split(',') if each.strip() != '']
for each in groups:
groups_iter.append(each)
group=','.join(groups)
assert set(groups_iter).issubset(samples)
group_iter=','.join(groups_iter)
if argv['groupname'] == None:
if flag_repeat == False:
groupname_tmp=groups
else:
groupname_tmp=['group'+str(k+1) for k in range(len(groups))]
else:
groupname_tmp=[each.strip() for each in argv['groupname'].split(',') if each.strip() != '']
assert len(groupname_tmp) == len(groups)
groupname=','.join(groupname_tmp)
compare = argv['compare'].strip()
compare_samples=[each.strip().split(':') for each in argv['compare'].strip().split(',') if each.strip() != '']
M=[]
for each1 in compare_samples:
assert len(each1) == 2
for each2 in each1:
assert each2.isdigit()
M.append(int(each2))
assert max(M) <= len(groupname_tmp)
assert min(M) > 0
compare_sample=','.join([','.join(each) for each in compare_samples])
temp2=[]
for each1 in compare_samples:
temp1=[]
for each2 in each1:
temp1.append(groupname_tmp[int(each2)-1])
temp2.append(':'.join(temp1))
compares_name=','.join(temp2)
if argv['venn']:
venn = argv['venn'].strip()
com_pairs=compare.split(',')
venn_clusters=[each.split('_') for each in venn.split(',')]
temp1=[]
for each1 in venn_clusters:
temp2=[]
for each2 in each1:
assert each2 in com_pairs
temp3=each2.split(':')
assert len(temp3) == 2
temp2.append(groupname_tmp[int(temp3[0])-1]+':'+groupname_tmp[int(temp3[1])-1])
temp1.append('_'.join(temp2))
venn_cluster_name=','.join(temp1)
else:
venn = compare.replace(',','_')
venn_cluster_name=compares_name.replace(',','_')
groups=group.split(',')
groupnames=groupname.split(',')
compares=compare.split(',')
venns=venn.split(',')
for each in groups:
temp=each.split(':')
assert len(temp)==len(list(set(temp)))
for each2 in temp:
assert each2 in samples
assert len(groups)==len(groupnames)
assert len(groupnames)==len(list(set(groupnames)))
for i,each in enumerate(groupnames):
group_tmp=groups[i]
group_tmp=group_tmp.replace(':',',')
compare_name=[]
for i,each in enumerate(compares):
compare_tmp=each
compare_tmp=compare_tmp.split(':')
assert len(compare_tmp)==2
compare_name=groupnames[int(compare_tmp[0])-1]+'vs'+groupnames[int(compare_tmp[1])-1]
for i,each in enumerate(venns):
venn_tmp=each
venn_tmp=venn_tmp.split('_')
for each2 in venn_tmp:
assert each2 in compares
venn_tmp2=each2.split(':')
venn_name=groupnames[int(venn_tmp2[0])-1]+'vs'+groupnames[int(venn_tmp2[1])-1]
#-----------------------------------------------------------------------
goann = argv['goann'].strip()
goann = os.path.abspath(goann)
species = ppi_number = ppi_blast = ''
assert os.path.isfile(goann)
if set([4,5,8]).issubset(includes):
if argv['species']:
species = argv['species'].strip()
else:
species = 'kaas'
if set([4,5,9]).issubset(includes):
if argv['ppi_number']:
ppi_number = argv['ppi_number'].strip()
if argv['ppi_blast']:
ppi_blast = argv['ppi_blast'].strip()
if argv['ppi_blast']:
if argv['ppi_number'] == None:
print 'Error: the parameters --ppi_blast and --ppi_number are not consensus!\n'
exit()
else:
if argv['ppi_number']:
print 'Error: the parameters --ppi_blast and --ppi_number are not consensus!\n'
exit()
if argv['genenamefile']:
genenamefile = argv['genenamefile'].strip()
genenamefile = os.path.abspath(genenamefile)
assert os.path.isfile(genenamefile)
##display all parameters##
display = open(root_dir + '/' + 'TR_command.txt','w')
display.write('project: %s\n' % (project))
display.write('sample: %s\n' % (sample))
display.write('fq: %s\n' % (fq))
display.write('adapter: ')
if argv['ad']:
display.write('%s\n' % (argv['ad'].rstrip()))
if argv['generate_adapter']:
generate_adapter = argv['generate_adapter']
display.write('generate_adapter: %s\n' % (generate_adapter))
if argv['index']:
indexes = argv['index'].rstrip().split(',')
for i,index_tmp in enumerate(samples):
display.write('%s:\t%s\n' % (index_tmp,indexes[i]))
display.write('\n')
display.write('length: %s\n' % (length))
display.write('fa: %s\n' % (fa))
display.write('gtf: %s\n' % (gtf))
display.write('\ngroups:\n')
for i,each in enumerate(groupnames):
group_tmp=groups[i]
group_tmp=group_tmp.replace(':',',')
display.write('%s: %s\n' % (each,group_tmp))
display.write('\ncompare:\n')
compare_name=[]
for i,each in enumerate(compares):
compare_tmp=each
compare_tmp=compare_tmp.split(':')
assert len(compare_tmp)==2
compare_name=groupnames[int(compare_tmp[0])-1]+'vs'+groupnames[int(compare_tmp[1])-1]
display.write('%s: \t' % (each))
display.write('%s\n' % (compare_name))
display.write('\nvenn:\n')
for i,each in enumerate(venns):
display.write('%s: \t' % (each))
venn_tmp=each.split('_')
for each2 in venn_tmp:
venn_tmp2=each2.split(':')
venn_name=groupnames[int(venn_tmp2[0])-1]+'vs'+groupnames[int(venn_tmp2[1])-1]
display.write('%s,' % (venn_name))
display.write('\n')
display.write('\n')
display.write('goann: %s\n' % (goann))
if species:
display.write('KEGG species: %s\n' % (species) )
display.write('PPI number: %s\n' % (ppi_number) )
display.write('PPI blast: %s\n' % (ppi_blast))
if argv['genenamefile']:
display.write('genenamefile: %s\n' % (genenamefile) )
display.close()
#################################################################################################
#for QC
code='''
import os
fq='%s'
ss='%s'
fa='%s'
gtf='%s'
sample='%s'
root_dir='%s'
''' % (fq,ss,fa,gtf,sample,root_dir)
if argv['ad']:
code+='''
ad='%s'
''' % (ad)
if generate_adapter != 'n':
code+='''
index='%s'
''' % (index)
if argv['mapfile']:
code+='''
mapfile='%s'
''' % (root_dir+'/libraryID')
code+='''
assert not os.system('mkdir QC_TR')
os.chdir('QC_TR')
f=open(root_dir+'/QC_TR/generate_QC.sh','w')
f.write('awk \\'{if($3==\\"exon\\"){print $0}}\\' %s > %s\\n' % (gtf,root_dir+'/QC_TR/exon.gtf'))
f.write('msort -k mf1 -k nf4 %s > %s\\n' % (root_dir+'/QC_TR/exon.gtf',root_dir+'/QC_TR/sorted.gtf'))
f.write('perl /PUBLIC/source/RNA/QC/QC_v2/gtf2bed.pl %s %s\\n' % (root_dir+'/QC_TR/sorted.gtf',root_dir+'/QC_TR/sorted.bed'))
f.write('perl /PUBLIC/source/RNA/QC/QC_v2/allrunQC_v2.1.pl -fq %s -se-pe pe -n %s -o %s -spe %s -R %s -G %s -bed %s ' %(fq,sample,root_dir+'/QC_TR',ss,fa,gtf,root_dir+'/QC_TR/sorted.bed'))
'''
if argv['mapfile']:
code+='''
f.write('-mapfile %s ' % (mapfile))
'''
if argv['ad']:
code+='''
f.write('-ad %s\\n' % (ad))
'''
if argv['index']:
code+='''
f.write('-m_ad y -index %s\\n' % (index))
'''
code+='''
f.write('\\n')
f.close()
assert not os.system('sh %s/generate_QC.sh' %(root_dir+'/QC_TR'))
samples=sample.split(',')
for eachsample in samples:
os.chdir(root_dir+'/QC_TR/'+eachsample)
assert not os.system('qsub -V -l vf=5g,p=8 -cwd %s' % (eachsample+'_QC.sh'))
os.chdir(root_dir)
'''
open('TR_step1_QC.py','w').write(code)
#################################################################################################
#for QCreport
code='''
import os
sample='%s'
project='%s'
root_dir='%s'
''' % (sample,project,root_dir)
code+='''
assert not os.system('mkdir QC_TR/QCreport')
os.system('sh /PUBLIC/source/RNA/QC/QC_v2/QCreport/TR_QCreport.sh -dir %s -sample %s -title %s -results %s' %(root_dir+'/QC_TR',sample,project,root_dir+'/QC_TR/QCreport'))
'''
open('TR_step1_QCreport.py','w').write(code)
#################################################################################################
#for CAN and SNP
code=''
code='''
import os
ss='%s'
sample='%s'
fa='%s'
gtf='%s'
bam='%s'
sam='%s'
group='%s'
groupname='%s'
goann='%s'
root_dir='%s'
''' % (ss,sample,fa,gtf,root_dir+'/QC_TR/bam',root_dir+'/QC_TR/sam',group,groupname,goann,root_dir)
if set([1]).issubset(includes):
code+='''
if ss == 'no':
lib='fr-unstranded'
elif ss == 'yes':
lib = 'fr-firststrand'
else:
lib = 'fr-secondstrand'
#for CAN
assert not os.system('mkdir CAN_TR')
os.chdir('CAN_TR')
f=open(root_dir+'/CAN_TR/generate_CAN.sh','w')
f.write('perl /PUBLIC/source/RNA/RefRNA/TransRef/scripts/runCAN.pl -R %s -G %s -i %s -sam %s -o %s -lib %s -group %s -groupname %s \\n' % (fa,gtf,bam,sam,root_dir+'/CAN_TR/CAN',lib,group,groupname))
f.write('sh %s/runCAN.sh\\n' % (root_dir+'/CAN_TR'))
novel_gtf=root_dir+'/CAN_TR/CAN/NovelGene/novelGene.gtf.xls'
f.write('perl /PUBLIC/source/RNA/RefRNA/TransRef/scripts/novelhmm.pl %s %s %s %s \\n' % (novel_gtf,fa,goann,root_dir+'/CAN_TR/CAN/NovelGene/GO'))
f.write('sh %s/novelhmm.sh\\n' % (root_dir+'/CAN_TR'))
f.close()
assert not os.system('qsub -V -l vf=5g,p=8 -cwd %s/generate_CAN.sh' % (root_dir+'/CAN_TR'))
os.chdir(root_dir)
'''
if set([1,2]).issubset(includes):
code+='''
#for SNP
assert not os.system('mkdir SNP_TR')
os.chdir('SNP_TR')
f=open(root_dir+'/SNP_TR/generate_SNP.sh','w')
f.write('perl /PUBLIC/source/RNA/RefRNA/TransRef/GATKsnp/runGATK2.1.pl -R %s -t bam -i %s -o %s -b %s -n %s -gff %s\\n' % (fa,bam,root_dir+'/SNP_TR/SNP',sample,sample,gtf))
f.write('mv %s/workflow.sh %s/workflow.sh\\n' % (root_dir+'/SNP_TR/SNP',root_dir+'/SNP_TR'))
f.close()
assert not os.system('sh %s' % (root_dir+'/SNP_TR/generate_SNP.sh'))
assert not os.system('qsub -V -l vf=10g,p=6 -cwd %s/workflow.sh' % (root_dir+'/SNP_TR'))
os.chdir(root_dir)
'''
open('TR_step2_CAN_SNP.py','w').write(code)
#################################################################################################
#for DEXSeq
code=''
if set([1,3]).issubset(includes):
code='''
import os
sam='%s'
group='%s'
groupname='%s'
compare='%s'
ss='%s'
allsamples_gtf='%s'
allsamples_tmap='%s'
root_dir='%s'
''' % (root_dir+'/QC_TR/sam',group,groupname,compare,ss,root_dir+'/CAN_TR/CAN/merged_gtf_tmap/allsamples.gtf',root_dir+'/CAN_TR/CAN/merged_gtf_tmap/allsamples.allsamples.gtf.tmap',root_dir)
DEXseq_groups=group.split(',')
for i,each in enumerate(DEXseq_groups):
DEXseq_groups[i]=DEXseq_groups[i].split(':')
DEXseq_compare=[]
DEXseq_compares=compare.split(',')
for each in DEXseq_compares:
temp=each.split(':')
tmp1=DEXseq_groups[int(temp[0])-1]
tmp2=DEXseq_groups[int(temp[1])-1]
tmp=tmp1+tmp2
if (len(DEXseq_groups[int(temp[0])-1])>1 and len(DEXseq_groups[int(temp[1])-1])>1 and len(list(set(tmp)))==len(tmp1)+len(tmp2)):
DEXseq_compare.append(each)
DEXseq_compare=','.join(DEXseq_compare)
code+='''
DEXseq_compare='%s'
assert not os.system('mkdir DEXseq_TR')
os.chdir('DEXseq_TR')
f=open(root_dir+'/DEXseq_TR/generate_DEXseq.sh','w')
f.write('/PUBLIC/software/public/System/Python-2.7.6/bin/python /PUBLIC/source/RNA/RefRNA/TransRef/DEXSeq/runDEXSeq_v2.py -G %%s -i %%s -g %%s -n %%s -c %%s -o %%s -p yes -s %%s -a 10 -m %%s \\n' %% (allsamples_gtf,sam,group,groupname,DEXseq_compare,root_dir+'/DEXseq_TR/DEXseq',ss,allsamples_tmap))
f.close()
assert not os.system('sh %%s' %% (root_dir+'/DEXseq_TR/generate_DEXseq.sh'))
assert not os.system('qsub -cwd -l vf=2G,p=1 -V runDEXSeq.sh')
os.chdir(root_dir)
''' % (DEXseq_compare)
open('TR_step3_DEXseq.py','w').write(code)
#################################################################################################
#for Diff analysis and Curves
code=''
code='''
import re
import os
sample='%s'
ss='%s'
gtf='%s'
group='%s'
groupname='%s'
compare='%s'
venn='%s'
fa='%s'
n='%s'
length='%s'
root_dir='%s'
''' % (sample,ss,root_dir+'/CAN_TR/CAN/NovelGene/novelcombined.gtf',group,groupname,compare,venn,fa,number,length,root_dir)
if argv['genenamefile']:
code+='''
genenamefile='%s'
''' % (genenamefile)
if set([1,5]).issubset(includes):
code+='''
##Diff
sam=root_dir+'/QC_TR/sam'
samples = sample.split(',')
readcount=[]
for eachsample in samples:
temp='%s/Diff_TR/readcount/%s.readcount' % (root_dir,eachsample)
readcount.append(temp)
readcount=','.join(readcount)
assert not os.system('mkdir Diff_TR')
os.chdir('Diff_TR')
f=open(root_dir+'/Diff_TR/generate_Diff.sh','w')
f.write('perl /PUBLIC/source/RNA/RefRNA/DGE/DiffExpression/runDiff_analysis_v2.2.pl -fa %s -sam %s -g %s -o %s -group %s -groupname %s -compare %s -venn %s -spe %s -i %s ' % (fa,sam,gtf,root_dir+'/Diff_TR',group,groupname,compare,venn,ss,readcount))
'''
if argv['genenamefile']:
code+='''
f.write(' -genenamefile %s ' % (genenamefile))
'''
code+='''
f.write('\\n')
f.close()
assert not os.system('sh generate_Diff.sh')
assert not os.system('qsub -V -cwd -l vf=5G -l p=1 runDiff_analysis.sh')
os.chdir(root_dir)
'''
if set([1,4,6]).issubset(includes):
code+='''
##Curve
bam=root_dir+'/QC_TR/bam'
assert not os.system('mkdir Curve_TR')
os.chdir('Curve_TR')
f=open(root_dir+'/Curve_TR/generate_Curve.sh','w')
f.write('perl /PUBLIC/source/RNA/RefRNA/DGE/Curve/runCurve_v2.pl -bam %s -sample %s -n %s -r %s -fa %s -gtf %s -o %s\\n' % (bam,sample,n,length,fa,gtf,root_dir+'/Curve_TR'))
f.close()
assert not os.system('sh generate_Curve.sh')
assert not os.system('qsub -V -cwd -l vf=10G -l p=1 runSaturation.sh')
assert not os.system('qsub -V -cwd -l vf=5G -l p=1 rundensity.sh')
os.chdir(root_dir)
'''
open('TR_step4_Diff_Curves.py','w').write(code)
#################################################################################################
#for Enrichment and PPI
code='''
import os
fa='%s'
goann='%s'
groupname='%s'
compare='%s'
root_dir='%s'
''' % (fa,root_dir+'/CAN_TR/CAN/NovelGene/GO/gene.go',groupname,compare,root_dir)
code+='''
groupnames=groupname.split(',')
compares=compare.split(',')
'''
if set([1,4,5,7]).issubset(includes):
code+='''
##GOSeq
assert not os.system('mkdir GOSeq_TR')
os.chdir('GOSeq_TR')
go=open(root_dir+'/GOSeq_TR/runGOSeq.sh','w')
for each in compares:
temp=each.split(':')
dir=groupnames[int(temp[0])-1]+'vs'+groupnames[int(temp[1])-1]
id=root_dir+'/Diff_TR/Diff/'+dir+'/'+dir+'.diffgeneID'
out=root_dir+'/GOSeq_TR/'+dir
length=root_dir+'/Diff_TR/Diff/genelength'
result=root_dir+'/GOSeq_TR/'+dir+'/'+dir+'.GO_enrichment_result.xls'
diff=root_dir+'/Diff_TR/Diff/'+dir+'/'+dir+'.diffgene.xls'
go.write('###############%s#####################\\n' % (dir))
go.write('mkdir %s\\n' % (root_dir+'/GOSeq_TR/'+dir))
go.write('perl /PUBLIC/source/RNA/RefRNA/DGE/Enrichment/goseq_graph_v3.pl -i %s -goann %s -n %s -o %s -length %s\\n' % (id,goann,dir,out,length))
go.write('perl /PUBLIC/source/RNA/RefRNA/DGE/Enrichment/changeGO_up_down.pl %s %s %s\\n' % (result,diff,root_dir+'/GOSeq_TR/'+dir+'/'+dir+'.GO_enrichment_result_up_down.xls'))
go.write('/PUBLIC/software/public/System/R-2.15.3/bin/Rscript /PUBLIC/source/RNA/RefRNA/DGE/Enrichment/goBar.R %s %s %s\\n' % (result,out,dir))
go.write('/PUBLIC/software/public/System/R-2.15.3/bin/Rscript /PUBLIC/source/RNA/RefRNA/DGE/Enrichment/goBar2.R %s %s %s\\n' % (root_dir+'/GOSeq_TR/'+dir+'/'+dir+'.GO_enrichment_result_up_down.xls',out,dir))
go.close()
assert not os.system('qsub -V -cwd -l vf=5G -l p=1 runGOSeq.sh')
os.chdir(root_dir)
'''
if set([1,4,5]).issubset(includes) and argv['genenamefile'] == None:
code+='''
assert not os.system('mkdir Blast_TR')
os.chdir('Blast_TR')
f=open(root_dir+'/Blast_TR/runBlast_swissprot.sh','w')
query=root_dir+'/Diff_TR/Diff/diffgene_union.seq'
outdir1=root_dir+'/Blast_TR/Blast_Swissprot/'
out=root_dir+'/Blast_TR/Blast_Swissprot/diffgene_union.seq.blastout'
f.write('echo start blastx\\ndate\\n')
f.write('mkdir %s\\n' % (outdir1))
f.write('/PUBLIC/software/public/Alignment/ncbi-blast-2.2.28+/bin/blastx -query %s -db /PUBLIC/database/Common/SwissProt/uniprot_sprot.fasta -evalue 1e-5 -outfmt 5 -max_target_seqs 1 -num_threads 10 -out %s\\n' % (query,out))
f.write('echo blastx end\\ndate\\n')
f.write('perl /PUBLIC/source/RNA/RefRNA/DGE/scriptdir/extractIDsEVxml.pl %s %s\\n' % (out,outdir1+'/diffgene_union.genenames'))
compare=root_dir+'/Diff_TR/Diff/compare.txt'
indir=root_dir+'/Diff_TR/Diff/'
outdir2=root_dir+'/Diff_TR/Diff/DiffGeneList'
f.write('mkdir %s\\n' % (outdir2))
f.write('perl /PUBLIC/source/RNA/RefRNA/DGE/scriptdir/getdiffGN.up_down_v2.pl %s %s %s %s\\n' % (indir,compare,outdir1+'/diffgene_union.genenames',outdir2))
f.close()
assert not os.system('qsub -V -cwd -l vf=5G -l p=10 runBlast_swissprot.sh')
os.chdir(root_dir)
'''
if set([1,4,5,8]).issubset(includes):
code+='''
species='%s'
''' % (species)
if argv['species'] == 'kaas':
code+='''
##KOBAS
assert not os.system('mkdir KOBAS_TR')
os.chdir('KOBAS_TR')
ko=open(root_dir+'/KOBAS_TR/runKOBAS.sh','w')
path=open(root_dir+'/KOBAS_TR/runpathway.sh','w')
query=root_dir+'/Diff_TR/Diff/diffgene_union.seq'
blastout=root_dir+'/Blast_TR/KOBAS_blast.xml'
ko.write('###############Run kaas#####################\\n')
ko.write('/PUBLIC/software/public/Annotation/kaas_sa2/bin/auto_annotate.pl -n -s %s\\n' % (query))
ko.write('python /PUBLIC/software/RNA/gene_annotation/scripts/convert2kobas_v1.py %s /PUBLIC/database/Common/KEGG/kos %s\\n' % (root_dir + '/Diff_TR/Diff/diffgene_union.seq.ko',root_dir + '/KOBAS_TR/koID.annotation'))
for each in compares:
temp=each.split(':')
dir=groupnames[int(temp[0])-1]+'vs'+groupnames[int(temp[1])-1]
id=root_dir+'/Diff_TR/Diff/'+dir+'/'+dir+'.diffgeneID'
out=root_dir+'/KOBAS_TR/'+dir
ko.write('###############%s#####################\\n' % (dir))
path.write('echo "###############%s#####################"\\n' % (dir))
path.write('cd %s\\n' % (out))
result=root_dir+'/KOBAS_TR/'+dir+'/'+'add.'+dir+'.identify.xls'
diff=root_dir+'/Diff_TR/Diff/'+dir+'/'+dir+'.diffgene.xls'
diffID=root_dir+'/Diff_TR/Diff/'+dir+'/'+dir+'.diffgeneID'
path.write('python /PUBLIC/source/RNA/RefRNA/DGE/KEGG_Enrichment/bin/pathway_annotation_flow_parallel_annotationfault_tolerant3.pyc --table %s --diff %s\\n' % (result,diff))
path.write('mv %s %s\\n' % ('add.'+dir+'.identify.xls_rendered_html_detail.html',dir+'.html'))
ko.write('mkdir %s\\n' % (root_dir+'/KOBAS_TR/'+dir))
ko.write('cd %s\\n' % (root_dir+'/KOBAS_TR/'+dir))
ko.write('perl /PUBLIC/source/RNA/noRef/KEGG_enrichment/runKEGG_enrich.pl -diff %s -ko %s -g %s\\n' % (diffID,root_dir + '/KOBAS_TR/koID.annotation',dir))
path.close()
ko.close()
assert not os.system('qsub -V -cwd -l vf=5G -l p=10 runKOBAS.sh')
os.chdir(root_dir)
'''
else:
code+='''
##KOBAS
assert not os.system('mkdir KOBAS_TR')
os.chdir('KOBAS_TR')
ko=open(root_dir+'/KOBAS_TR/runKOBAS.sh','w')
path=open(root_dir+'/KOBAS_TR/runpathway.sh','w')
query=root_dir+'/Diff_TR/Diff/diffgene_union.seq'
blastout=root_dir+'/Blast_TR/KOBAS_blast.xml'
ko.write('###############Run Blast#####################\\n')
ko.write('mkdir %s\\n' % (root_dir+'/Blast_TR/'))
ko.write('perl /PUBLIC/source/RNA/RefRNA/DGE/KEGG_Enrichment/bin/KEGG_step1_blast.pl %s %s %s %s\\n' % (query,species,blastout,root_dir+'/Blast_TR/KOBAS_blast.sh'))
ko.write('sh %s\\n' % (root_dir+'/Blast_TR/KOBAS_blast.sh'))
for each in compares:
temp=each.split(':')
dir=groupnames[int(temp[0])-1]+'vs'+groupnames[int(temp[1])-1]
id=root_dir+'/Diff_TR/Diff/'+dir+'/'+dir+'.diffgeneID'
out=root_dir+'/KOBAS_TR/'+dir
ko.write('###############%s#####################\\n' % (dir))
path.write('echo "###############%s#####################"\\n' % (dir))
path.write('cd %s\\n' % (out))
result=root_dir+'/KOBAS_TR/'+dir+'/'+'add.'+dir+'.identify.xls'
diff=root_dir+'/Diff_TR/Diff/'+dir+'/'+dir+'.diffgene.xls'
path.write('python /PUBLIC/source/RNA/RefRNA/DGE/KEGG_Enrichment/bin/pathway_annotation_flow_parallel_annotationfault_tolerant3.pyc --table %s --diff %s\\n' % (result,diff))
path.write('mv %s %s\\n' % ('add.'+dir+'.identify.xls_rendered_html_detail.html',dir+'.html'))
ko.write('mkdir %s\\n' % (root_dir+'/KOBAS_TR/'+dir))
script=root_dir+'/KOBAS_TR/'+dir+'/run.sh'
ko.write('perl /PUBLIC/source/RNA/RefRNA/DGE/KEGG_Enrichment/bin/KEGG_step2_enrich.pl -id %s -out-dir %s -species %s -blast-result %s -sample-names %s>%s\\n' % (id,out,species,blastout,dir,script))
ko.write('sh %s\\n' % (script))
path.close()
ko.close()
assert not os.system('qsub -V -cwd -l vf=5G -l p=10 runKOBAS.sh')
os.chdir(root_dir)
'''
if set([1,4,5,9]).issubset(includes):
code+='''
ppi_number='%s'
ppi_blast='%s'
''' % (ppi_number,ppi_blast)
code+='''
##PPI
assert not os.system('mkdir PPI_TR')
os.chdir('PPI_TR')
ppi=open(root_dir+'/PPI_TR/runPPI.sh','w')
for each in compares:
temp=each.split(':')
dir=groupnames[int(temp[0])-1]+'vs'+groupnames[int(temp[1])-1]
id=root_dir+'/Diff_TR/Diff/'+dir+'/'+dir+'.diffgeneID'
seq=root_dir+'/Diff_TR/Diff/Diff_Gene_Seq/'+dir+'.diffgene.seq'
out=root_dir+'/PPI_TR/'+dir
ppi.write('mkdir %s\\n' % (out))
'''
if argv['ppi_blast'] == 'y':
code+='''
ppi.write('python /PUBLIC/source/RNA/RefRNA/DGE/Enrichment/BLASTX_TO_PPI_v4.py --species %s --fa %s --outdir %s --name %s\\n' % (ppi_number,seq,out,dir))
'''
else:
code+='''
ppi_dir='/PUBLIC/database/RNA/PPI_ref/PPI_99'
ppi.write('python /PUBLIC/source/RNA/RefRNA/DGE/Enrichment/get_my_PPI.py -p %s -g %s -o %s\\n' % (ppi_dir+'/PPI_'+ppi_number+'.txt',id,out+'/'+dir+'.ppi.txt'))
'''
code+='''
ppi.close()
assert not os.system('qsub -V -cwd -l vf=5G -l p=10 runPPI.sh')
os.chdir(root_dir)
'''
open('TR_step5_Enrichment.py','w').write(code)
#################################################################################################
#for Report
code='''
import re
import os
import os.path
import glob
import sys
import gzip
import linecache
reload(sys)
sys.setdefaultencoding('utf-8')
from django.template import Template, Context, loader
from django.conf import settings
settings.configure(DEBUG=True, TEMPLATE_DEBUG=True,TEMPLATE_DIRS=('/PUBLIC/source/RNA/RefRNA/Report/template/TR',))
fq='%s'
sample='%s'
groupname='%s'
compare='%s'
project='%s'
root_dir='%s'
ss='%s'
venn_cluster_name='%s'
flag_uniform=True
''' % (fq,sample,groupname,compare,project,root_dir,ss,venn_cluster_name)
code+='''
samples=sample.split(',')
##md5
dir=root_dir+'/QC_TR'
cd_md5=open(root_dir+'/QC_TR/cd_md5.sh','w')
rd_md5=open(root_dir+'/QC_TR/rd_md5.sh','w')
os.chdir(dir)
cd_md5.write('cd %s/cleandata\\n' % (dir))
cd_md5.write('echo -e \"md5\\tfile\">cd_md5.txt\\n')
rd_md5.write('echo -e \"md5\\tfile\">rd_md5.txt\\n')
for each in samples:
cd_md5.write('md5sum %s_1.clean.fq>>cd_md5.txt\\n' % (each))
cd_md5.write('md5sum %s_2.clean.fq>>cd_md5.txt\\n' % (each))
cd_md5.write('unlink %s_1.clean.fq\\n' %(each))
cd_md5.write('unlink %s_2.clean.fq\\n' %(each))
cd_temp1=root_dir+'/QC_TR/'+each+'/clean_data/'+each+'_1.clean.fq'
cd_temp2=root_dir+'/QC_TR/'+each+'/clean_data/'+each+'_2.clean.fq'
cd_md5.write('gzip %s\\n' % (cd_temp1))
cd_md5.write('gzip %s\\n' % (cd_temp2))
cd_md5.write('ln -s %s.gz %s\\n' % (cd_temp1,dir+'/cleandata/'))
cd_md5.write('ln -s %s.gz %s\\n' % (cd_temp2,dir+'/cleandata/'))
rd_md5.write('cd %s\\n' % (root_dir+'/QC_TR/'+each))
rd_md5.write('md5sum %s>>%srd_md5.txt\\n' % (each+'_1.fq.gz',root_dir+'/QC_TR/'))
rd_md5.write('md5sum %s>>%srd_md5.txt\\n' % (each+'_2.fq.gz',root_dir+'/QC_TR/'))
cd_md5.close()
rd_md5.close()
os.chdir(root_dir)
os.chdir(root_dir+'/QC_TR')
rdmd5=glob.glob('rd_md5.txt')
if not rdmd5:
assert not os.system('qsub -V -l vf=3g,p=1 -cwd rd_md5.sh')
os.chdir(root_dir+'/QC_TR/cleandata')
cdmd5=glob.glob('cd_md5.txt')
if not cdmd5:
os.chdir(root_dir+'//QC_TR')
assert not os.system('qsub -V -l vf=3g,p=1 -cwd cd_md5.sh')
os.chdir(root_dir)
'''
if set([1,4,5,8]).issubset(includes):
code+='''
##path
path=root_dir+'/KOBAS_TR/runpathway.sh'
assert not os.system('sh %s' % (path))
'''
code+='''
#results
assert not os.system('mkdir '+project+'_TR_result')
assert not os.system('mkdir '+project+'_TR_result/'+project+'_results')
assert not os.system('mkdir '+project+'_TR_result/'+project+'_report')
os.chdir(project+'_TR_result/'+project+'_results')
result_order=0
result_order+=1
assert not os.system('mkdir '+str(result_order)+'.OriginalData')
rd_order=str(result_order)
os.chdir(''+str(result_order)+'.OriginalData')
for eachsample in samples:
f_in=gzip.open(root_dir+'/QC_TR/'+eachsample+'/'+eachsample+'_1.fq.gz','rb')
f_out=[f_in.readline() for num in range(20)]
open(eachsample+'.example.fq.txt','w').writelines(f_out)
f_in.close()
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/OriginalData.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.OriginalData/'+str(result_order)+'.OriginalData.README.txt'))
os.chdir(root_dir+'/'+project+'_TR_result/'+project+'_results')
result_order+=1
assert not os.system('mkdir '+str(result_order)+'.QC')
qc_order=str(result_order)
os.chdir(''+str(result_order)+'.QC')
assert not os.system('mkdir '+str(result_order)+'.1.ErrorRate')
os.chdir(''+str(result_order)+'.1.ErrorRate')
for eachsample in samples:
assert not os.system('cp %s %s' % (root_dir+'/QC_TR/'+eachsample+'/clean_data/'+eachsample+'.Error.png',eachsample+'.error_rate_distribution.png'))
assert not os.system('cp %s %s' % (root_dir+'/QC_TR/'+eachsample+'/clean_data/'+eachsample+'.Error.pdf',eachsample+'.error_rate_distribution.pdf'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/Error.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.QC/'+str(result_order)+'.1.ErrorRate/'+str(result_order)+'.1ErrorRate.README.txt'))
os.chdir('..')
assert not os.system('mkdir '+str(result_order)+'.2.GC')
os.chdir(''+str(result_order)+'.2.GC')
for eachsample in samples:
assert not os.system('cp %s %s' % (root_dir+'/QC_TR/'+eachsample+'/clean_data/'+eachsample+'.GC.png',eachsample+'.GC_content_distribution.png'))
assert not os.system('cp %s %s' % (root_dir+'/QC_TR/'+eachsample+'/clean_data/'+eachsample+'.GC.pdf',eachsample+'.GC_content_distribution.pdf'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/GC.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.QC/'+str(result_order)+'.2.GC/'+str(result_order)+'.2GC.README.txt'))
os.chdir('..')
assert not os.system('mkdir '+str(result_order)+'.3.ReadsClassification')
os.chdir(''+str(result_order)+'.3.ReadsClassification')
for eachsample in samples:
assert not os.system('cp %s %s' % (root_dir+'/QC_TR/'+eachsample+'/files/'+eachsample+'.pie3d.png',eachsample+'.raw_reads_classification.png'))
assert not os.system('cp %s %s' % (root_dir+'/QC_TR/'+eachsample+'/files/'+eachsample+'.pie3d.pdf',eachsample+'.raw_reads_classification.pdf'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/Filter.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.QC/'+str(result_order)+'.3.ReadsClassification/'+str(result_order)+'.3ReadsClassification.README.txt'))
os.chdir('..')
assert not os.system('mkdir '+str(result_order)+'.4.DataTable')
os.chdir(''+str(result_order)+'.4.DataTable')
alldataTable = [ root_dir + '/QC_TR/' + sample + '/files/dataTable' for sample in samples]
alldataTable = ' '.join(alldataTable)
assert not os.system("cat %s|cut -f 1-8 > %s " % ( alldataTable ,'datatable.xls.1'))
assert not os.system('cat %s %s > %s' % ('/PUBLIC/source/RNA/RefRNA/DGE/Report/datatable','datatable.xls.1','datatable.xls'))
assert not os.system('rm %s' % ('datatable.xls.1'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/DataTable.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.QC/'+str(result_order)+'.4.DataTable/'+str(result_order)+'.4DataTable.README.txt'))
os.chdir(root_dir+'/'+project+'_TR_result/'+project+'_results')
result_order+=1
assert not os.system('mkdir '+str(result_order)+'.Mapping')
mp_order=str(result_order)
os.chdir(''+str(result_order)+'.Mapping')
assert not os.system('mkdir '+str(result_order)+'.1.MapStat')
os.chdir(''+str(result_order)+'.1.MapStat')
for eachsample in samples:
assert not os.system('cut -f 2 %s > %s' % (root_dir+'/QC_TR/'+eachsample+'/files/'+eachsample+'.stat',eachsample+'.stat.2'))
assert not os.system('cut -f 1 %s > %s' % (root_dir+'/QC_TR/'+samples[0]+'/files/'+samples[0]+'.stat','stat.1'))
allStat_2 = [ root_dir + '/' + project+'_TR_result/'+project+'_results/'+str(result_order)+'.Mapping/'+str(result_order)+'.1.MapStat/'+sample+'.stat.2' for sample in samples ]
allStat_2 = ' '.join(allStat_2)
assert not os.system('paste %s %s > %s' % ('stat.1',allStat_2,'MapStat.xls'))
assert not os.system("sed -i -e '/^Reads mapped in proper pairs/d' %s" % ('MapStat.xls'))
assert not os.system("sed -i -e '/^Proper-paired reads map to different chrom/d' %s" % ('MapStat.xls'))
assert not os.system('rm stat.1')
assert not os.system('rm *.stat.2')
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/MapStat.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.Mapping/'+str(result_order)+'.1.MapStat/'+str(result_order)+'.1MapStat.README.txt'))
os.chdir('..')
assert not os.system('mkdir '+str(result_order)+'.2.MapReg')
mr_order=str(result_order)
os.chdir(''+str(result_order)+'.2.MapReg')
for eachsample in samples:
assert not os.system('cp %s %s' % (root_dir+'/QC_TR/'+eachsample+'/files/'+eachsample+'.MR.png',eachsample+'.Mapped_Region.png'))
assert not os.system('cp %s %s' % (root_dir+'/QC_TR/'+eachsample+'/files/'+eachsample+'.MR.pdf',eachsample+'.Mapped_Region.pdf'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/MapReg.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.Mapping/'+str(result_order)+'.2.MapReg/'+str(result_order)+'.2MappedRegion.README.txt'))
os.chdir('..')
assert not os.system('mkdir '+str(result_order)+'.3.ChrDen')
cd_order=str(result_order)
os.chdir(''+str(result_order)+'.3.ChrDen')
for eachsample in samples:
assert not os.system('cp %s .' % (root_dir+'/Curve_TR/density/'+eachsample+'/'+eachsample+'.density.png'))
assert not os.system('cp %s .' % (root_dir+'/Curve_TR/density/'+eachsample+'/'+eachsample+'.density.pdf'))
assert not os.system('cp %s .' % (root_dir+'/Curve_TR/density/'+eachsample+'/'+eachsample+'.ReadsVSlength.png'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/ChrDen.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.Mapping/'+str(result_order)+'.3.ChrDen/'+str(result_order)+'.3ChrDen.README.txt'))
os.chdir('..')
assert not os.system('mkdir '+str(result_order)+'.4.IGV')
igv_order=str(result_order)
os.chdir(''+str(result_order)+'.4.IGV')
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/Report/IGVQuickStart.pdf %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.Mapping/'+str(result_order)+'.4.IGV'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/IGV.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.Mapping/'+str(result_order)+'.4.IGV/'+str(result_order)+'.4IGV.README.txt'))
os.chdir(root_dir+'/'+project+'_TR_result/'+project+'_results')
'''
if set([1]).issubset(includes):
code+='''
result_order+=1
assert not os.system('mkdir '+str(result_order)+'.AS')
as_order=str(result_order)
os.chdir(''+str(result_order)+'.AS')
assert not os.system('cp %s .' % (root_dir+'/CAN_TR/CAN/ASprofile/AS.png'))
assert not os.system('cp %s .' % (root_dir+'/CAN_TR/CAN/ASprofile/AS.pdf'))
for eachsample in samples:
assert not os.system('cp %s .' % (root_dir+'/CAN_TR/CAN/ASprofile/'+eachsample+'/'+eachsample+'.fpkm.xls'))
assert not os.system('cp %s .' % (root_dir+'/CAN_TR/CAN/ASprofile/ASevent.stat.xls'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/AS.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.AS/'+str(result_order)+'.AS.README.txt'))
os.chdir(root_dir+'/'+project+'_TR_result/'+project+'_results')
result_order+=1
assert not os.system('mkdir '+str(result_order)+'.NovelGene')
ng_order=str(result_order)
os.chdir(''+str(result_order)+'.NovelGene')
assert not os.system('cp %s .' % (root_dir+'/CAN_TR/CAN/NovelGene/novelGene.gtf.xls'))
assert not os.system('cp %s .' % (root_dir+'/CAN_TR/CAN/NovelGene/novelIsoform.gtf.xls'))
assert not os.system('cp %s .' % (root_dir+'/CAN_TR/CAN/NovelGene/geneStructOpt.xls'))
assert not os.system('cp %s .' % (root_dir+'/CAN_TR/CAN/NovelGene/GO/Novelgene.fa'))
assert not os.system('cp %s .' % (root_dir+'/CAN_TR/CAN/NovelGene/GO/Novelgene.pfam.txt'))
assert not os.system('cp %s .' % (root_dir+'/CAN_TR/CAN/NovelGene/GO/Novelgene.hmm_go.txt'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/NovelGene.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.NovelGene/'+str(result_order)+'.NovelGene.README.txt'))
os.chdir(root_dir+'/'+project+'_TR_result/'+project+'_results')
'''
if set([1,2]).issubset(includes):
code+='''
result_order+=1
assert not os.system('mkdir '+str(result_order)+'.SNP')
snp_order=str(result_order)
os.chdir(''+str(result_order)+'.SNP')
assert not os.system('cp %s .' % (root_dir+'/SNP_TR/SNP/ResultsQ30/InDels.xls'))
assert not os.system('cp %s .' % (root_dir+'/SNP_TR/SNP/ResultsQ30/SNPs.xls'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/SNP.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.SNP/'+str(result_order)+'.SNP.README.txt'))
os.chdir(root_dir+'/'+project+'_TR_result/'+project+'_results')
'''
if set([1,4,5]).issubset(includes):
code+='''
result_order+=1
assert not os.system('mkdir '+str(result_order)+'.GeneExprQuatification')
HTSeq_order=str(result_order)
os.chdir(''+str(result_order)+'.GeneExprQuatification')
assert not os.system('cp %s .' % (root_dir+'/Diff_TR/Diff/rpkm.xls'))
assert not os.system('cp %s .' % (root_dir+'/Diff_TR/Diff/readcount.xls'))
assert not os.system('cp %s .' % (root_dir+'/Diff_TR/Diff/rpkm.stat.xls'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/Quatification.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.GeneExprQuatification/'+str(result_order)+'GeneExprQuatification.README.txt'))
os.chdir(root_dir+'/'+project+'_TR_result/'+project+'_results')
'''
if set([1,4,6]).issubset(includes):
code+='''
result_order+=1
assert not os.system('mkdir '+str(result_order)+'.AdvancedQC')
os.chdir(''+str(result_order)+'.AdvancedQC')
assert not os.system('mkdir '+str(result_order)+'.1.SaturationCurve')
os.chdir(''+str(result_order)+'.1.SaturationCurve')
for eachsample in samples:
assert not os.system('cp %s .' % (root_dir+'/Curve_TR/SaturationCurve/'+eachsample+'/'+eachsample+'.saturation.png'))
assert not os.system('cp %s .' % (root_dir+'/Curve_TR/SaturationCurve/'+eachsample+'/'+eachsample+'.saturation.pdf'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/SatCurve.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.AdvancedQC/'+str(result_order)+'.1.SaturationCurve/'+str(result_order)+'.1SaturationCurve.README.txt'))
os.chdir('..')
if flag_uniform:
assert not os.system('mkdir '+str(result_order)+'.2.MeanCoverage')
os.chdir(''+str(result_order)+'.2.MeanCoverage')
for eachsample in samples:
assert not os.system('cp %s %s' % (root_dir+'/QC_TR/'+eachsample+'/files/'+eachsample+'.MC.png',eachsample+'.Mean_coverage_distribution.png'))
assert not os.system('cp %s %s' % (root_dir+'/QC_TR/'+eachsample+'/files/'+eachsample+'.MC.pdf',eachsample+'.Mean_coverage_distribution.pdf'))
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/MeanCov.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.AdvancedQC/'+str(result_order)+'.2.MeanCoverage/'+str(result_order)+'.2MeanCoverage.README.txt'))
os.chdir(root_dir+'/'+project+'_TR_result/'+project+'_results')
'''
if set([1,4,5]).issubset(includes):
code +='''
if flag_uniform:
os.chdir(''+str(result_order)+'.AdvancedQC')
assert not os.system('mkdir '+str(result_order)+'.3.Correlation')
os.chdir(''+str(result_order)+'.3.Correlation')
for png in glob.iglob(root_dir+'/Diff_TR/Diff/corr_plot/*.png'):
assert not os.system('cp %s .' % png)
for pdf in glob.iglob(root_dir+'/Diff_TR/Diff/corr_plot/*.pdf'):
assert not os.system('cp %s .' % pdf)
assert not os.system( 'cp %s .' % (root_dir+'/Diff_TR/Diff/corr_plot/cor_pearson.xls') )
assert not os.system('cp /PUBLIC/source/RNA/RefRNA/TransRef/README_v2/DupCorr.README.txt %s' % (root_dir+'/'+project+'_TR_result/'+project+'_results/'+str(result_order)+'.AdvancedQC/'+str(result_order)+'.3.Correlation/'+str(result_order)+'.3Correlation.README.txt'))
os.chdir(root_dir+'/'+project+'_TR_result/'+project+'_results')