-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseSAMOutput.py
executable file
·64 lines (48 loc) · 1.49 KB
/
parseSAMOutput.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
#!python
# Load libraries
import sys, getopt
import pysam
import libPipeline
# Set constants
helpMsg ='''
SYNOPSIS
parseSAMOutput
parseSAMOutput [OPTIONS] SAMFILE
#
DESCRIPTION
parseSAMOutput.py
Parses SAM alignments into paired-end read summaries.
Prints results to stdout.
If SAMFILE has a .sam or .SAM file extension, it is converted to BAM and all
transformations (sorting, rmdup) are run via samtools.
If SAMFILE has a .bam or .BAM file extension, conversion to BAM is skipped
and all transformations are run via samtools.
If SAMFILE has a .sorted.bam file extension (in any case), then sorting is
skipped.
If SAMFILE has a .unique.bam file extension, all samtools processing is
skipped, including rmdup.
OPTIONS
--rmdup Remove duplicate reads (reduces PCR effects)
-h/--help Print help message and exit
'''
if __name__ == "__main__":
# Set defaults
rmdup = False
# Parse arguments
options, args = getopt.getopt(sys.argv[1:], 'h', ["help", "rmdup"])
for opt, value in options:
if opt in ("-h", "--help"):
print >> sys.stderr, helpMsg
sys.exit(2)
elif opt == "--rmdup":
rmdup = True
else:
print >> sys.stderr, "Error -- option %s not recognized" % opt
sys.exit(1)
# Parse arguments & options
if len(args) > 0:
alignmentPath = args[0]
else:
print >> sys.stderr, "Error -- need path to SAM file"
sys.exit(1)
libPipeline.processSAMOutput(alignmentPath, sys.stdout, rmdup=rmdup)