Skip to content

Commit

Permalink
Don't assume that conseq_ins.csv is sorted by refname, for #442.
Browse files Browse the repository at this point in the history
  • Loading branch information
donkirkby committed Jan 17, 2020
1 parent 6af6593 commit 34a5c35
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions micall/core/aln2counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,18 @@ def read_clipping(self, clipping_csv):

def read_insertions(self, conseq_ins_csv):
reader = csv.DictReader(conseq_ins_csv)
for refname, rows in groupby(reader, itemgetter('refname')):
insertion_names = defaultdict(set) # {pos: set([qname])}
for row in rows:
pos = int(row['pos'])
pos_names = insertion_names[pos]
pos_names.add(row['qname'])
self.conseq_insertion_counts[refname] = Counter(
{pos: len(names) for pos, names in insertion_names.items()})

# {ref: {pos: set([qname])}}
insertion_names = defaultdict(lambda: defaultdict(set))

for row in reader:
ref_name = row['refname']
pos = int(row['pos'])
pos_names = insertion_names[ref_name][pos]
pos_names.add(row['qname'])
for ref_name, ref_positions in insertion_names.items():
self.conseq_insertion_counts[ref_name] = Counter(
{pos: len(names) for pos, names in ref_positions.items()})

@staticmethod
def _create_amino_writer(amino_file):
Expand Down
2 changes: 1 addition & 1 deletion micall/tests/test_aln2counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,9 @@ def testInsertionBetweenReadAndConsensusNucleotideReport(self):
conseq_ins_csv = StringIO("""\
qname,fwd_rev,refname,pos,insert,qual
Example_read_1,F,R1-seed,3,AAC,AAA
Example_read_3,F,R2-seed,6,GTA,AAA
Example_read_2,F,R1-seed,3,AAC,AAA
Example_read_2,R,R1-seed,3,AAC,AAA
Example_read_3,F,R2-seed,6,GTA,AAA
""")

expected_text = """\
Expand Down

0 comments on commit 34a5c35

Please sign in to comment.