Skip to content

Commit

Permalink
Allow missing columns in IrObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
grst committed Mar 17, 2021
1 parent f484cdf commit f9043fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion scirpy/io/_convert_anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,12 @@ def to_ir_objs(adata: AnnData) -> List[IrCell]:
for cell_id, row in adata.obs.iterrows():
tmp_ir_cell = IrCell(cell_id, multi_chain=row["multi_chain"])
for chain_type, chain_id in itertools.product(["VJ", "VDJ"], ["1", "2"]):
# expr_raw is optional
keys = IR_OBS_KEYS[:]
if f"IR_{chain_type}_{chain_id}_expr_raw" not in row:
keys.remove("expr_raw")
chain_dict = {
key: row[f"IR_{chain_type}_{chain_id}_{key}"] for key in IR_OBS_KEYS
key: row[f"IR_{chain_type}_{chain_id}_{key}"] for key in keys
}
# per definition, we currently only have productive chains in adata.
chain_dict["is_productive"] = True
Expand Down
5 changes: 4 additions & 1 deletion scirpy/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
TESTDATA / "10x/filtered_contig_annotations.csv",
],
)
def test_read_and_convert_10x_example(path):
@pytest.mark.parametrize("omit_cols", [True, False])
def test_read_and_convert_10x_example(path, omit_cols):
"""Test that a full 10x CSV table can be imported without errors.
Additionally test that the round-trip conversion using `to_ir_objs` and
Expand All @@ -34,6 +35,8 @@ def test_read_and_convert_10x_example(path):
under CC-BY-4.0
"""
anndata = read_10x_vdj(path)
if omit_cols:
del adata.obs["IR_VJ_1_expr_raw"]
assert anndata.shape[0] > 0

# Test that round-trip conversion succeeds
Expand Down

0 comments on commit f9043fb

Please sign in to comment.