Skip to content

Commit

Permalink
date for biocurator
Browse files Browse the repository at this point in the history
  • Loading branch information
pnrobinson committed Apr 29, 2024
1 parent a459f0b commit e78ef38
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/pyphetools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from . import visualization
from . import validation

__version__ = "0.9.81"
__version__ = "0.9.82"

__all__ = [
"creation",
Expand Down
2 changes: 1 addition & 1 deletion src/pyphetools/creation/import_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def create_hpoa_from_phenopackets(self,
if target is not None:
ppkt_list = TemplateImporter.filter_diseases(target, ppkt_list)
TemplateImporter.check_disease_entries(ppkt_list)
builder = HpoaTableBuilder(phenopacket_list=ppkt_list)
builder = HpoaTableBuilder(phenopacket_list=ppkt_list, created_by=self._created_by)
if moi == "Autosomal dominant":
builder.autosomal_dominant(pmid)
elif moi == "Autosomal recessive":
Expand Down
19 changes: 16 additions & 3 deletions src/pyphetools/visualization/hpoa_table_creator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import json
from typing import List, Dict
from datetime import datetime as d


from google.protobuf.json_format import Parse

Expand Down Expand Up @@ -119,6 +121,9 @@ def __init__(self, phenopacket_list, onset_term_d, moi_d, created_by:str=None)
:type: Dict[str, OnsetTerm]
:param moi_d: Dictionary with key PMID and value Mode of inheritance
"""
date = d.now()
todays_date = date.strftime("%Y-%m-%d")
self._todays_date = f"[{todays_date}]"
self._phenopackets = phenopacket_list
self._created_by = created_by
self._all_hpo_d = self._get_all_hpos()
Expand All @@ -128,6 +133,7 @@ def __init__(self, phenopacket_list, onset_term_d, moi_d, created_by:str=None)
self._onset_rows = self._add_age_of_onset_terms(onset_term_d)
self._moi_rows = self._add_moi_rows(moi_d)



def _get_all_hpos(self) -> Dict[str,HpTerm]:
"""Get a dictionary of HpTerms, with key being HPO id and the value the corresponding HpTerm
Expand Down Expand Up @@ -211,6 +217,10 @@ def _count_hpos(self):
if pf.excluded is not None and not pf.excluded:
hpo_counter.increment_observed(hpterm.id)
return hpo_counter_d

def _format_biocurator(self, bcurator):
return f"{bcurator}{self._todays_date}"


def _add_age_of_onset_terms(self, onset_term_d) -> List[HpoaTableRow]:
"""
Expand All @@ -219,7 +229,7 @@ def _add_age_of_onset_terms(self, onset_term_d) -> List[HpoaTableRow]:
"""
onset_rows = list() # reset
for pmid, oterm_list in onset_term_d.items():
biocurator = self._biocurator_d.get(pmid)
biocurator = self._format_biocurator(self._biocurator_d.get(pmid))
for oterm in oterm_list:
hpo_onset_term = HpTerm(hpo_id=oterm.id, label=oterm.label)
row = HpoaTableRow(disease=self._disease, hpo_term=hpo_onset_term, publication=pmid, biocurator=biocurator, freq_num=oterm.numerator, freq_denom=oterm.denominator)
Expand All @@ -239,7 +249,9 @@ def _add_moi_rows(self, moi_d) -> List[HpoaTableRow]:
# If we add an MOI outside of the template, then it will not have a PMID
# the template builder requires a created_by field which is designed for this.
if biocurator is None:
biocurator = self._created_by
biocurator = biocurator = self._format_biocurator(self._created_by)
else:
biocurator = self._format_biocurator(biocurator)
for hpterm in hpterm_list:
row = HpoaTableRow(disease=self._disease, hpo_term=hpterm, publication=pmid, biocurator=biocurator)
moi_rows.append(row)
Expand All @@ -253,6 +265,7 @@ def get_dataframe(self):
"description", "publication","evidence", "biocuration"]
for pmid, counter in self._hpo_counter_d.items():
biocurator = self._biocurator_d.get(pmid)
biocurator = self._format_biocurator(biocurator)
measured_d = counter.get_measured_d()
observed_d = counter.get_observed_d()
# by construction, there can be no term in observed_d that is not in measured_d
Expand Down Expand Up @@ -282,7 +295,7 @@ def write_data_frame(self):

class HpoaTableBuilder:

def __init__(self, indir=None, phenopacket_list=None, created_by:str=None) -> None:
def __init__(self, created_by:str, indir=None, phenopacket_list=None) -> None:
if indir is not None:
if not os.path.isdir(indir):
raise ValueError(f"indir argument {indir} must be directory!")
Expand Down

0 comments on commit e78ef38

Please sign in to comment.