Skip to content

Commit

Permalink
Metadata percentage nodes patch for NaN values (#78)
Browse files Browse the repository at this point in the history
* Updated anndata version to 0.10.5

* Updated version to 0.1.21

* Add skip mechanism to add_metadata_nodes for NaN values

* Use UUID URIRef for terms without a valid ontology ID
  • Loading branch information
ubyndr authored Jul 12, 2024
1 parent f7db1d3 commit 144e986
Show file tree
Hide file tree
Showing 3 changed files with 397 additions and 362 deletions.
28 changes: 16 additions & 12 deletions pandasaurus_cxg/graph_generator/graph_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ def add_metadata_nodes(self, metadata_fields: List[str]):
percentage_annotation_property = self.ns["percentage"]
self.graph.add((percentage_annotation_property, RDF.type, OWL.AnnotationProperty))
for metadata in metadata_fields:
# Extract the ontology term ID mapping
ontology_term_id_mapping = (
obs[[metadata, f"{metadata}_ontology_term_id"]]
.drop_duplicates()
.set_index(metadata)
.to_dict()[f"{metadata}_ontology_term_id"]
)

for s, _, _ in self.graph.triples((None, RDF.type, URIRef(CLUSTER.get("iri")))):
for a_cell_type in author_cell_types:
literal = self.graph.value(subject=s, predicate=self.ns[a_cell_type])
Expand All @@ -247,19 +255,15 @@ def add_metadata_nodes(self, metadata_fields: List[str]):
* 100
).loc[lambda x: x != 0.0]

# Extract the ontology term ID mapping
ontology_term_id_mapping = (
obs[[metadata, f"{metadata}_ontology_term_id"]]
.drop_duplicates()
.set_index(metadata)
.to_dict()[f"{metadata}_ontology_term_id"]
)

for label, percentage in percentages.items():
ontology_term_id = ontology_term_id_mapping.get(label).split(":")
annotated_target = Namespace(prefixes.get(ontology_term_id[0]))[
ontology_term_id[-1]
]
ontology_term_id = ontology_term_id_mapping.get(label)
if isinstance(ontology_term_id, str) and ":" in ontology_term_id:
ontology_term_id = ontology_term_id_mapping.get(label).split(":")
annotated_target = Namespace(prefixes.get(ontology_term_id[0]))[
ontology_term_id[-1]
]
else:
annotated_target = URIRef(self.ns[str(uuid.uuid4())])
self.graph.add((annotated_target, RDFS.label, Literal(label)))
bnode_axiom = BNode()
self.graph.add((bnode_axiom, RDF.type, OWL.Axiom))
Expand Down
Loading

0 comments on commit 144e986

Please sign in to comment.