HTSeq 2.1.2__cp313-cp313-macosx_10_15_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- HTSeq/StepVector.py +629 -0
- HTSeq/StretchVector.py +491 -0
- HTSeq/_HTSeq.cpython-313-darwin.so +0 -0
- HTSeq/_HTSeq_internal.py +85 -0
- HTSeq/_StepVector.cpython-313-darwin.so +0 -0
- HTSeq/__init__.py +1249 -0
- HTSeq/features.py +489 -0
- HTSeq/scripts/__init__.py +0 -0
- HTSeq/scripts/count.py +528 -0
- HTSeq/scripts/count_features/__init__.py +0 -0
- HTSeq/scripts/count_features/count_features_per_file.py +465 -0
- HTSeq/scripts/count_features/reads_io_processor.py +187 -0
- HTSeq/scripts/count_features/reads_stats.py +92 -0
- HTSeq/scripts/count_with_barcodes.py +746 -0
- HTSeq/scripts/qa.py +336 -0
- HTSeq/scripts/utils.py +372 -0
- HTSeq/utils.py +92 -0
- htseq-2.1.2.dist-info/METADATA +813 -0
- htseq-2.1.2.dist-info/RECORD +23 -0
- htseq-2.1.2.dist-info/WHEEL +5 -0
- htseq-2.1.2.dist-info/entry_points.txt +4 -0
- htseq-2.1.2.dist-info/licenses/LICENSE +674 -0
- htseq-2.1.2.dist-info/top_level.txt +1 -0
HTSeq/scripts/count.py
ADDED
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import argparse
|
|
3
|
+
import operator
|
|
4
|
+
import itertools
|
|
5
|
+
import warnings
|
|
6
|
+
import traceback
|
|
7
|
+
import os.path
|
|
8
|
+
import multiprocessing
|
|
9
|
+
import numpy as np
|
|
10
|
+
import pysam
|
|
11
|
+
|
|
12
|
+
import HTSeq
|
|
13
|
+
from HTSeq.scripts.count_features.count_features_per_file import count_reads_single_file
|
|
14
|
+
from HTSeq.scripts.utils import (
|
|
15
|
+
my_showwarning,
|
|
16
|
+
_write_output,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def count_reads_in_features(args):
|
|
21
|
+
"""Count reads in features, parallelizing by file
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
args: ArgumentParser args, i.e. each argument is a property of this
|
|
25
|
+
instance. Check the CLI parsing function below for a full list
|
|
26
|
+
of properties, i.e. command-line options.
|
|
27
|
+
|
|
28
|
+
This function can be conceptually split into the following steps:
|
|
29
|
+
|
|
30
|
+
1. Load features from GTF file into memory
|
|
31
|
+
2. Parse the reads from each BAM file in parallel or series
|
|
32
|
+
3. Write output table
|
|
33
|
+
|
|
34
|
+
Step 2 can be further split into two main components:
|
|
35
|
+
|
|
36
|
+
1. Find what features overlap with each read/read pair
|
|
37
|
+
2. Assign that read/pair to a feature (if unique) or a corner case
|
|
38
|
+
(e.g. multimappers)
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
# Load feature GenomicArrayOfSets to mark overlaps
|
|
42
|
+
gff = HTSeq.GFF_Reader(args.featuresfilename)
|
|
43
|
+
feature_scan = HTSeq.make_feature_genomicarrayofsets(
|
|
44
|
+
gff,
|
|
45
|
+
args.idattr,
|
|
46
|
+
feature_type=args.feature_type,
|
|
47
|
+
feature_query=args.feature_query,
|
|
48
|
+
additional_attributes=args.additional_attributes,
|
|
49
|
+
stranded=args.stranded != "no",
|
|
50
|
+
verbose=not args.quiet,
|
|
51
|
+
add_chromosome_info=args.add_chromosome_info,
|
|
52
|
+
)
|
|
53
|
+
features = feature_scan["features"]
|
|
54
|
+
attributes = feature_scan["attributes"]
|
|
55
|
+
feature_attr = sorted(attributes.keys())
|
|
56
|
+
if len(feature_attr) == 0:
|
|
57
|
+
sys.stderr.write("Warning: No features of type '{args.feature_type}' found.\n")
|
|
58
|
+
|
|
59
|
+
# Count reads in parallel or in series
|
|
60
|
+
count_args, attributes = _prepare_args_for_counting(
|
|
61
|
+
features,
|
|
62
|
+
feature_attr,
|
|
63
|
+
attributes,
|
|
64
|
+
args.add_chromosome_info,
|
|
65
|
+
args.additional_attributes,
|
|
66
|
+
args.feature_query,
|
|
67
|
+
args.feature_type,
|
|
68
|
+
args.featuresfilename,
|
|
69
|
+
args.idattr,
|
|
70
|
+
args.max_buffer_size,
|
|
71
|
+
args.minaqual,
|
|
72
|
+
args.nonunique,
|
|
73
|
+
args.order,
|
|
74
|
+
args.mode,
|
|
75
|
+
args.quiet,
|
|
76
|
+
args.samfilenames,
|
|
77
|
+
args.samout_format,
|
|
78
|
+
args.samouts,
|
|
79
|
+
args.secondary_alignments,
|
|
80
|
+
args.stranded,
|
|
81
|
+
args.supplementary_alignments,
|
|
82
|
+
)
|
|
83
|
+
if args.nprocesses > 1:
|
|
84
|
+
with multiprocessing.Pool(args.nprocesses) as pool:
|
|
85
|
+
results = pool.starmap(count_reads_single_file, count_args)
|
|
86
|
+
results.sort(key=operator.itemgetter("isam"))
|
|
87
|
+
else:
|
|
88
|
+
results = list(itertools.starmap(count_reads_single_file, count_args))
|
|
89
|
+
|
|
90
|
+
# Merge and write output
|
|
91
|
+
_write_output(
|
|
92
|
+
results,
|
|
93
|
+
args.samfilenames,
|
|
94
|
+
attributes,
|
|
95
|
+
args.additional_attributes,
|
|
96
|
+
args.output_filename,
|
|
97
|
+
args.output_delimiter,
|
|
98
|
+
args.output_append,
|
|
99
|
+
sparse=args.counts_output_sparse,
|
|
100
|
+
dtype=np.float32,
|
|
101
|
+
add_tsv_header=args.with_header
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _prepare_args_for_counting(
|
|
106
|
+
features,
|
|
107
|
+
feature_attr,
|
|
108
|
+
attributes,
|
|
109
|
+
add_chromosome_info,
|
|
110
|
+
additional_attributes,
|
|
111
|
+
feature_query,
|
|
112
|
+
feature_type,
|
|
113
|
+
gff_filename,
|
|
114
|
+
id_attribute,
|
|
115
|
+
max_buffer_size,
|
|
116
|
+
minaqual,
|
|
117
|
+
multimapped_mode,
|
|
118
|
+
order,
|
|
119
|
+
overlap_mode,
|
|
120
|
+
quiet,
|
|
121
|
+
sam_filenames,
|
|
122
|
+
samout_format,
|
|
123
|
+
samouts,
|
|
124
|
+
secondary_alignment_mode,
|
|
125
|
+
stranded,
|
|
126
|
+
supplementary_alignment_mode,
|
|
127
|
+
):
|
|
128
|
+
args = []
|
|
129
|
+
for isam, (sam_filename, samout_filename) in enumerate(zip(sam_filenames, samouts)):
|
|
130
|
+
args.append(
|
|
131
|
+
(
|
|
132
|
+
isam,
|
|
133
|
+
sam_filename,
|
|
134
|
+
features,
|
|
135
|
+
feature_attr,
|
|
136
|
+
order,
|
|
137
|
+
max_buffer_size,
|
|
138
|
+
stranded,
|
|
139
|
+
overlap_mode,
|
|
140
|
+
multimapped_mode,
|
|
141
|
+
secondary_alignment_mode,
|
|
142
|
+
supplementary_alignment_mode,
|
|
143
|
+
feature_type,
|
|
144
|
+
id_attribute,
|
|
145
|
+
additional_attributes,
|
|
146
|
+
quiet,
|
|
147
|
+
minaqual,
|
|
148
|
+
samout_format,
|
|
149
|
+
samout_filename,
|
|
150
|
+
)
|
|
151
|
+
)
|
|
152
|
+
return args, attributes
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _check_sam_files(sam_filenames):
|
|
156
|
+
if (len(sam_filenames) != 1) or (sam_filenames[0] != "-"):
|
|
157
|
+
for sam_filename in sam_filenames:
|
|
158
|
+
with pysam.AlignmentFile(sam_filename, "r") as sf:
|
|
159
|
+
pass
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _check_samouts(sam_filenames, samout_format, samouts):
|
|
163
|
+
if len(samouts) != len(sam_filenames):
|
|
164
|
+
raise ValueError("Select the same number of input and output files")
|
|
165
|
+
# Try to open samout files early in case any of them has issues
|
|
166
|
+
if samout_format in ("SAM", "sam"):
|
|
167
|
+
for samout in samouts:
|
|
168
|
+
with open(samout, "w"):
|
|
169
|
+
pass
|
|
170
|
+
else:
|
|
171
|
+
# We don't have a template if the input is stdin
|
|
172
|
+
if (len(sam_filenames) != 1) or (sam_filenames[0] != "-"):
|
|
173
|
+
for sam_filename, samout in zip(sam_filenames, samouts):
|
|
174
|
+
with pysam.AlignmentFile(sam_filename, "r") as sf:
|
|
175
|
+
with pysam.AlignmentFile(samout, "w", template=sf):
|
|
176
|
+
pass
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
# Adapted from: https://github.com/python/cpython/issues/60603
|
|
181
|
+
class OverwriteUniqueAppendAction(argparse.Action):
|
|
182
|
+
"""Custom action to append unique values to a list, overwriting the default.
|
|
183
|
+
|
|
184
|
+
When using the `append` action, the default value is not removed
|
|
185
|
+
from the list. This problem is described in
|
|
186
|
+
https://github.com/python/cpython/issues/60603
|
|
187
|
+
|
|
188
|
+
This custom action aims to fix this problem by removing the default
|
|
189
|
+
value when the argument is specified for the first time.
|
|
190
|
+
|
|
191
|
+
Moreover, it only appends if the value is not already there, so the resulting
|
|
192
|
+
list has unique elements.
|
|
193
|
+
"""
|
|
194
|
+
|
|
195
|
+
def __init__(self, option_strings, dest, nargs=None, **kwargs):
|
|
196
|
+
"""Initialize the action."""
|
|
197
|
+
self.called_times = 0
|
|
198
|
+
self.default_value = kwargs.get("default")
|
|
199
|
+
super().__init__(option_strings, dest, **kwargs)
|
|
200
|
+
|
|
201
|
+
def __call__(self, parser, namespace, values, option_string=None):
|
|
202
|
+
"""When the argument is specified on the commandline."""
|
|
203
|
+
current_values = getattr(namespace, self.dest)
|
|
204
|
+
|
|
205
|
+
if self.called_times == 0 and current_values == self.default_value:
|
|
206
|
+
current_values = []
|
|
207
|
+
|
|
208
|
+
# Only add if not already present (unique values)
|
|
209
|
+
if values not in current_values:
|
|
210
|
+
current_values.append(values)
|
|
211
|
+
|
|
212
|
+
setattr(namespace, self.dest, current_values)
|
|
213
|
+
self.called_times += 1
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _parse_sanitize_cmdline_arguments():
|
|
217
|
+
pa = argparse.ArgumentParser(
|
|
218
|
+
add_help=False,
|
|
219
|
+
)
|
|
220
|
+
pa.add_argument(
|
|
221
|
+
"--version", action="store_true", help="Show software version and exit"
|
|
222
|
+
)
|
|
223
|
+
args, argv = pa.parse_known_args()
|
|
224
|
+
|
|
225
|
+
# Version is the only case where the BAM and GTF files are optional
|
|
226
|
+
if args.version:
|
|
227
|
+
print(HTSeq.__version__)
|
|
228
|
+
sys.exit()
|
|
229
|
+
|
|
230
|
+
pa = argparse.ArgumentParser(
|
|
231
|
+
parents=[pa],
|
|
232
|
+
description="This script takes one or more alignment files in SAM/BAM "
|
|
233
|
+
+ "format and a feature file in GFF format and calculates for each feature "
|
|
234
|
+
+ "the number of reads mapping to it. See "
|
|
235
|
+
+ "http://htseq.readthedocs.io/en/master/count.html for details.",
|
|
236
|
+
epilog="Written by Simon Anders (sanders@fs.tum.de), "
|
|
237
|
+
+ "European Molecular Biology Laboratory (EMBL), Givanna Putri "
|
|
238
|
+
+ "(g.putri@unsw.edu.au) and Fabio Zanini "
|
|
239
|
+
+ "(fabio.zanini@unsw.edu.au), UNSW Sydney. (c) 2010-2021. "
|
|
240
|
+
+ "Released under the terms of the GNU General Public License v3. "
|
|
241
|
+
+ "Please cite the following paper if you use this script: \n"
|
|
242
|
+
+ " G. Putri et al. Analysing high-throughput sequencing data in "
|
|
243
|
+
+ "Python with HTSeq 2.0. Bioinformatics (2022). "
|
|
244
|
+
+ "https://doi.org/10.1093/bioinformatics/btac166.\n"
|
|
245
|
+
+ "Part of the 'HTSeq' framework, version %s." % HTSeq.__version__,
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
pa.add_argument(
|
|
249
|
+
"samfilenames",
|
|
250
|
+
nargs="+",
|
|
251
|
+
type=str,
|
|
252
|
+
help="Path to the SAM/BAM files containing the mapped reads. "
|
|
253
|
+
+ "If '-' is selected, read from standard input",
|
|
254
|
+
)
|
|
255
|
+
pa.add_argument(
|
|
256
|
+
"featuresfilename",
|
|
257
|
+
type=str,
|
|
258
|
+
help="Path to the GTF file containing the features",
|
|
259
|
+
)
|
|
260
|
+
pa.add_argument(
|
|
261
|
+
"-f",
|
|
262
|
+
"--format",
|
|
263
|
+
dest="samtype",
|
|
264
|
+
choices=("sam", "bam", "auto"),
|
|
265
|
+
default="auto",
|
|
266
|
+
help="Type of <alignment_file> data. DEPRECATED: "
|
|
267
|
+
+ "file format is detected automatically. This option is ignored.",
|
|
268
|
+
)
|
|
269
|
+
pa.add_argument(
|
|
270
|
+
"-r",
|
|
271
|
+
"--order",
|
|
272
|
+
dest="order",
|
|
273
|
+
choices=("pos", "name"),
|
|
274
|
+
default="name",
|
|
275
|
+
help="'pos' or 'name'. Sorting order of <alignment_file> (default: name). Paired-end sequencing "
|
|
276
|
+
+ "data must be sorted either by position or by read name, and the sorting order "
|
|
277
|
+
+ "must be specified. Ignored for single-end data.",
|
|
278
|
+
)
|
|
279
|
+
pa.add_argument(
|
|
280
|
+
"--max-reads-in-buffer",
|
|
281
|
+
dest="max_buffer_size",
|
|
282
|
+
type=int,
|
|
283
|
+
default=30000000,
|
|
284
|
+
help="When <alignment_file> is paired end sorted by position, "
|
|
285
|
+
+ "allow only so many reads to stay in memory until the mates are "
|
|
286
|
+
+ "found (raising this number will use more memory). Has no effect "
|
|
287
|
+
+ "for single end or paired end sorted by name",
|
|
288
|
+
)
|
|
289
|
+
pa.add_argument(
|
|
290
|
+
"-s",
|
|
291
|
+
"--stranded",
|
|
292
|
+
dest="stranded",
|
|
293
|
+
choices=("yes", "no", "reverse"),
|
|
294
|
+
default="yes",
|
|
295
|
+
help="Whether the data is from a strand-specific assay. Specify 'yes', "
|
|
296
|
+
+ "'no', or 'reverse' (default: yes). "
|
|
297
|
+
+ "'reverse' means 'yes' with reversed strand interpretation",
|
|
298
|
+
)
|
|
299
|
+
pa.add_argument(
|
|
300
|
+
"-a",
|
|
301
|
+
"--minaqual",
|
|
302
|
+
type=int,
|
|
303
|
+
dest="minaqual",
|
|
304
|
+
default=10,
|
|
305
|
+
help="Skip all reads with MAPQ alignment quality lower than the given "
|
|
306
|
+
+ "minimum value (default: 10). MAPQ is the 5th column of a SAM/BAM "
|
|
307
|
+
+ "file and its usage depends on the software used to map the reads.",
|
|
308
|
+
)
|
|
309
|
+
pa.add_argument(
|
|
310
|
+
"-t",
|
|
311
|
+
"--type",
|
|
312
|
+
type=str,
|
|
313
|
+
dest="feature_type",
|
|
314
|
+
action=OverwriteUniqueAppendAction,
|
|
315
|
+
default=["exon"],
|
|
316
|
+
help="Feature type (3rd column in GTF file) to be used, "
|
|
317
|
+
+ "all features of other type are ignored (default, suitable for"
|
|
318
|
+
+ "Ensembl GTF files: exon). If you can call this option multiple times, "
|
|
319
|
+
+ "features of all specified types will be included, e.g. to include "
|
|
320
|
+
+ "both genes and pseudogenes you might use -t gene -t pseudogene. "
|
|
321
|
+
+ "Calling this option multiple times is a rare need and might result "
|
|
322
|
+
+ "in excessive numbers of ambiguous counts: only use if you know what "
|
|
323
|
+
+ "you are doing.",
|
|
324
|
+
)
|
|
325
|
+
pa.add_argument(
|
|
326
|
+
"-i",
|
|
327
|
+
"--idattr",
|
|
328
|
+
type=str,
|
|
329
|
+
dest="idattr",
|
|
330
|
+
action=OverwriteUniqueAppendAction,
|
|
331
|
+
default=["gene_id"],
|
|
332
|
+
help="GTF attribute to be used as feature ID (default, "
|
|
333
|
+
+ "suitable for Ensembl GTF files: gene_id). All feature of the "
|
|
334
|
+
+ "right type (see -t option) within the same GTF attribute will "
|
|
335
|
+
+ "be added together. The typical way of using this option is to "
|
|
336
|
+
+ "count all exonic reads from each gene and add the exons "
|
|
337
|
+
+ "but other uses are possible as well. You can call this option "
|
|
338
|
+
+ "multiple times: in that case, the combination of all attributes "
|
|
339
|
+
+ "separated by colons (:) will be used as a unique identifier, "
|
|
340
|
+
+ "e.g. for exons you might use -i gene_id -i exon_number.",
|
|
341
|
+
)
|
|
342
|
+
pa.add_argument(
|
|
343
|
+
"--additional-attr",
|
|
344
|
+
type=str,
|
|
345
|
+
action='append',
|
|
346
|
+
dest='additional_attributes',
|
|
347
|
+
default=[],
|
|
348
|
+
help="Additional feature attributes (default: none, "
|
|
349
|
+
+ "suitable for Ensembl GTF files: gene_name). Use multiple times "
|
|
350
|
+
+ "for more than one additional attribute. These attributes are "
|
|
351
|
+
+ "only used as annotations in the output, while the determination "
|
|
352
|
+
+ "of how the counts are added together is done based on option -i.",
|
|
353
|
+
)
|
|
354
|
+
pa.add_argument(
|
|
355
|
+
"--add-chromosome-info",
|
|
356
|
+
action="store_true",
|
|
357
|
+
help="Store information about the chromosome of each feature as "
|
|
358
|
+
+ "an additional attribute (e.g. colunm in the TSV output file).",
|
|
359
|
+
)
|
|
360
|
+
pa.add_argument(
|
|
361
|
+
"-m",
|
|
362
|
+
"--mode",
|
|
363
|
+
dest="mode",
|
|
364
|
+
choices=("union", "intersection-strict", "intersection-nonempty"),
|
|
365
|
+
default="union",
|
|
366
|
+
help="Mode to handle reads overlapping more than one feature "
|
|
367
|
+
+ "(choices: union, intersection-strict, intersection-nonempty; default: union)",
|
|
368
|
+
)
|
|
369
|
+
pa.add_argument(
|
|
370
|
+
"--nonunique",
|
|
371
|
+
dest="nonunique",
|
|
372
|
+
type=str,
|
|
373
|
+
choices=("none", "all", "fraction", "random"),
|
|
374
|
+
default="none",
|
|
375
|
+
help="Whether and how to score reads that are not uniquely aligned "
|
|
376
|
+
+ "or ambiguously assigned to features "
|
|
377
|
+
+ "(choices: none, all, fraction, random; default: none)",
|
|
378
|
+
)
|
|
379
|
+
pa.add_argument(
|
|
380
|
+
"--secondary-alignments",
|
|
381
|
+
dest="secondary_alignments",
|
|
382
|
+
type=str,
|
|
383
|
+
choices=("score", "ignore"),
|
|
384
|
+
default="ignore",
|
|
385
|
+
help="Whether to score secondary alignments (0x100 flag)",
|
|
386
|
+
)
|
|
387
|
+
pa.add_argument(
|
|
388
|
+
"--supplementary-alignments",
|
|
389
|
+
dest="supplementary_alignments",
|
|
390
|
+
type=str,
|
|
391
|
+
choices=("score", "ignore"),
|
|
392
|
+
default="ignore",
|
|
393
|
+
help="Whether to score supplementary alignments (0x800 flag)",
|
|
394
|
+
)
|
|
395
|
+
pa.add_argument(
|
|
396
|
+
"-o",
|
|
397
|
+
"--samout",
|
|
398
|
+
type=str,
|
|
399
|
+
dest="samouts",
|
|
400
|
+
action='append',
|
|
401
|
+
default=[],
|
|
402
|
+
help="Write out all SAM alignment records into "
|
|
403
|
+
+ "SAM/BAM files (one per input file needed), annotating each line "
|
|
404
|
+
+ "with its feature assignment (as an optional field with tag 'XF')"
|
|
405
|
+
+ ". See the -p option to use BAM instead of SAM.",
|
|
406
|
+
)
|
|
407
|
+
pa.add_argument(
|
|
408
|
+
"-p",
|
|
409
|
+
"--samout-format",
|
|
410
|
+
type=str,
|
|
411
|
+
dest="samout_format",
|
|
412
|
+
choices=("SAM", "BAM", "sam", "bam"),
|
|
413
|
+
default="SAM",
|
|
414
|
+
help="Format to use with the --samout option.",
|
|
415
|
+
)
|
|
416
|
+
pa.add_argument(
|
|
417
|
+
"-d",
|
|
418
|
+
"--delimiter",
|
|
419
|
+
type=str,
|
|
420
|
+
dest="output_delimiter",
|
|
421
|
+
default="\t",
|
|
422
|
+
help="Column delimiter in output (default: TAB).",
|
|
423
|
+
)
|
|
424
|
+
pa.add_argument(
|
|
425
|
+
"-c",
|
|
426
|
+
"--counts_output",
|
|
427
|
+
type=str,
|
|
428
|
+
dest="output_filename",
|
|
429
|
+
default="",
|
|
430
|
+
help="Filename to output the counts to instead of stdout.",
|
|
431
|
+
)
|
|
432
|
+
pa.add_argument(
|
|
433
|
+
"--counts-output-sparse",
|
|
434
|
+
action="store_true",
|
|
435
|
+
help="Store the counts as a sparse matrix (mtx, h5ad, loom).",
|
|
436
|
+
)
|
|
437
|
+
pa.add_argument(
|
|
438
|
+
"--append-output",
|
|
439
|
+
action="store_true",
|
|
440
|
+
dest="output_append",
|
|
441
|
+
help="Append counts output to an existing file instead of "
|
|
442
|
+
+ "creating a new one. This option is useful if you have "
|
|
443
|
+
+ "already creates a TSV/CSV/similar file with a header for your "
|
|
444
|
+
+ "samples (with additional columns for the feature name and any "
|
|
445
|
+
+ "additionl attributes) and want to fill in the rest of the file.",
|
|
446
|
+
)
|
|
447
|
+
pa.add_argument(
|
|
448
|
+
"-n",
|
|
449
|
+
"--nprocesses",
|
|
450
|
+
type=int,
|
|
451
|
+
dest="nprocesses",
|
|
452
|
+
default=1,
|
|
453
|
+
help="Number of parallel CPU processes to use (default: 1). "
|
|
454
|
+
+ "This option is useful to process several input files at once. "
|
|
455
|
+
+ "Each file will use only 1 CPU. It is possible, of course, to "
|
|
456
|
+
+ "split a very large input SAM/BAM files into smaller chunks "
|
|
457
|
+
+ "upstream to make use of this option.",
|
|
458
|
+
)
|
|
459
|
+
pa.add_argument(
|
|
460
|
+
"--feature-query",
|
|
461
|
+
type=str,
|
|
462
|
+
dest="feature_query",
|
|
463
|
+
default=None,
|
|
464
|
+
help="Restrict to features descibed in this expression. Currently "
|
|
465
|
+
+ 'supports a single kind of expression: attribute == "one attr" to '
|
|
466
|
+
+ "restrict the GFF to a single gene or transcript, e.g. "
|
|
467
|
+
+ "--feature-query 'gene_name == \"ACTB\"' - notice the single "
|
|
468
|
+
+ "quotes around the argument of this option and the double "
|
|
469
|
+
+ "quotes around the gene name. Broader queries might become "
|
|
470
|
+
+ "available in the future.",
|
|
471
|
+
)
|
|
472
|
+
pa.add_argument(
|
|
473
|
+
"-q",
|
|
474
|
+
"--quiet",
|
|
475
|
+
action="store_true",
|
|
476
|
+
dest="quiet",
|
|
477
|
+
help="Suppress progress report",
|
|
478
|
+
) # and warnings" )
|
|
479
|
+
|
|
480
|
+
pa.add_argument(
|
|
481
|
+
"--with-header",
|
|
482
|
+
action="store_true",
|
|
483
|
+
dest="with_header",
|
|
484
|
+
help="Whether to add a column header to the output TSV file indicating which column "
|
|
485
|
+
+ "corresponds to which input BAM file. Only used if output to console or tsv or csv file. "
|
|
486
|
+
+ "Default to False."
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
args = pa.parse_args()
|
|
490
|
+
|
|
491
|
+
# Never use more CPUs than files
|
|
492
|
+
args.nprocesses = min(args.nprocesses, len(args.samfilenames))
|
|
493
|
+
|
|
494
|
+
# Check and sanitize annotated SAM/BAM outputs
|
|
495
|
+
if args.samouts != []:
|
|
496
|
+
_check_samouts(args.samfilenames, args.samout_format, args.samouts)
|
|
497
|
+
else:
|
|
498
|
+
args.samouts = [None for x in args.samfilenames]
|
|
499
|
+
|
|
500
|
+
# Try to open samfiles to fail early in case any of them is not there
|
|
501
|
+
_check_sam_files(args.samfilenames)
|
|
502
|
+
|
|
503
|
+
return args
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
def main():
|
|
507
|
+
'''Main loop for htseq-count'''
|
|
508
|
+
|
|
509
|
+
args = _parse_sanitize_cmdline_arguments()
|
|
510
|
+
|
|
511
|
+
warnings.showwarning = my_showwarning
|
|
512
|
+
try:
|
|
513
|
+
count_reads_in_features(args)
|
|
514
|
+
except:
|
|
515
|
+
sys.stderr.write(" %s\n" % str(sys.exc_info()[1]))
|
|
516
|
+
sys.stderr.write(
|
|
517
|
+
" [Exception type: %s, raised in %s:%d]\n"
|
|
518
|
+
% (
|
|
519
|
+
sys.exc_info()[1].__class__.__name__,
|
|
520
|
+
os.path.basename(traceback.extract_tb(sys.exc_info()[2])[-1][0]),
|
|
521
|
+
traceback.extract_tb(sys.exc_info()[2])[-1][1],
|
|
522
|
+
)
|
|
523
|
+
)
|
|
524
|
+
sys.exit(1)
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
if __name__ == "__main__":
|
|
528
|
+
main()
|
|
File without changes
|