File tree 1 file changed +25
-1
lines changed
1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 2
2
from dataclasses import dataclass
3
3
from fractions import Fraction
4
4
import csv
5
+ import os
5
6
6
7
from micall .utils .contig_stitcher_contigs import Contig
7
8
from micall .utils .find_maximum_overlap import find_maximum_overlap
@@ -142,7 +143,30 @@ def stitch_consensus(contigs: Iterable[Contig]) -> Iterable[Contig]:
142
143
if not most_probable .has_contig (contig ))
143
144
144
145
145
- def read_referenceless_contigs (input_csv : TextIO ) -> Iterable [Contig ]:
146
+ def write_contigs (output_csv : TextIO , contigs : Iterable [Contig ]):
147
+ writer = csv .DictWriter (output_csv , fieldnames = ['contig' ],
148
+ lineterminator = os .linesep )
149
+ writer .writeheader ()
150
+ for contig in contigs :
151
+ writer .writerow (dict (contig = contig .seq ))
152
+ output_csv .flush ()
153
+
154
+
155
+ def read_contigs (input_csv : TextIO ) -> Iterable [Contig ]:
146
156
for row in csv .DictReader (input_csv ):
147
157
seq = row ['contig' ]
148
158
yield Contig (name = None , seq = seq )
159
+
160
+
161
+ def referenceless_contig_stitcher (input_csv : TextIO ,
162
+ output_csv : Optional [TextIO ],
163
+ ) -> int :
164
+ contigs = list (read_contigs (input_csv ))
165
+
166
+ if output_csv is not None :
167
+ contigs = list (stitch_consensus (contigs ))
168
+
169
+ if output_csv is not None :
170
+ write_contigs (output_csv , contigs )
171
+
172
+ return len (contigs )
You can’t perform that action at this time.
0 commit comments