Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion ingest/anndata_.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,29 @@ def generate_cluster_body(adata, clustering_name):
Append clustering data to clustering file
"""
cluster_cells = pd.DataFrame(adata.obs_names)
raw_cluster_body = pd.DataFrame(adata.obsm[clustering_name])
cluster_body = pd.concat(
[cluster_cells, pd.DataFrame(adata.obsm[clustering_name])], axis=1
[cluster_cells, pd.DataFrame(
AnnDataIngestor.get_cluster_body_as_ndarray(raw_cluster_body)
)], axis=1
)
filename = AnnDataIngestor.set_clustering_filename(clustering_name)
pd.DataFrame(cluster_body).to_csv(
filename, sep="\t", mode="a", header=None, index=False
)
AnnDataIngestor.compress_file(filename)

@staticmethod
def get_cluster_body_as_ndarray(raw_body):
"""
Get the cluster body as a numpy array
will convert on the fly as necessary
"""
if raw_body.__class__.__name__ == "DataFrame":
return raw_body.to_numpy()
else:
return raw_body

@staticmethod
def set_clustering_filename(name):
return f"h5ad_frag.cluster.{name}.tsv"
Expand Down
Binary file modified ingest/validation/ontologies/cl.min.tsv.gz
Binary file not shown.
Binary file modified ingest/validation/ontologies/efo.min.tsv.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion ingest/validation/ontologies/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1772637743 # validation cache key
1774285924 # validation cache key
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pytest==7.2.1
coverage==7.12.0
pytest-xdist==1.29.0
pre-commit==1.18.1
black==24.3.0
black==26.3.1
flake8==3.7.8
pytest-cov==2.8.1
diffxpy==0.7.4
Expand Down
17 changes: 17 additions & 0 deletions tests/test_anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import os
import gzip
import time
import pandas as pd
from numpy.testing import assert_array_equal
from unittest.mock import MagicMock, patch

from test_expression_files import mock_expression_load
Expand Down Expand Up @@ -145,6 +147,21 @@ def test_generate_cluster_body(self):
'did not get expected coordinates from cluster body',
)

def test_get_cluster_body_as_ndarray(self):
test_df = pd.DataFrame({
'X': [1, 2, 3],
'Y': [4, 5, 6],
})
cluster_body = self.anndata_ingest.get_cluster_body_as_ndarray(test_df)
expected_body = [[1, 4],[2, 5],[3, 6]]
assert_array_equal(expected_body, cluster_body)
# normal test
# long precision is because we're looking at raw numpy array
raw_body = self.anndata_ingest.obtain_adata().obsm[self.cluster_name]
cluster_body = self.anndata_ingest.get_cluster_body_as_ndarray(raw_body)
assert_array_equal([16.00995445251465, -21.07384490966797], cluster_body[0].tolist())


def test_generate_metadata_file(self):
self.anndata_ingest.generate_metadata_file(
self.anndata_ingest.obtain_adata(), self.metadata_filename
Expand Down
Loading