Skip to content

Commit

Permalink
Fix remaining problem for #470 by overriding HCV subtype elsewhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
donkirkby committed Jun 19, 2019
1 parent da6fa92 commit 45eb80a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
[travis]: https://travis-ci.org/cfe-lab/MiCall
[Code Coverage]: https://codecov.io/github/cfe-lab/MiCall/coverage.svg?branch=master
[codecov]: https://codecov.io/github/cfe-lab/MiCall?branch=master
[DOI]: https://zenodo.org/badge/DOI/10.5281/zenodo.2644171.svg
[zenodo]: https://doi.org/10.5281/zenodo.2644171
[DOI]: https://zenodo.org/badge/DOI/10.5281/zenodo.1289989.svg
[zenodo]: https://doi.org/10.5281/zenodo.1289989

Maps all the reads from a sample against a set of reference sequences, then
stitches all the reads into consensus sequences and coverage maps.
Expand Down
6 changes: 4 additions & 2 deletions micall/resistance/resistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def combine_aminos(amino_csv, midi_amino_csv, failures):
in the midi_amino_csv file.
"""
is_midi = True
midi_rows = {} # {seed: [row]}
midi_rows = {} # {genotype: [row]}
midi_start = 231
midi_end = 561
is_midi_separate = midi_amino_csv.name != amino_csv.name
Expand Down Expand Up @@ -203,14 +203,16 @@ def combine_midi_rows(main_rows, midi_rows, seed):
positions = sorted({pos
for pos in chain(main_row_map.keys(),
midi_row_map.keys())})

for midi_row in midi_row_map.values():
midi_row['seed'] = seed # Override MIDI seed with main seed.
for pos in positions:
main_row = main_row_map.get(pos)
midi_row = midi_row_map.get(pos)
if midi_row is None:
if pos <= 336:
yield main_row
elif main_row is None:
midi_row['seed'] = seed # Override MIDI seed with main seed.
yield midi_row
elif (pos <= 336 and
int(main_row['coverage']) > int(midi_row['coverage'])):
Expand Down
45 changes: 39 additions & 6 deletions micall/tests/test_resistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ def test_combine_aminos_ns5b_multiple_subtypes():
seed,region,q-cutoff,query.nuc.pos,refseq.aa.pos,\
A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y,*,X,partial,del,ins,clip,g2p_overlap,coverage
HCV-4m,HCV4-ED43-NS5b,15,1,558,0,0,0,0,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4m,HCV4-ED43-NS5b,15,1,559,0,0,0,0,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4m,HCV4-ED43-NS5b,15,4,560,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4m,HCV4-ED43-NS5b,15,7,561,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4m,HCV4-ED43-NS5b,15,4,559,0,0,0,0,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4m,HCV4-ED43-NS5b,15,7,560,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4m,HCV4-ED43-NS5b,15,10,561,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
""")
midi_amino_csv.name = 'midi_amino.csv'
expected_csv = """\
Expand All @@ -335,9 +335,42 @@ def test_combine_aminos_ns5b_multiple_subtypes():
HCV-4c,HCV4-ED43-NS5b,15,4,2,0,0,0,0,10000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10000
HCV-4c,HCV4-ED43-NS5b,15,7,228,10000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10000
HCV-4c,HCV4-ED43-NS5b,15,1,558,0,0,0,0,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4c,HCV4-ED43-NS5b,15,1,559,0,0,0,0,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4c,HCV4-ED43-NS5b,15,4,560,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4c,HCV4-ED43-NS5b,15,7,561,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4c,HCV4-ED43-NS5b,15,4,559,0,0,0,0,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4c,HCV4-ED43-NS5b,15,7,560,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4c,HCV4-ED43-NS5b,15,10,561,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
"""

check_combination(amino_csv, midi_amino_csv, expected_csv)


def test_combine_aminos_ns5b_multiple_subtypes_with_overlap():
""" Main sample's subtype overrides MIDI subtype when they disagree. """
amino_csv = StringIO("""\
seed,region,q-cutoff,query.nuc.pos,refseq.aa.pos,\
A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y,*,X,partial,del,ins,clip,g2p_overlap,coverage
HCV-4c,HCV4-ED43-NS5b,15,1,1,0,0,0,0,0,0,0,0,10000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10000
HCV-4c,HCV4-ED43-NS5b,15,4,2,0,0,0,0,10000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10000
HCV-4c,HCV4-ED43-NS5b,15,7,228,10000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10000
""")
amino_csv.name = 'main_amino.csv'
midi_amino_csv = StringIO("""\
seed,region,q-cutoff,query.nuc.pos,refseq.aa.pos,\
A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y,*,X,partial,del,ins,clip,g2p_overlap,coverage
HCV-4m,HCV4-ED43-NS5b,15,1,228,0,0,0,0,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4m,HCV4-ED43-NS5b,15,4,559,0,0,0,0,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4m,HCV4-ED43-NS5b,15,7,560,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4m,HCV4-ED43-NS5b,15,10,561,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
""")
midi_amino_csv.name = 'midi_amino.csv'
expected_csv = """\
seed,region,q-cutoff,query.nuc.pos,refseq.aa.pos,\
A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y,*,X,partial,del,ins,clip,g2p_overlap,coverage
HCV-4c,HCV4-ED43-NS5b,15,1,1,0,0,0,0,0,0,0,0,10000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10000
HCV-4c,HCV4-ED43-NS5b,15,4,2,0,0,0,0,10000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10000
HCV-4c,HCV4-ED43-NS5b,15,1,228,0,0,0,0,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4c,HCV4-ED43-NS5b,15,4,559,0,0,0,0,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4c,HCV4-ED43-NS5b,15,7,560,0,0,0,0,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
HCV-4c,HCV4-ED43-NS5b,15,10,561,20000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20000
"""

check_combination(amino_csv, midi_amino_csv, expected_csv)
Expand Down

0 comments on commit 45eb80a

Please sign in to comment.