Skip to content

Commit 7c23561

Browse files
authored
Merge pull request #169 from openvax/codex/fix-allele-counts-cli-output
[codex] Restore allele-count CLI output
2 parents d79fa7c + 019613c commit 7c23561

5 files changed

Lines changed: 42 additions & 11 deletions

File tree

isovar/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13-
__version__ = "1.4.18"
13+
__version__ = "1.4.19"
1414

1515

1616
from .allele_read import AlleleRead

isovar/cli/isovar_allele_counts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from ..logging import get_logger
2020

21-
from .rna_args import make_rna_reads_arg_parser, read_evidence_dataframe_from_args
21+
from .rna_args import make_rna_reads_arg_parser, allele_counts_dataframe_from_args
2222
from .output_args import add_output_args, write_dataframe
2323

2424

@@ -28,15 +28,15 @@
2828
parser = add_output_args(
2929
parser,
3030
filename="isovar-allele-counts-result.csv",
31-
description="Name of CSV file which contains read sequences")
31+
description="Name of CSV file which contains read and fragment counts")
3232

3333

3434
def run(args=None):
3535
if args is None:
3636
args = sys.argv[1:]
3737
args = parser.parse_args(args)
3838
logger.info(args)
39-
df = read_evidence_dataframe_from_args(args)
39+
df = allele_counts_dataframe_from_args(args)
4040
logger.info(df)
4141
write_dataframe(
4242
df=df,

isovar/cli/rna_args.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
from ..default_parameters import MIN_READ_MAPPING_QUALITY
2222

2323
from ..read_collector import ReadCollector
24-
from ..dataframe_helpers import allele_reads_to_dataframe, read_evidence_generator_to_dataframe
24+
from ..dataframe_helpers import (
25+
allele_counts_dataframe,
26+
allele_reads_to_dataframe,
27+
read_evidence_generator_to_dataframe,
28+
)
2529

2630

2731
def add_rna_args(
@@ -160,6 +164,15 @@ def read_evidence_dataframe_from_args(args):
160164
read_evidence_generator_from_args(args))
161165

162166

167+
def allele_counts_dataframe_from_args(args):
168+
"""
169+
Collect read and fragment counts for each variant and turn them into a
170+
DataFrame.
171+
"""
172+
return allele_counts_dataframe(
173+
read_evidence_generator_from_args(args))
174+
175+
163176
def allele_reads_dataframe_from_args(args):
164177
"""
165178
Collect all allele reads for each variant and turn them into a DataFrame.

tests/test_allele_counts.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,26 @@ def test_allele_count_dataframe():
2525
trimmed_alt="G",
2626
ref_reads=[
2727
AlleleRead(prefix="AAA", allele="C", suffix="TTT", name="C1"),
28-
AlleleRead(prefix="AAC", allele="C", suffix="TTA", name="C2"),
28+
AlleleRead(prefix="AAC", allele="C", suffix="TTA", name="C1"),
2929
],
3030
alt_reads=[
31-
AlleleRead(prefix="AAA", allele="G", suffix="TTT", name="G1")
31+
AlleleRead(prefix="AAA", allele="G", suffix="TTT", name="G1"),
32+
AlleleRead(prefix="AAT", allele="G", suffix="TTC", name="G1"),
3233
],
33-
other_reads=[])
34+
other_reads=[
35+
AlleleRead(prefix="CCA", allele="T", suffix="GGA", name="T1"),
36+
AlleleRead(prefix="CCG", allele="T", suffix="GGT", name="T2"),
37+
AlleleRead(prefix="CCT", allele="T", suffix="GGC", name="T2"),
38+
])
3439
df = allele_counts_dataframe([(variant, read_evidence)])
3540
assert len(df) == 1, "Wrong number of rows in DataFrame: %s" % (df,)
3641
row = df.iloc[0]
3742
eq_(row.num_ref_reads, 2)
38-
eq_(row.num_alt_reads, 1)
39-
eq_(row.num_other_reads, 0)
43+
eq_(row.num_alt_reads, 2)
44+
eq_(row.num_other_reads, 3)
45+
eq_(row.num_ref_fragments, 1)
46+
eq_(row.num_alt_fragments, 1)
47+
eq_(row.num_other_fragments, 2)
4048

4149

4250
if __name__ == "__main__":

tests/test_cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from isovar.cli.isovar_variant_sequences import run as isovar_variant_sequences
2727
from isovar.cli.isovar_main import run as isovar_main
2828
from isovar.cli.rna_args import (
29+
allele_counts_dataframe_from_args,
2930
make_rna_reads_arg_parser,
3031
variants_reads_dataframe_from_args,
3132
)
@@ -60,7 +61,16 @@ def run_cli_fn(fn, include_bam_in_args=True, return_dataframe=False):
6061

6162

6263
def test_cli_allele_counts():
63-
run_cli_fn(isovar_allele_counts)
64+
df = run_cli_fn(isovar_allele_counts, return_dataframe=True)
65+
args = make_rna_reads_arg_parser().parse_args(args_with_bam)
66+
expected_df = allele_counts_dataframe_from_args(args)
67+
assert list(df.columns) == list(expected_df.columns)
68+
assert "ref_reads" not in df.columns
69+
assert len(df) == 4
70+
assert df[["num_ref_reads", "num_alt_reads", "num_other_reads"]].to_dict(orient="records") == \
71+
expected_df[["num_ref_reads", "num_alt_reads", "num_other_reads"]].to_dict(orient="records")
72+
assert df[["num_ref_fragments", "num_alt_fragments", "num_other_fragments"]].to_dict(orient="records") == \
73+
expected_df[["num_ref_fragments", "num_alt_fragments", "num_other_fragments"]].to_dict(orient="records")
6474

6575

6676
def test_cli_allele_reads():

0 commit comments

Comments
 (0)