-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNOREF_generator_v4.py
2225 lines (2022 loc) · 106 KB
/
NOREF_generator_v4.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
#noref pipline
#2013.01.06
#modified 2013.01.31
#modified 2013.5.24 by hanrui
#modified 2014.8.21 by yangying
#guoyang
import sys
import os
import os.path
import re
import argparse
root_dir=os.getcwd()
##################################################################################
#parse the arguments
parser = argparse.ArgumentParser(description="noref pipeline v1.5")
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=True)
parser.add_argument('--sample',help="sample names(sample1,sample2,...) warning: order sensitive!",required=True)
parser.add_argument('--seq',help="the original directory of the raw fastq reads for QC, [REQUIRED]",default=None)
parser.add_argument('--ad',help="the original directory of the adapter list for QC",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)",required=True)
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('--len',help="length of reads(n,n,...) for SNP, keep order in line with '--sample'",default=None)
parser.add_argument('--ex',help="the steps you do not wanna perform",default=None)
parser.add_argument('--group',help="sample classification, e.g. sample1:sample2,sample3 for differential expression analysis",default=None)
parser.add_argument('--groupname',help="group names, (default: group1,group2,... with 'sample repeat' or sample names directly without 'sample repeat'),for differential expression analysis",default=None)
parser.add_argument('--compare',help="group comparison strategy(1:2,1:3,...) warning: number only,for differential expression analysis",default=None)
parser.add_argument('--matrix',help="the score matrices for estscan program.",default='Hs')
parser.add_argument('--codon',help="the id indicates the genetic codon table.",default='1')
parser.add_argument('--ss',help='Probability of generating a read from the forward strand of a transcript.',choices=['0.0','0.5','1.0'],default='0.5')
parser.add_argument('--jc',help='(--jaccard_clip)set 1 if you have paired reads and you expect high gene density with UTR overlap (use FASTQ input file format for reads)(Default : 0)',choices=['0','1'],default='0')
parser.add_argument('--minkmercov',help='min count for K-mers to be assembled by Inchworm(Default : 2)',default='2')
parser.add_argument('--minglue',help='min number of reads needed to glue two inchworm contigs together(Default : 2)',default='2')
parser.add_argument('--db',help='Database (NR) used; choose "nr" for the whole database or "eu" for euKaryote only.',choices=['nr','eu'],default='eu')
parser.add_argument('--venn_cluster',help='compares groups for venn separately',default=None)
parser.add_argument('--generate_adapter',help='whether to generate the adpepter list y or 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 ,',default=None)
parser.add_argument('--ppi_number',help='the number of reference for PPI',default=None)
#extract, wash and check the parameter
argv=vars(parser.parse_args())
project=argv['project'].strip()
samples=[each.strip() for each in argv['sample'].strip().split(',') if each.strip() != '']
sample=','.join(samples)
assert not os.system('perl /PUBLIC/source/RNA/noRef/Pipeline_noRef/check.sample_name.pl -sample %s ' % (sample))
assert len(set(samples)) == len(samples)
generate_adapter=argv['generate_adapter']
assert argv['seq']!=None or argv['raw_dir'] != None
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['seq']!=None:
sequences=[]
seq=argv['seq'].strip()
for eachsample in samples:
sequences.append([seq+'/'+eachsample+'_1.fq.gz',seq+'/'+eachsample+'_2.fq.gz'])
if generate_adapter =='n':
adaptors=[]
for eachsample in samples:
adaptors.append([seq+'/'+eachsample+'_1.adapter.list.gz',seq+'/'+eachsample+'_2.adapter.list.gz'])
else:
assert not os.system('mkdir raw_data')
assert not os.system('perl /PUBLIC/source/RNA/noRef/QC/bin/ln_raw_data.pl %s %s pe raw_data' %(argv['mapfile'],argv['raw_dir']))
sequences=[]
for eachsample in samples:
sequences.append([root_dir+'/raw_data/'+eachsample+'_1.fq.gz',root_dir+'/raw_data/'+eachsample+'_2.fq.gz'])
if generate_adapter =='n':
adaptors=[]
for eachsample in samples:
adaptors.append([root_dir+'/raw_data/'+eachsample+'_1.adapter.list.gz',root_dir+'/raw_data/'+eachsample+'_2.adapter.list.gz'])
assert len(samples) == len(sequences)
for each1 in sequences:
for each2 in each1:
assert os.path.isfile(each2)
sequence=','.join([':'.join(each) for each in sequences])
if argv['ad'] != None :
ad=argv['ad'].strip()
adaptors=[]
for eachsample in samples:
adaptors.append([ad+'/'+eachsample+'_1.adapter.list.gz',ad+'/'+eachsample+'_2.adapter.list.gz'])
assert len(samples) == len(adaptors)
for each1 in adaptors:
assert len(each1) == 2
if (each1[0].strip() != '') or (each1[1].strip() != ''):
for each2 in each1:
assert os.path.isfile(each2)
adaptor=','.join([':'.join(each) for each in adaptors])
else:
if argv['raw_dir'] !=None:
if generate_adapter =='n':
assert len(samples) == len(adaptors)
for each1 in adaptors:
assert len(each1) == 2
if (each1[0].strip() != '') or (each1[1].strip() != ''):
for each2 in each1:
assert os.path.isfile(each2)
adaptor=','.join([':'.join(each) for each in adaptors])
else:
assert argv['index']
indexs=[each.strip() for each in argv['index'].strip().split(',')]
assert len(samples) == len(indexs)
for each1 in indexs:
index=','.join(indexs)
adaptor=','.join([':' for i in range(len(samples))])
else:
if generate_adapter !='n':
assert argv['index']
indexs=[each.strip() for each in argv['index'].strip().split(',')]
assert len(samples) == len(indexs)
for each1 in indexs:
index=','.join(indexs)
adaptor=','.join([':' for i in range(len(samples))])
if argv['seq']!=None:
if generate_adapter =='n':
if argv['ad'] == None:
print 'Error: the parameters --ad and --generate_adapter are not consensus!\n'
exit()
################################
all_content=set([1,2,3,4,5,6,7,8,9,10])
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
includes=all_content-set(excludes) #set
################################
if set([1]).issubset(includes):
ss=argv['ss'].strip()
jc=argv['jc'].strip()
minkmercov=argv['minkmercov'].strip()
minglue=argv['minglue'].strip()
################################
'''
if set([1,3]).issubset(includes):
assert argv['len']
lengths=argv['len'].strip().strip(',').strip().split(',')
lengths=[each.strip() for each in lengths]
if len(lengths) == 1:
lengths=lengths*len(samples)
for each1 in lengths:
assert each1.isdigit()
length=','.join(lengths)
assert len(lengths) == len(samples)
'''
################################
if set([1,5,6]).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 len(groups_iter) == len(set(groups_iter))
assert set(groups_iter).issubset(samples)
group_iter=','.join(groups_iter)
if argv['groupname'] == None:
if flag_repeat == False:
groupnames=groups
else:
groupnames=['group'+str(k+1) for k in range(len(groups))]
else:
groupnames=[each.strip() for each in argv['groupname'].split(',') if each.strip() != '']
assert len(groupnames) == len(groups)
groupname=','.join(groupnames)
#############################
assert argv['compare']
compares=[each.strip().split(':') for each in argv['compare'].strip().split(',') if each.strip() != '']
M=[]
for each1 in compares:
assert len(each1) == 2
for each2 in each1:
assert each2.isdigit()
M.append(int(each2))
assert max(M) <= len(groupnames)
assert min(M) > 0
compare=','.join([':'.join(each) for each in compares])
temp2=[]
for each1 in compares:
temp1=[]
for each2 in each1:
temp1.append(groupnames[int(each2)-1])
temp2.append(':'.join(temp1))
compare_name=','.join(temp2)
#############################################
if argv['venn_cluster'] != None:
venn_cluster=argv['venn_cluster'].strip()
com_pairs=compare.split(',')
venn_clusters=[each.split('_') for each in venn_cluster.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(groupnames[int(temp3[0])-1]+':'+groupnames[int(temp3[1])-1])
temp1.append('_'.join(temp2))
venn_cluster_name=','.join(temp1)
else:
venn_cluster=compare.replace(',','_')
venn_cluster_name=compare_name.replace(',','_')
##########################################################################
if set([1,5,6,10]).issubset(includes):
assert argv['ppi_number'] !=None
ppi_number=argv['ppi_number']
########################################################################################
if set([1,2]).issubset(includes):
matrix=argv['matrix'].strip()
if (matrix not in ['At','Hs','Mm','Rn','Dm','Dr','Os','Zm']) and (not os.path.isfile(matrix)):
sys.exit('matrix fail...')
codon=argv['codon'].strip()
if codon not in ['1','2','3','4','5','6','9','10','11','12','13','14','15','16','21','22','23']:
sys.exit('codon fail...')
db=argv['db']
###########################################################################
#parameters display
display=open('parameters_display.txt','w')
display.write('project: '+project+'\n')
for i,eachsample in enumerate(samples):
display.write('sample: '+eachsample+'\n')
display.write('\traw data1: '+sequences[i][0]+'\n')
display.write('\traw data2: '+sequences[i][1]+'\n')
if argv['ad'] != None:
display.write('\tadaptor list1: '+adaptors[i][0]+'\n')
display.write('\tadaptor list2: '+adaptors[i][1]+'\n')
if argv['generate_adapter'] !='n':
display.write('\tindex list: '+indexs[i]+'\n')
#if set([1,3]).issubset(includes):
#display.write('\tlength: '+lengths[i]+'\n')
display.write('\n\n')
if set([1]).issubset(includes):
display.write('trinity parameters:\n')
display.write('\tStrand-specific RNA-Seq read orientation: %s\n' % ss)
display.write('\tjaccard_clip: %s\n' % jc)
display.write('\tmin count for K-mers to be assembled by Inchworm: %s\n' % minkmercov)
display.write('\tmin number of reads needed to glue two inchworm contigs together: %s\n\n\n' % minglue)
if set([1,5,6]).issubset(includes):
display.write('group:samples\n')
for i,eachgroup in enumerate(groupnames):
display.write(eachgroup+': '+str(groups[i])+'\n')
display.write('\n')
display.write('group comparison strategy:\n')
display.write(compare+'\n')
display.write(compare_name+'\n')
display.write('\n\n')
display.write('venn cluster:\n')
display.write(venn_cluster.replace('_',' ').replace(',','\n'))
display.write('venn cluster name:\n')
display.write(venn_cluster_name.replace('_',' ').replace(',','\n'))
display.write('\n\n\n')
if set([1,2]).issubset(includes):
display.write('matrix: '+matrix+'\n')
display.write('codon: '+codon+'\n')
db_detail={'nr':'for the whole database','eu':'for eukaryote only'}
display.write('database: '+db+' ('+db_detail[db]+')\n')
display.write('E-value: 1e-5\n\n\n')
contents_detail={0:'QC (default)',1:'trinity assembly',2:'function annotation & CDS prediction',3:'SNP',4:'SSR',5:'RSEM',6:'DIFF_EXP',7:'RNAseq QC',8:'KEGG enrichment',9:'GO enrichment',10:'PPI'}
display.write('content(s) included:\n')
display.write('\tcontent0: QC (default)\n')
for eachone in includes:
display.write('\tcontent%s: %s\n' % (eachone,contents_detail[eachone]))
display.write('\n\n\n\n\n\n\n\n##########################################\n')
display.write(sample+'\n')
display.write(str(samples)+'\n')
display.write(sequence+'\n')
display.write(str(sequences)+'\n')
if argv['ad'] != None:
display.write(str(adaptors)+'\n')
display.write(adaptor+'\n')
if set([1]).issubset(includes):
display.write(ss+'\n')
display.write(jc+'\n')
display.write(minkmercov+'\n')
display.write(minglue+'\n')
'''
if set([1,3]).issubset(includes):
display.write(length+'\n')
display.write(str(lengths)+'\n')
'''
if set([1,5,6]).issubset(includes):
display.write(group+'\n')
display.write(str(groups)+'\n')
display.write(groupname+'\n')
display.write(str(groupnames)+'\n')
display.write(compare+'\n')
display.write(str(compares)+'\n')
display.write(compare_name+'\n')
display.write(venn_cluster+'\n')
display.write(venn_cluster_name+'\n')
if argv['ppi_number'] != None:
display.write('ppi_number: %s\n\n' % (ppi_number))
if set([1,2]).issubset(includes):
display.write(matrix+'\n')
display.write(codon+'\n')
display.write(db+'\n')
display.write(str(excludes)+'\n')
display.write(str(includes)+'\n')
display.close()
###########################################################################
#for QC (run)
code='''
import os
sample='%s'
samples=sample.split(',')
sequence='%s'
sequences=[each.split(':') for each in sequence.split(',')]
adaptor='%s'
adaptors=[each.split(':') for each in adaptor.split(',')]
root_dir='%s'
generate_adapter='%s'
''' % (sample,sequence,adaptor,root_dir,generate_adapter)
if generate_adapter != 'n':
code+='''
index='%s'
indexs=index.split(',')
''' % (index)
code+='''
assert not os.system('mkdir QC')
os.chdir('QC')
for i,eachsample in enumerate(samples):
assert not os.system('mkdir '+eachsample)
os.chdir(eachsample)
assert not os.system('ln -s %s %s' % (sequences[i][0],eachsample+'_1.fq.gz'))
assert not os.system('ln -s %s %s' % (sequences[i][1],eachsample+'_2.fq.gz'))
par_map=root_dir+'/libraryID'
par_a=eachsample+'_1.fq.gz'
par_b=eachsample+'_2.fq.gz'
par_n=samples[i]
if (adaptors[i][0].strip() != '') and (adaptors[i][1].strip() != ''):
par_ad1=adaptors[i][0]
par_ad2=adaptors[i][1]
f=open('qc_'+eachsample+'.sh','w')
f.write('perl /PUBLIC/source/RNA/noRef/QC/runQC_noref_v2.2.pl -a %s -b %s -ad1 %s -ad2 %s -n %s -mapfile %s' % (par_a,par_b,par_ad1,par_ad2,par_n,par_map))
f.close()
assert not os.system('sh qc_%s.sh' % (eachsample))
else:
f=open('qc_'+eachsample+'.sh','w')
f.write('perl /PUBLIC/source/RNA/noRef/QC/runQC_noref_v2.2.pl -a %s -b %s -n %s -mapfile %s' % (par_a,par_b,par_n,par_map))
if generate_adapter !='n':
par_index=indexs[i]
f.write(' -m_ad %s -index %s' % (generate_adapter,par_index))
f.close()
assert not os.system('sh qc_%s.sh' % (eachsample))
assert not os.system('qsub -V -cwd -l vf=2G -l p=3 runQC_noref.sh')
os.chdir('..')
os.chdir(root_dir)
'''
open('NOREF_step1.py','w').write(code)
##############################################################################
#for QC_report
code='''
import os
sample='%s'
project='%s'
os.chdir('QC')
f=open('QC_report.sh','w')
f.write('perl /PUBLIC/source/RNA/noRef/QC/noRef_QC_report_library.pl -n %%s -p %%s -dir .\\n' %% (sample, project))
f.write('perl /PUBLIC/source/RNA/noRef/QC/bin/clean_data_sum.pl -n %%s\\n' %% (sample))
f.close()
assert not os.system('sh QC_report.sh')
''' % (sample, project)
open('NOREF_step1_QCreport.py','w').write(code)
####################################################################
#for trinity (sh->py noly, not run) root_dir
code=''
if set([1]).issubset(includes):
code+='''
import os
import os.path
import sys
import argparse
import re
parser = argparse.ArgumentParser(description='run trinity and resource list required')
parser.add_argument('--vf',required=True,help='momery required for qsub')
parser.add_argument('--h',required=True,help="the fat node for qsub")
argv=vars(parser.parse_args())
vf=argv['vf']
h=argv['h']
root_dir='%s'
sample='%s'
samples=sample.split(',')
ss='%s'
jc='%s'
minkmercov='%s'
minglue='%s'
project='%s'
clean_left=[]
clean_right=[]
for eachsample in samples:
each_clean_left=root_dir+'/QC/'+eachsample+'/clean_data/'+eachsample+'_1.clean.fq'
assert os.path.isfile(each_clean_left)
clean_left.append(each_clean_left)
each_clean_right=root_dir+'/QC/'+eachsample+'/clean_data/'+eachsample+'_2.clean.fq'
assert os.path.isfile(each_clean_right)
clean_right.append(each_clean_right)
clean_left=','.join(clean_left)
clean_right=','.join(clean_right)
rRNA=root_dir+'/QC/'+project+'.QC_results/results/1dataTable/dataTable'
assert os.path.isfile(rRNA)
cluster_num=re.search(r'([1-9])',h).group(1)
P_mem='mem'+str(cluster_num)
q_mem=P_mem+'.q'
if cluster_num==str(3) or cluster_num==str(4):
P_mem='mem3'
q_mem='mem3.q'
assert not os.system('mkdir TRINITY')
os.chdir('TRINITY')
f=open('trinity.sh','w')
f.write('perl /PUBLIC/source/RNA/noRef/Trinity_CDS/runTrinity_cds_v2.pl -left %%s -right %%s -ss %%s -jc %%s -minkmercov %%s -minglue %%s -JM %%s -rRNA %%s' %% (clean_left,clean_right,ss,jc,minkmercov,minglue,vf,rRNA))
f.close()
assert not os.system('sh trinity.sh')
assert not os.system('/opt/gridengine/bin/lx26-amd64/qsub -cwd -l vf=%%s -l p=10 -P %%s -q %%s -V run_Trinity_cds.sh' %% (vf,P_mem,q_mem))
''' % (root_dir,sample,ss,jc,minkmercov,minglue,project)
open('NOREF_step2.py','w').write(code)
##########################################################################
#for RSEM and SSR and the first step of SNP and ANNOTATION(sh->py only, not run) root_dir
code='''
import os
import os.path
import sys
'''
if set([1,2]).issubset(includes):
code+='''
import argparse
parser = argparse.ArgumentParser(description='some in-time parameters for annotation')
parser.add_argument('--new',help='where to qsub the annotation script,(1 on the New cluster,0 on the old DELL )',choices=['0','1'],default='1')
parser.add_argument('--n',help="split sequence file into given number, only for blast NR",default='0')
argv=vars(parser.parse_args())
ibm=argv['new']
n=argv['n'].strip()
assert n.isdigit()
'''
code+='''
sample='%s'
samples=sample.split(',')
root_dir='%s'
project='%s'
''' % (sample,root_dir,project)
if set([1,2]).issubset(includes):
code+='''
##ANNOTATION
matrix='%s'
codon='%s'
db='%s'
assert not os.system('mkdir ANNOTATION_ALL')
os.chdir('ANNOTATION_ALL')
assert os.path.isfile(root_dir+'/TRINITY/assembly_INFO/unigene.fasta')
par_seq=root_dir+'/TRINITY/assembly_INFO/unigene.fasta'
num = n if int(n) else int(round(int(os.popen('grep -c \\">\\" '+par_seq).read().rstrip())/20000.0))
par_out=root_dir+'/ANNOTATION_ALL'
f=open('annot.sh','w')
f.write('perl /PUBLIC/source/RNA/noRef/ANNOTATION/annotation_v4.pl -seq %%s -out %%s -p %%s -matrix %%s -codon %%s -n %%s -db %%s -new %%s' %% (par_seq,par_out,project,matrix,codon,num,db,ibm))
f.close()
assert not os.system('sh annot.sh')
os.chdir(root_dir)
''' % (matrix,codon,db)
if set([1,5]).issubset(includes):
code+='''
##RSEM
ss='%s'
assert not os.system('mkdir RSEM')
os.chdir('RSEM')
assert os.path.isfile(root_dir+'/TRINITY/trinity.out/Trinity.fasta')
for eachsample in samples:
assert not os.system('mkdir %%s' %% eachsample)
os.chdir(eachsample)
assert os.path.isfile(root_dir+'/QC/'+eachsample+'/clean_data/'+eachsample+'_1.clean.fq')
assert os.path.isfile(root_dir+'/QC/'+eachsample+'/clean_data/'+eachsample+'_2.clean.fq')
par_a=root_dir+'/TRINITY/trinity.out/Trinity.fasta'
par_r=root_dir+'/QC/'+eachsample+'/clean_data/'+eachsample+'_1.clean.fq'+','+root_dir+'/QC/'+eachsample+'/clean_data/'+eachsample+'_2.clean.fq'
runRSEM=open('RSEM_'+eachsample+'.sh','w')
runRSEM.write('perl /PUBLIC/source/RNA/noRef/RSEM/runRSEM_v1.5.pl -a %%s -r %%s -n %%s -s %%s -ss %%s' %% (par_a,par_r,project,eachsample,ss))
runRSEM.close()
assert not os.system('qsub -V -cwd -l vf=4G -l p=2 RSEM_%%s.sh' %% eachsample)
os.chdir('..')
os.chdir(root_dir)
''' % (ss)
if set([1,3]).issubset(includes):
code+='''
##the first step of SNP
#length='%s'
#lengths=length.split(',')
assert not os.system('mkdir SNP')
os.chdir('SNP')
assert os.path.isfile(root_dir+'/TRINITY/assembly_INFO/unigene.fasta')
assert not os.system('mkdir bam')
par_bamdir=root_dir+'/SNP/bam'
par_D=root_dir+'/TRINITY/assembly_INFO/unigene.fasta'
par_dir=root_dir+'/SNP'
f=open('snp_step1.sh','w')
f.write('/PUBLIC/software/RNA/bowtie2-2.2.3/bowtie2-build %s %s\\n' % (par_D,par_D))
for i,eachsample in enumerate(samples):
#assert not os.system('mkdir %s' % eachsample)
#os.chdir(eachsample)
par_a=root_dir+'/QC/'+eachsample+'/clean_data/'+eachsample+'_1.clean.fq'
par_b=root_dir+'/QC/'+eachsample+'/clean_data/'+eachsample+'_2.clean.fq'
par_n=eachsample
#par_L=lengths[i]
par_sam=eachsample+'.sam'
par_bam='bam/'+eachsample+'.bam'
#par_i=root_dir+'/TRINITY/assembly_INFO/geneINFO'
#assert os.path.isfile(par_i)
f.write('/PUBLIC/software/RNA/bowtie2-2.2.3/bowtie2 -p 8 -x %s -1 %s -2 %s | samtools view -Sb - >%s\\n' % (par_D,par_a,par_b,par_bam))
#os.chdir('..')
f.write('perl /PUBLIC/source/RNA/noRef/GATKsnp/runGATK2_v1.pl -ref %s -t bam -i %s \\n' % (par_D,par_bamdir))
f.write('sh workflow.sh\\n')
f.close()
assert not os.system('qsub -V -cwd -l vf=12G -l p=8 snp_step1.sh')
os.chdir(root_dir)
'''
if set([1,4]).issubset(includes):
code+='''
##SSR
assert not os.system('mkdir SSR')
os.chdir('SSR')
assert os.path.isfile(root_dir+'/TRINITY/assembly_INFO/unigene.fasta')
f=open('ssr.sh','w')
f.write('perl /PUBLIC/source/RNA/noRef/SSR_Primer/runSSR_primer_v2.pl -a %s ' % (root_dir+'/TRINITY/assembly_INFO/unigene.fasta'))
f.close()
assert not os.system('sh ssr.sh')
assert not os.system('qsub -V -cwd -l vf=1G -l p=1 runSSR_primer.sh')
os.chdir(root_dir)
'''
open('NOREF_step3.py','w').write(code)
#########################################################
#for different expression (sh->py only, not run) root_dir
code=''
if set([1,5,6]).issubset(includes):
code+='''
import os
import os.path
import sys
assert not os.system('mkdir DIFF_EXP')
os.chdir('DIFF_EXP')
sample='%s'
samples=sample.split(',')
root_dir='%s'
group='%s'
groupname='%s'
compare='%s'
venn_cluster='%s'
readcount=[]
for eachsample in samples:
temp='%%s/RSEM/%%s/%%s.RSEM.out/%%s.Readcount_FPKM.xls' %% (root_dir,eachsample,eachsample,eachsample)
assert os.path.isfile(temp)
readcount.append(temp)
readcount=','.join(readcount)
geneinfo=root_dir+'/TRINITY/assembly_INFO/geneINFO'
assert os.path.isfile(geneinfo)
f=open('diff_exp.sh','w')
f.write('perl /PUBLIC/source/RNA/noRef/Diff_analysis/DE_analysis/runDE_analysis_v2.pl -i %%s -c %%s -group %%s -groupname %%s -g %%s -venn_cluster %%s' %% (readcount,geneinfo,group,groupname,compare,venn_cluster))
f.close()
assert not os.system('sh diff_exp.sh')
assert not os.system('qsub -V -cwd -l vf=2G -l p=2 Diff_Analysis.sh')
''' % (sample,root_dir,group,groupname,compare,venn_cluster)
open('NOREF_step4.py','w').write(code)
###########################################################
#for runAnnotationTable.sh,CDS prediction from ANNOTATION_ALL
code='''
import os
import os.path
sample='%s'
samples=sample.split(',')
root_dir='%s'
''' % (sample,root_dir)
if set([1,2]).issubset(includes):
code+='''
##runAnnotationTable.sh
os.chdir('ANNOTATION_ALL')
assert os.path.isfile('runAnnotationTable.sh')
assert not os.system('qsub -V -cwd -l vf=1G -l p=2 runAnnotationTable.sh')
'''
#if set([1,3]).issubset(includes):
#code+='''
#SNPanalysis_step2.sh
#os.chdir(root_dir)
#for eachsample in samples:
#os.chdir(root_dir+'/SNP/'+eachsample)
#assert not os.system('qsub -V -cwd -l vf=1G -l p=1 SNPanalysis_step2.sh')
#'''
open('NOREF_step5.py','w').write(code)
##########################################################
#for the second step of SNP, KEGG, GO and RNA-seqQC
code='''
import os
import os.path
root_dir='%s'
project='%s'
sample='%s'
samples=sample.split(',')
''' % (root_dir,project,sample)
if set([1,2,5,7]).issubset(includes):
code+='''
##RNA-seqQC
assert not os.system('mkdir RNA_SEQ_QC')
os.chdir('RNA_SEQ_QC')
par_b=[]
for eachsample in samples:
assert os.path.isfile(root_dir+'/RSEM/'+eachsample+'/'+eachsample+'.RSEM.out/'+eachsample+'.transcript.bam')
par_b.append(root_dir+'/RSEM/'+eachsample+'/'+eachsample+'.RSEM.out/'+eachsample+'.transcript.bam')
par_b=','.join(par_b)
par_s=sample
par_a=root_dir+'/ANNOTATION_ALL/'+project+'.swissprot.xml'
assert os.path.isfile(par_a)
par_gi=root_dir+'/TRINITY/assembly_INFO/geneINFO'
assert os.path.isfile(par_gi)
par_ti=root_dir+'/TRINITY/assembly_INFO/isoformINFO'
assert os.path.isfile(par_ti)
f=open('rnaseq_qc.sh','w')
f.write('perl /PUBLIC/source/RNA/noRef/Uni_saturation/uni_saturation_v1.5.pl -b %s -s %s -a %s -gi %s -ti %s' % (par_b,par_s,par_a,par_gi,par_ti))
f.close()
assert not os.system('sh rnaseq_qc.sh')
assert not os.system('qsub -V -cwd -l vf=1G -l p=1 step5_Uni_saturation.sh')
os.chdir(root_dir)
'''
if set ([1,2,3]).issubset(includes):
code+='''
##SNP step2
os.chdir('SNP')
f=open('run.snp_step2.sh','w')
f.write('perl /PUBLIC/source/RNA/noRef/GATKsnp/get_gtf.pl '+root_dir+'/ANNOTATION_ALL/CDSprediction/'+project+'.blast.cds.fasta >'+root_dir+'/SNP/ResultsQ30/blast.cds.gtf\\n')
f.write('perl /PUBLIC/source/RNA/noRef/GATKsnp/annotationSNP.pl --outdir '+root_dir+'/SNP/ResultsQ30/ --name SNPs_annotation --gff '+root_dir+'/SNP/ResultsQ30/blast.cds.gtf --snp '+root_dir+'/SNP/ResultsQ30/SNPs.xls --fa '+root_dir+'/TRINITY/assembly_INFO/unigene.fasta\\n')
f.write('perl /PUBLIC/source/RNA/noRef/GATKsnp/snp_annot.pl '+root_dir+'/SNP/ResultsQ30/SNPs.xls '+root_dir+'/SNP/ResultsQ30/SNPs_annotation.info.txt '+root_dir+'/SNP/ResultsQ30/SNPs_non_synonymous.xls '+root_dir+'/SNP/ResultsQ30/SNPs_non_synonymous.stat.xls\\n')
f.write('rm -rf '+root_dir+'/SNP/dedup\\n')
f.close()
assert not os.system('qsub -V -cwd -l vf=0.5G run.snp_step2.sh')
os.chdir(root_dir)
'''
if set([1,2,4]).issubset(includes):
code+='''
##SSR step2
os.chdir(root_dir+'/SSR/')
assert not os.system('python /PUBLIC/source/RNA/noRef/SSR_Primer/bin/SSR_position.py --project %s --root_dir %s'%(project,root_dir))
assert not os.system('qsub -V -cwd -l vf=1G -l p=1 SSR_utr.sh')
os.chdir(root_dir)
'''
if set([1,2,6]).issubset(includes):
code+='''
###check DIFFgene number
assert not os.system('perl /PUBLIC/source/RNA/noRef/Diff_analysis/DE_analysis/diffreport.pl -diffdir %s ' % (root_dir+'/DIFF_EXP/'))
'''
if set([1,2,5,6,9]).issubset(includes):
code+='''
##GO
compare_name='%s'
compare_names=[each.split(':') for each in compare_name.split(',')]
assert not os.system('mkdir GO_ENRICHMENT')
os.chdir('GO_ENRICHMENT')
assert not os.system('mkdir ALL')
os.chdir('ALL')
for each in compare_names:
temp='vs'.join(each)
par_i=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEGlist.txt'
assert os.path.isfile(par_i)
par_goann=root_dir+'/ANNOTATION_ALL/'+project+'.go.txt'
assert os.path.isfile(par_goann)
par_length=root_dir+'/TRINITY/assembly_INFO/geneINFO'
assert os.path.isfile(par_length)
assert not os.system('mkdir %%s' %% temp)
os.chdir(temp)
par_o=os.getcwd()
py=open('run_goseq_'+temp+'.sh','w')
py.write('perl /PUBLIC/software/RNA/GOseq/goseq_graph_v3.pl -i %%s -goann %%s -o %%s -length %%s -p %%s' %% (par_i,par_goann,par_o,par_length,temp))
py.close()
assert not os.system('qsub -V -cwd -l vf=2G -l p=1 run_goseq_%%s.sh' %% temp)
os.chdir('..')
os.chdir('..')
assert not os.system('mkdir UP')
os.chdir('UP')
for each in compare_names:
temp='vs'.join(each)
par_i=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEGlist_up.txt'
assert os.path.isfile(par_i)
par_goann=root_dir+'/ANNOTATION_ALL/'+project+'.go.txt'
assert os.path.isfile(par_goann)
par_length=root_dir+'/TRINITY/assembly_INFO/geneINFO'
assert os.path.isfile(par_length)
assert not os.system('mkdir %%s' %% temp)
os.chdir(temp)
par_o=os.getcwd()
py=open('run_goseq_up_'+temp+'.sh','w')
py.write('perl /PUBLIC/software/RNA/GOseq/goseq_graph_v3.pl -i %%s -goann %%s -o %%s -length %%s -p %%s' %% (par_i,par_goann,par_o,par_length,temp+'_up'))
py.close()
assert not os.system('qsub -V -cwd -l vf=2G -l p=1 run_goseq_up_%%s.sh' %% temp)
os.chdir('..')
os.chdir('..')
assert not os.system('mkdir DOWN')
os.chdir('DOWN')
for each in compare_names:
temp='vs'.join(each)
par_i=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEGlist_down.txt'
assert os.path.isfile(par_i)
par_goann=root_dir+'/ANNOTATION_ALL/'+project+'.go.txt'
assert os.path.isfile(par_goann)
par_length=root_dir+'/TRINITY/assembly_INFO/geneINFO'
assert os.path.isfile(par_length)
assert not os.system('mkdir %%s' %% temp)
os.chdir(temp)
par_o=os.getcwd()
py=open('run_goseq_down_'+temp+'.sh','w')
py.write('perl /PUBLIC/software/RNA/GOseq/goseq_graph_v3.pl -i %%s -goann %%s -o %%s -length %%s -p %%s' %% (par_i,par_goann,par_o,par_length,temp+'_down'))
py.close()
assert not os.system('qsub -V -cwd -l vf=2G -l p=1 run_goseq_down_%%s.sh' %% temp)
os.chdir('..')
os.chdir(root_dir)
''' % (compare_name)
if set([1,2,5,6,8]).issubset(includes):
code+='''
##KEGG
compare_name='%s'
compare_names=[each.split(':') for each in compare_name.split(',')]
assert not os.system('mkdir KEGG')
os.chdir('KEGG')
assert not os.system('mkdir ALL')
os.chdir('ALL')
for each in compare_names:
temp='vs'.join(each)
assert not os.system('mkdir %%s' %% temp)
os.chdir(temp)
par_diff=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEGlist.txt'
par_ko=root_dir+'/ANNOTATION_ALL/koID.annotation'
assert os.path.isfile(par_ko)
py=open('runKEGG_enrich_'+temp+'.sh','w')
py.write('perl /PUBLIC/source/RNA/noRef/KEGG_enrichment/runKEGG_enrich.pl -diff %%s -ko %%s -g %%s' %% (par_diff,par_ko,temp))
py.close()
assert not os.system('qsub -V -cwd -l vf=1G -l p=1 runKEGG_enrich_%%s.sh' %% temp)
os.chdir('..')
os.chdir('..')
assert not os.system('mkdir UP')
os.chdir('UP')
for each in compare_names:
temp='vs'.join(each)
assert not os.system('mkdir %%s' %% temp)
os.chdir(temp)
par_diff=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEGlist_up.txt'
par_ko=root_dir+'/ANNOTATION_ALL/koID.annotation'
assert os.path.isfile(par_ko)
py=open('runKEGG_enrich_up_'+temp+'.sh','w')
py.write('perl /PUBLIC/source/RNA/noRef/KEGG_enrichment/runKEGG_enrich.pl -diff %%s -ko %%s -g %%s' %% (par_diff,par_ko,temp+'_up'))
py.close()
assert not os.system('qsub -V -cwd -l vf=1G -l p=1 runKEGG_enrich_up_%%s.sh' %% temp)
os.chdir('..')
os.chdir('..')
assert not os.system('mkdir DOWN')
os.chdir('DOWN')
for each in compare_names:
temp='vs'.join(each)
assert not os.system('mkdir %%s' %% temp)
os.chdir(temp)
par_diff=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEGlist_down.txt'
par_ko=root_dir+'/ANNOTATION_ALL/koID.annotation'
assert os.path.isfile(par_ko)
py=open('runKEGG_enrich_down_'+temp+'.sh','w')
py.write('perl /PUBLIC/source/RNA/noRef/KEGG_enrichment/runKEGG_enrich.pl -diff %%s -ko %%s -g %%s' %% (par_diff,par_ko,temp+'_down'))
py.close()
assert not os.system('qsub -V -cwd -l vf=1G -l p=1 runKEGG_enrich_down_%%s.sh' %% temp)
os.chdir('..')
os.chdir(root_dir)
''' % (compare_name)
if set([1,2,5,6,10]).issubset(includes):
code+='''
##PPI
compare_name='%s'
compare_names=[each.split(':') for each in compare_name.split(',')]
ppi_number='%s'
assert not os.system('mkdir PPI')
os.chdir('PPI')
assert not os.system('mkdir ALL')
os.chdir('ALL')
for each in compare_names:
temp='vs'.join(each)
assert not os.system('mkdir %%s' %% temp)
os.chdir(temp)
par_diff=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEGlist.txt'
par_a=root_dir+'/TRINITY/assembly_INFO/unigene.fasta'
py=open('runPPI_'+temp+'.sh','w')
py.write('python /PUBLIC/source/RNA/guoyang_tools/BLASTX_TO_PPI_v4.py --entries %%s --species %%s --fa %%s --name %%s --output . \\n' %% (par_diff,ppi_number,par_a,temp))
py.write('cp %%s %%s' %% (root_dir+'/PPI/ALL/'+temp+'/'+temp+'.ppi.txt',root_dir+'/PPI/ALL/'+temp+'/'+temp+'.PPI.txt'))
py.close()
assert not os.system('qsub -V -cwd -l vf=1G -l p=4 runPPI_%%s.sh' %% temp)
os.chdir('..')
os.chdir('..')
assert not os.system('mkdir UP')
os.chdir('UP')
for each in compare_names:
temp='vs'.join(each)
assert not os.system('mkdir %%s' %% temp)
name=temp+'_up'
os.chdir(temp)
par_diff=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEGlist_up.txt'
par_a=root_dir+'/TRINITY/assembly_INFO/unigene.fasta'
py=open('runPPI_up_'+temp+'.sh','w')
py.write('python /PUBLIC/source/RNA/guoyang_tools/BLASTX_TO_PPI_v4.py --entries %%s --species %%s --fa %%s --name %%s --output . \\n' %% (par_diff,ppi_number,par_a,name))
py.write('cp %%s %%s' %% (root_dir+'/PPI/UP/'+temp+'/'+name+'.ppi.txt',root_dir+'/PPI/UP/'+temp+'/'+temp+'_up.PPI.txt'))
py.close()
assert not os.system('qsub -V -cwd -l vf=1G -l p=4 runPPI_up_%%s.sh' %% temp)
os.chdir('..')
os.chdir('..')
assert not os.system('mkdir DOWN')
os.chdir('DOWN')
for each in compare_names:
temp='vs'.join(each)
assert not os.system('mkdir %%s' %% temp)
name=temp+'_down'
os.chdir(temp)
par_diff=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEGlist_down.txt'
par_a=root_dir+'/TRINITY/assembly_INFO/unigene.fasta'
py=open('runPPI_down_'+temp+'.sh','w')
py.write('python /PUBLIC/source/RNA/guoyang_tools/BLASTX_TO_PPI_v4.py --entries %%s --species %%s --fa %%s --name %%s --output . \\n' %% (par_diff,ppi_number,par_a,name))
py.write('cp %%s %%s' %% (root_dir+'/PPI/DOWN/'+temp+'/'+name+'.ppi.txt',root_dir+'/PPI/DOWN/'+temp+'/'+temp+'_down.PPI.txt'))
py.close()
assert not os.system('qsub -V -cwd -l vf=1G -l p=4 runPPI_down_%%s.sh' %% temp)
os.chdir('..')
os.chdir(root_dir)
''' % (compare_name,ppi_number)
open('NOREF_step6.py','w').write(code)
####################################################
#for web Visualization for KEGG due to the network problem, can not qsub this step
code='''
import os
import os.path
root_dir='%s'
''' % (root_dir)
if set([1,2]).issubset(includes):
code+='''
os.chdir(root_dir+'/ANNOTATION_ALL')
par_ko=root_dir+'/ANNOTATION_ALL/Annotation_KO.xls'
assert os.path.isfile(par_ko)
assert not os.system('python /PUBLIC/source/RNA/guoyang_tools/pathway_ko_annotation_parallel_tolerant.pyc %s' % par_ko)
os.chdir(root_dir)
'''
if set([1,5,6,8]).issubset(includes):
code+='''
compare_name='%s'
compare_names=[each.split(':') for each in compare_name.split(',')]
for each in compare_names:
temp='vs'.join(each)
os.chdir(root_dir+'/KEGG/ALL/'+temp)
par_table=temp+'.DEG_KEGG_pathway_enrichment_add.xls'
par_diff=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEG.xls'
if os.path.isfile(par_table) and os.path.isfile(par_diff):
print '###'+temp+'###'
assert not os.system('python /PUBLIC/source/RNA/guoyang_tools/pathway_annotation_flow_parallel_annotationfault_tolerant.pyc --table %%s --diff %%s' %% (par_table,par_diff))
else:
print '!!!'+temp+'!!! file(s) unavailable...'
os.chdir(root_dir+'/KEGG/UP/'+temp)
par_table=temp+'_up.DEG_KEGG_pathway_enrichment_add.xls'
par_diff=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEG_up.xls'
if os.path.isfile(par_table) and os.path.isfile(par_diff):
print '###'+temp+' up###'
assert not os.system('python /PUBLIC/source/RNA/guoyang_tools/pathway_annotation_flow_parallel_annotationfault_tolerant.pyc --table %%s --diff %%s' %% (par_table,par_diff))
else:
print '!!!'+temp+' up!!! file(s) unavailable...'
os.chdir(root_dir+'/KEGG/DOWN/'+temp)
par_table=temp+'_down.DEG_KEGG_pathway_enrichment_add.xls'
par_diff=root_dir+'/DIFF_EXP/Diff_analysis.out/'+temp+'/'+temp+'.DEG_down.xls'
if os.path.isfile(par_table) and os.path.isfile(par_diff):
print '###'+temp+' down###'
assert not os.system('python /PUBLIC/source/RNA/guoyang_tools/pathway_annotation_flow_parallel_annotationfault_tolerant.pyc --table %%s --diff %%s' %% (par_table,par_diff))
else:
print '!!!'+temp+' down!!! file(s) unavailable...'
''' % (compare_name)
open('NOREF_step7.py','w').write(code)
####################################################
# for summary
code='''
import os
import os.path
import glob
import gzip
import sys
import re
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/noRef/Pipeline_noRef/report_v2',))
def fasta_trim(file,k,typ):
fa=[]
for eachLine in open(file):
if eachLine.startswith('>'):
k-=1
if k == 0:
break
if typ == 1:
fa.append(eachLine)
else:
fa.append(eachLine.strip()+'<br />')
return fa