9
9
import os
10
10
from .__init__ import __version__
11
11
12
+ def read_file (f ):
13
+ if not os .path .exists (f ):
14
+ raise ValueError ("Error, file %s not found!\n " % f )
15
+ fList = []
16
+ with open (f ) as fin :
17
+ for line in fin :
18
+ if line .startswith ("#" ) or line .strip () == "" :
19
+ continue
20
+ fList .append (line .strip ())
21
+ return fList
22
+
12
23
def parsing_gtf_update ():
13
24
parser = argparse .ArgumentParser (
14
25
description = "This script is designed for preparing the appropriate GTF file from \
@@ -59,9 +70,12 @@ def parsing_metaplots():
59
70
)
60
71
parser .add_argument ("-a" ,"--annot_dir" ,dest = "annot_dir" ,required = True ,type = str ,
61
72
help = "transcripts annotation directory, generated by prepare_transcripts." )
62
- parser .add_argument ("-r" ,"--rpf_mapping_file" ,dest = "rpf_mapping_file" ,required = True ,type = str ,
73
+ group = parser .add_mutually_exclusive_group (required = True )
74
+ group .add_argument ("-r" ,"--rpf_mapping_file" ,dest = "rpf_mapping_file" ,required = False ,type = str ,
63
75
help = "ribo-seq BAM/SAM file aligned to the transcriptome." )
64
- parser .add_argument ("-s" ,"--stranded" ,dest = "stranded" ,required = False ,type = str ,choices = ["yes" ,"reverse" ],
76
+ group .add_argument ("-i" ,"--input_file" ,dest = "rpf_mapping_file" ,required = False ,type = read_file ,
77
+ help = "the file list the ribo-seq BAM/SAM files aligned to the transcriptome." )
78
+ parser .add_argument ("-s" ,"--stranded" ,dest = "stranded" ,required = False ,type = str ,choices = ["yes" ,"reverse" ,"no" ],
65
79
default = "yes" ,help = "whether the data is strand-specific, \
66
80
reverse means reversed strand interpretation.(default: yes)" )
67
81
parser .add_argument ("-m" ,"--minimum-length" ,dest = "minLength" ,required = False ,type = int ,default = 24 ,
@@ -86,9 +100,17 @@ def parsing_metaplots():
86
100
raise ValueError ("minimum length must be <= maximum length (currently %d and %d, respectively)" % (args .minLength , args .maxLength ))
87
101
if args .minLength <= 0 or args .maxLength <= 0 :
88
102
raise ValueError ("minimum length or maximum length must be larger than 0." )
89
- if not os .path .exists (args .rpf_mapping_file ):
90
- raise ValueError ("Error, the rpf mapping file not found: %s\n " % args .rpf_mapping_file )
91
- args .stranded = True if args .stranded == "yes" else False
103
+ if type (args .rpf_mapping_file ) is str :
104
+ if not os .path .exists (args .rpf_mapping_file ):
105
+ raise ValueError ("Error, the rpf mapping file not found: %s\n " % args .rpf_mapping_file )
106
+ args .rpf_mapping_file = [args .rpf_mapping_file ]
107
+
108
+ if args .stranded == "yes" :
109
+ args .stranded = True
110
+ elif args .stranded == "reverse" :
111
+ args .stranded = False
112
+ else :
113
+ args .stranded = None
92
114
args .pvalue1_cutoff = float (args .pvalue1_cutoff )
93
115
args .pvalue2_cutoff = float (args .pvalue2_cutoff )
94
116
args .frame0_percent = float (args .frame0_percent )
@@ -111,9 +133,6 @@ def parsing_ribo():
111
133
If set to no , the position of start codon will be automatically determined by program." , type = str )
112
134
parser .add_argument ("-p" ,"--pval-cutoff" ,dest = "pval_cutoff" ,default = 0.05 ,required = False ,
113
135
help = "P-value cutoff for ORF filtering, default 0.05" , type = float )
114
- parser .add_argument ("--stranded" ,"--stranded" ,dest = "stranded" ,required = False ,type = str ,choices = ["yes" ,"reverse" ],
115
- default = "yes" ,help = "whether the data is strand-specific, \
116
- reverse means reversed strand interpretation.(default: yes)" )
117
136
parser .add_argument ("-s" ,"--start_codon" ,default = "ATG" ,type = str ,dest = "start_codon" ,
118
137
help = "The canonical start codon. default: ATG" )
119
138
parser .add_argument ("-A" ,"--alt_start_codons" ,default = "" ,type = str ,dest = "alternative_start_codons" ,
@@ -128,12 +147,12 @@ def parsing_ribo():
128
147
# parser.add_argument("-P","--parallel_num",dest="parallel_num",default=1,required=False,
129
148
# help="the number of threads to read the alignment file(s), \
130
149
# the optimal value is the number of alignment files, default=1",type=int)
131
- parser .add_argument ("-o" ,"--output-name" ,dest = "output_name" ,default = "final_result" ,required = False ,
132
- help = "output file name, default: final_result" , type = str )
133
150
parser .add_argument ("-g" ,"--output-gtf" ,dest = "output_gtf" ,action = 'store_true' ,default = False ,required = False ,
134
151
help = "output the gtf file of predicted ORFs" )
135
152
parser .add_argument ("-b" ,"--output-bed" ,dest = "output_bed" ,action = 'store_true' ,default = False ,required = False ,
136
153
help = "output the bed file of predicted ORFs" )
154
+ parser .add_argument ("-o" ,"--output-name" ,dest = "output_name" ,default = "final_result" ,required = False ,
155
+ help = "output file name, default: final_result" , type = str )
137
156
parser .add_argument ('-V' ,"--version" ,action = "version" ,version = __version__ )
138
157
args = parser .parse_args ()
139
158
@@ -174,7 +193,7 @@ def parsing_ORF_count():
174
193
description = "This script is designed for calculating the number of reads mapping to ORF with the alignment files \
175
194
in SAM/BAM format (aligned to genome) and a feature file in GTF format"
176
195
)
177
- parser .add_argument ("-s" ,"--stranded" ,dest = "stranded" ,required = False ,type = str ,choices = ["yes" ,"reverse" ],
196
+ parser .add_argument ("-s" ,"--stranded" ,dest = "stranded" ,required = False ,type = str ,choices = ["yes" ,"reverse" , "no" ],
178
197
default = "yes" ,help = "whether the data is strand-specific, \
179
198
reverse means reversed strand interpretation. (default: yes)" )
180
199
parser .add_argument ("-a" ,"--minaqual" ,dest = "min_quality" ,required = False ,type = int ,
@@ -228,9 +247,12 @@ def parsing_ribo_onestep():
228
247
please refer: https://en.wikipedia.org/wiki/GENCODE' )
229
248
parser .add_argument ("-f" ,"--fasta" ,dest = "genomeFasta" ,required = True ,type = str ,
230
249
help = "The genome sequences file in fasta format." )
231
- parser .add_argument ("-r" ,"--rpf_mapping_file" ,dest = "rpf_mapping_file" ,required = True ,type = str ,
250
+ group = parser .add_mutually_exclusive_group (required = True )
251
+ group .add_argument ("-r" ,"--rpf_mapping_file" ,dest = "rpf_mapping_file" ,required = True ,type = str ,
232
252
help = "ribo-seq BAM/SAM file aligned to the transcriptome." )
233
- parser .add_argument ("-stranded" ,"--stranded" ,dest = "stranded" ,required = False ,type = str ,choices = ["yes" ,"reverse" ],
253
+ group .add_argument ("-i" ,"--input_file" ,dest = "rpf_mapping_file" ,required = False ,type = read_file ,
254
+ help = "the file list the ribo-seq BAM/SAM files aligned to the transcriptome." )
255
+ parser .add_argument ("-stranded" ,"--stranded" ,dest = "stranded" ,required = False ,type = str ,choices = ["yes" ,"reverse" ,"no" ],
234
256
default = "yes" ,help = "whether the data is strand-specific, \
235
257
reverse means reversed strand interpretation.(default: yes)" )
236
258
parser .add_argument ("-m" ,"--minimum-length" ,dest = "minLength" ,required = False ,type = int ,default = 24 ,
@@ -266,9 +288,16 @@ def parsing_ribo_onestep():
266
288
help = "output the bed file of predicted ORFs" )
267
289
parser .add_argument ('-V' ,"--version" ,action = "version" ,version = __version__ )
268
290
args = parser .parse_args ()
269
- if not os .path .exists (args .rpf_mapping_file ):
270
- raise ValueError ("Error, the rpf mapping file not found: %s\n " % args .rpf_mapping_file )
271
- args .stranded = True if args .stranded == "yes" else False
291
+ if type (args .rpf_mapping_file ) is str :
292
+ if not os .path .exists (args .rpf_mapping_file ):
293
+ raise ValueError ("Error, the rpf mapping file not found: %s\n " % args .rpf_mapping_file )
294
+ args .rpf_mapping_file = [args .rpf_mapping_file ]
295
+ if args .stranded == "yes" :
296
+ args .stranded = True
297
+ elif args .stranded == "reverse" :
298
+ args .stranded = False
299
+ else :
300
+ args .stranded = None
272
301
if args .minLength > args .maxLength :
273
302
raise ValueError ("minimum length must be <= maximum length (currently %d and %d, respectively)" % (args .minLength , args .maxLength ))
274
303
if args .minLength <= 0 or args .maxLength <= 0 :
0 commit comments