forked from TomSkelly/PacBioEDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PacBio_CmpDetails.py
executable file
·111 lines (83 loc) · 3.6 KB
/
PacBio_CmpDetails.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
#!/usr/bin/env python
# Copyright (C) 2011 Genome Research Limited -- See full notice at end
# of module.
# Print details of sub-read alignments for one movie from a cmp.h5
# file. Alignments are printed in the order in which they appear in
# the cmp file, which may have been sorted in several ways. Note that
# one of the corresponding bas.h5 files must be specified as the first
# command line parameter, to determine the desired movie.
# See the --help option for details. Output is to stdout.
import sys
import optparse
import H5BasFile
import H5CmpFile
from tt_log import logger
def main ():
logger.debug("%s starting" % sys.argv[0])
opt, args = getParms()
if len(args) != 2:
logger.error ("please specify bas.h5 and cmp.h5 files as parameters. See --help")
sys.exit()
basFilename = args[0]
logger.debug("bas file: %s" % basFilename)
bf = H5BasFile.BasFile (basFilename)
cmpFilename = args[1]
logger.debug("cmp file: %s" % cmpFilename)
cf = H5CmpFile.CmpFile (fileName=cmpFilename)
cmp = H5CmpFile.CmpMovie (cmpObject=cf,
movieName=bf.movieName(),
maxHole=bf.maxZMW())
cf.printDetails()
print " AlnID RG Hole Set Stb SubRd Seq Ref St Start End RefStrt RefEnd OffStrt OffEnd"
print
if opt.sort == 'hole':
for align in cmp.getAlignmentsByHole():
printAlign(align)
else : # else, must be 'none'
for align in cmp.getAllAlignments(): # generator function, returns a dict
printAlign(align)
logger.debug("complete")
def printAlign (align):
print "%6d %2d %5d %2d %2d %5d %2d %2d %1d %9d %9d %6d %6d %9d %9d %5d %5d" \
% (align['AlignmentId'],
align['ReadGroupId'],
align['HoleNumber'],
align['SetNumber'],
align['StrobeNumber'],
align['SubreadId'],
align['RefSeqId'],
align['contig'], # chicanery here, see H5CmpFile.py
align['RCRefStrand'],
align['tStart'],
align['tEnd'],
align['rStart'],
align['rEnd'],
align['offset_begin'],
align['offset_end'],
align['rEnd'] - align['rStart'],
align['tEnd'] - align['tStart'])
return
def getParms (): # use default input sys.argv[1:]
parser = optparse.OptionParser(usage='%prog [options] <bas_file> <cmp_file>',
description='Print (to stdout) summary information about the contents of a cmp.h5 file.')
parser.add_option ('--sort', type='choice', choices=['hole', 'none'],
help='desired sort order: none/hole (def: %default)')
parser.set_defaults (sort='none')
opt, args = parser.parse_args()
return opt, args
if __name__ == "__main__":
main()
# Copyright (C) 2011 Genome Research Limited
#
# This library is free software. You can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.