-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildReadLengthDist.py
executable file
·57 lines (49 loc) · 1.5 KB
/
buildReadLengthDist.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
#!python
# Import packages
import libPipeline
import sys
import getopt
helpMsg = '''
SYNOPSIS
buildReadLengthDist
buildReadLengthDist [OPTIONS] [FILE]
#
DESCRIPTION
buildReadLengthDist.py
Builds distribution of read lengths from file of raw paired-end data.
Prints distribution in two-column format to stdout.
First column is length, second is number of reads with that length.
OPTIONS
-o/--offset= Offset (number of base pairs read per end);
defaults to 35bp
-h/--help Print help message and exit
'''
if __name__=="__main__":
# Set default parameters
offset = 0
# Parse arguments
options, args = getopt.getopt(sys.argv[1:], "o:h",
["offset=","help"])
#
for opt, value in options:
if opt in ('-h', "--help"):
print >> sys.stderr, helpMsg
sys.exit(2)
elif opt in ('-o', "--offset"):
offset = int(value)
else:
print >> sys.stderr, "Error -- option %s not recognized" % opt
sys.exit(1)
#
if len(args) < 1:
dataFile = sys.stdin
else:
rawDataFilename = args[0]
try:
dataFile = open(rawDataFilename, "rb")
except:
print >> sys.stderr, "Error -- could not open %s" % rawDataFilename
sys.exit(1)
# Build distribution and write to stdout
libPipeline.getReadLengthDist(dataFile, sys.stdout, offset)
sys.exit(0)