Skip to content

Commit

Permalink
Merge pull request #70 from klarman-cell-observatory/yiming
Browse files Browse the repository at this point in the history
Add unit test for data aggregation
  • Loading branch information
yihming committed Jul 16, 2021
2 parents f6a178e + 2b52d15 commit e4faf84
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ jobs:
- name: IO test
run: |
pytest tests/test_io.py
- name: Data aggregation test
run: |
bash tests/run_aggregate_matrix.sh
pytest tests/test_aggr.py
5 changes: 3 additions & 2 deletions pegasusio/data_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def aggregate_matrices(
if "Object" in row:
data = row["Object"].copy()
else:
assert "Location" in row
assert "Location" in row, f"Row of sample '{row['Sample']}' must contain a 'Location' column!"
assert not row.isnull().values.any(), f"Row of sample '{row['Sample']}' has one or more NaN/NA values!"

input_file = os.path.expanduser(os.path.expandvars(row["Location"].rstrip(os.sep))) # extend all user variables
file_type, copy_path, copy_type = infer_file_type(input_file) # infer file type
Expand Down Expand Up @@ -198,7 +199,7 @@ def aggregate_matrices(
genome = def_genome
modality = row.get("Modality", None)
data = read_input(input_file, file_type = file_type, genome = genome, modality = modality)

if len(genome_dict) > 0:
data._update_genome(genome_dict)

Expand Down
1 change: 1 addition & 0 deletions tests/run_aggregate_matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pegasusio aggregate_matrix pegasusio-test-data/aggr_case/count_matrix.csv pegasusio-test-data/aggr_result --attributes Donor --min-genes 100 --mito-prefix MT- --percent-mito 10
18 changes: 18 additions & 0 deletions tests/test_aggr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest

import pegasusio as io

class TestAggr(unittest.TestCase):

def test_aggregate_matrices(self):
data = io.read_input("pegasusio-test-data/aggr_result.zarr.zip")

self.assertEqual(data.shape, (16303, 36601), "Count matrix shape differs!")
self.assertTrue('Donor' in data.obs, "Attribute 'Donor' is not included in the resulting count matrix!")
self.assertEqual(data.obs['Channel'].cat.categories.size, 3, "Some sample is not included in the result count matrix!")
self.assertLessEqual(data.obs['percent_mito'].max(), 10, "Filtration based on '--percent-mito' fails!")
self.assertGreaterEqual(data.obs['n_genes'].min(), 100, "Filtration based on '--min-genes' fails!")


if __name__ == '__main__':
unittest.main()

0 comments on commit e4faf84

Please sign in to comment.