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 __author__ = "Michael Imelfort"
28 __copyright__ = "Copyright 2014"
29 __credits__ = ["Michael Imelfort"]
30 __license__ = "LGPLv3"
31 __maintainer__ = "Michael Imelfort"
32 __email__ = "mike@mikeimelfort.com"
33
34
35
36
37 import ctypes as c
38
39
40 from cWrapper import *
41
42
43
44
45
46
47
49 '''A single link joining two contigs'''
50
51 - def __init__(self,
52 r1,
53 r2,
54 p1,
55 p2,
56 bid = None):
57 '''Default constructor.
58
59 Initializes a BM_LinkInfo instance with the provided set of properties.
60
61 Inputs:
62 r1 - int, == 1 if the read maps to contig 1 in reverse orientation
63 r2 - int, == 1 if the read maps to contig 2 in reverse orientation
64 pos1 - int, leftmost position of read on contig 1
65 pos2 - int, leftmost position of read on contig 2
66 bid - unique identifier for the bam file describing this link
67
68 Outputs:
69 None
70 '''
71 self.reversed1 = r1
72 self.reversed2 = r2
73 self.pos1 = p1
74 self.pos2 = p2
75 self.bamID = bid
76
77 - def printMore(self,
78 bamFileNames,
79 len1,
80 len2):
81 '''Advanced string function
82
83 used for creating output to links file
84
85 Inputs:
86 bamFileNames - { bamId : string }, storage for long bam file names
87 len1 - int, length of contig 1
88 len1 - int, length of contig 2
89
90 Outputs:
91 String describing the link
92 '''
93 return "%d\t%d\t%d\t%d\t%d\t%d\t%s" % (len1,
94 self.pos1,
95 self.reversed1,
96 len2,
97 self.pos2,
98 self.reversed2,
99 bamFileNames[self.bamID])
100
102 '''override basic string function'''
103 return "%d\t%d\t%d\t%d\t%s" % (self.pos1,
104 self.reversed1,
105 self.pos2,
106 self.reversed2,
107 self.bamID)
108
109
110
111
112
113
114
115
117 '''Container class for storing all links joining two contigs'''
118
119 - def __init__(self,
120 cid1,
121 cid2):
122 '''Default constructor.
123
124 Initializes a BM_LinkPair instance with the provided set of properties.
125
126 Inputs:
127 cid1 - unique identifier for contig 1
128 cid2 - unique identifier for contig 2
129
130 Outputs:
131 None
132 '''
133 self.cid1 = cid1
134 self.cid2 = cid2
135 self.numLinks = 0
136 self.links = []
137
138 - def addLink(self,
139 r1,
140 r2,
141 p1,
142 p2,
143 bamFile):
144 '''Add a link between the two contigs
145
146 Inputs:
147 r1 - int, == 1 if the read maps to contig 1 in reverse orientation
148 r2 - int, == 1 if the read maps to contig 2 in reverse orientation
149 pos1 - int, leftmost position of read on contig 1
150 pos2 - int, leftmost position of read on contig 2
151 bamFile - BM_bamFile instance that describes this link
152
153 Outputs:
154 None
155 '''
156 LI = BM_linkInfo(r1,
157 r2,
158 p1,
159 p2,
160 bamFile.bid)
161 self.links.append(LI)
162 self.numLinks += 1
163
165 '''Return a unique key for this link pair'''
166 return "%d,%d" % (self.cid1, self.cid2)
167
168 - def printMore(self,
169 contigNames,
170 contigLengths,
171 bamFileNames):
172 '''Advanced string function
173
174 used for creating output to links file
175 calls link.printmore()
176
177 Inputs:
178 contigNames - { cid : string }, storage for long contig names
179 contigLengths - { cid : int }, storage for contig lengths
180 bamFileNames - { bamId : string }, storage for long bam file names
181
182 Outputs:
183 Multi-line string descrtibing all the links between the two contigs
184 '''
185
186 """Print function used to export a tabular format"""
187 return "\n".join(["%s\t%s\t%s"%(contigNames[self.cid1],
188 contigNames[self.cid2],
189 link.printMore(bamFileNames,
190 contigLengths[self.cid1],
191 contigLengths[self.cid2]
192 )
193 )
194 for link in self.links])
195
197 '''override basic string function'''
198 return "\n".join(["%s\t%s\t%s" % (self.cid1,
199 self.cid2,
200 link) for link in self.links]
201 )
202
203
204
205
206
207