Skip to content

Commit

Permalink
Update code to address NaN/numerator/denominator
Browse files Browse the repository at this point in the history
References #4
  • Loading branch information
u8sand committed Apr 21, 2022
1 parent bfcdc06 commit 8e07c66
Showing 1 changed file with 48 additions and 36 deletions.
84 changes: 48 additions & 36 deletions c2m2_assessment/rubrics/FAIR_2022_q4.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'biosample' in CFDE.tables and 'biosample_substance' in CFDE.tables:
total_associated = CFDE.tables['biosample'] \
.link(CFDE.tables['biosample_substance'],
on=(CFDE.tables['biosample_substance'].biosample_local_id == CFDE.tables['biosample'].local_id)
& (CFDE.tables['biosample_substance'].biosample_id_namespace == CFDE.tables['biosample'].id_namespace)
).groupby(CFDE.tables['biosample'].id_namespace, CFDE.tables['biosample'].local_id).count()
total = total_biosamples(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}

@rubric.metric({
Expand All @@ -46,18 +47,19 @@ def _(CFDE, full=False, **kwargs):
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'collection' in CFDE.tables and 'collection_gene' in CFDE.tables:
total_associated = CFDE.tables['collection'] \
.link(CFDE.tables['collection_gene'],
on=(CFDE.tables['collection_gene'].collection_local_id == CFDE.tables['collection'].local_id)
& (CFDE.tables['collection_gene'].collection_id_namespace == CFDE.tables['collection'].id_namespace)
).groupby(CFDE.tables['collection'].id_namespace, CFDE.tables['collection'].local_id).count()
total = total_collections(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}

@rubric.metric({
Expand All @@ -67,18 +69,19 @@ def _(CFDE, full=False, **kwargs):
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'collection' in CFDE.tables and 'collection_substance' in CFDE.tables:
total_associated = CFDE.tables['collection'] \
.link(CFDE.tables['collection_substance'],
on=(CFDE.tables['collection_substance'].collection_local_id == CFDE.tables['collection'].local_id)
& (CFDE.tables['collection_substance'].collection_id_namespace == CFDE.tables['collection'].id_namespace)
).groupby(CFDE.tables['collection'].id_namespace, CFDE.tables['collection'].local_id).count()
total = total_collections(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}

@rubric.metric({
Expand All @@ -88,18 +91,19 @@ def _(CFDE, full=False, **kwargs):
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'subject' in CFDE.tables and 'subject_substance' in CFDE.tables:
total_associated = CFDE.tables['subject_substance'] \
.link(CFDE.tables['subject'],
on=(CFDE.tables['subject_substance'].subject_local_id == CFDE.tables['subject'].local_id)
& (CFDE.tables['subject_substance'].subject_id_namespace == CFDE.tables['subject'].id_namespace)
).groupby(CFDE.tables['subject'].id_namespace, CFDE.tables['subject'].local_id).count()
total = total_subjects(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}

@rubric.metric({
Expand All @@ -109,18 +113,19 @@ def _(CFDE, full=False, **kwargs):
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'biosample' in CFDE.tables and 'biosample_gene' in CFDE.tables:
total_associated = CFDE.tables['biosample'] \
.link(CFDE.tables['biosample_gene'],
on=(CFDE.tables['biosample_gene'].biosample_local_id == CFDE.tables['biosample'].local_id)
& (CFDE.tables['biosample_gene'].biosample_id_namespace == CFDE.tables['biosample'].id_namespace)
).groupby(CFDE.tables['biosample'].id_namespace, CFDE.tables['biosample'].local_id).count()
total = total_biosamples(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}

@rubric.metric({
Expand All @@ -130,17 +135,18 @@ def _(CFDE, full=False, **kwargs):
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'phenotype' in CFDE.tables and 'phenotype_gene' in CFDE.tables:
total_associated = CFDE.tables['phenotype_gene'] \
.link(CFDE.tables['phenotype'], on=(
CFDE.tables['phenotype'].id == CFDE.tables['phenotype_gene'].phenotype
)).groupby(CFDE.tables['phenotype'].id).count()
total = total_phenotypes(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}

@rubric.metric({
Expand All @@ -150,17 +156,18 @@ def _(CFDE, full=False, **kwargs):
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'protein' in CFDE.tables and 'protein_gene' in CFDE.tables:
total_associated = CFDE.tables['protein_gene'] \
.link(CFDE.tables['protein'], on=(
CFDE.tables['protein'].id == CFDE.tables['protein_gene'].protein
)).groupby(CFDE.tables['protein'].id).count()
total = total_proteins(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}


Expand All @@ -171,18 +178,19 @@ def _(CFDE, full=False, **kwargs):
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'collection' in CFDE.tables and 'collection_protein' in CFDE.tables:
total_associated = CFDE.tables['collection'] \
.link(CFDE.tables['collection_protein'],
on=(CFDE.tables['collection_protein'].collection_local_id == CFDE.tables['collection'].local_id)
& (CFDE.tables['collection_protein'].collection_id_namespace == CFDE.tables['collection'].id_namespace)
).groupby(CFDE.tables['collection'].id_namespace, CFDE.tables['collection'].local_id).count()
total = total_collections(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}

@rubric.metric({
Expand All @@ -192,7 +200,7 @@ def _(CFDE, full=False, **kwargs):
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'subject' in CFDE.tables and 'subject_phenotype' in CFDE.tables:
total_associated = CFDE.tables['subject_phenotype'] \
.link(CFDE.tables['subject'], on=((
Expand All @@ -201,10 +209,11 @@ def _(CFDE, full=False, **kwargs):
CFDE.tables['subject'].id_namespace == CFDE.tables['subject_phenotype'].subject_id_namespace
))).groupby(CFDE.tables['subject'].id_namespace, CFDE.tables['subject'].local_id).count()
total = total_subjects(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}

@rubric.metric({
Expand All @@ -214,17 +223,18 @@ def _(CFDE, full=False, **kwargs):
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'gene' in CFDE.tables and 'phenotype_gene' in CFDE.tables:
total_associated = CFDE.tables['phenotype_gene'] \
.link(CFDE.tables['gene'], on=(
CFDE.tables['gene'].id == CFDE.tables['phenotype_gene'].gene
)).groupby(CFDE.tables['gene'].id).count()
total = total_genes(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}

@rubric.metric({
Expand All @@ -234,17 +244,18 @@ def _(CFDE, full=False, **kwargs):
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'disease' in CFDE.tables and 'phenotype_disease' in CFDE.tables:
total_associated = CFDE.tables['phenotype_disease'] \
.link(CFDE.tables['disease'], on=(
CFDE.tables['disease'].id == CFDE.tables['phenotype_disease'].disease
)).groupby(CFDE.tables['disease'].id).count()
total = total_diseases(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}

@rubric.metric({
Expand All @@ -254,16 +265,17 @@ def _(CFDE, full=False, **kwargs):
})
def _(CFDE, full=False, **kwargs):
total_associated = total = 0
value = float('nan')
value = None
if 'collection' in CFDE.tables and 'collection_phenotype' in CFDE.tables:
total_associated = CFDE.tables['collection'] \
.link(CFDE.tables['collection_phenotype'],
on=(CFDE.tables['collection_phenotype'].collection_local_id == CFDE.tables['collection'].local_id)
& (CFDE.tables['collection_phenotype'].collection_id_namespace == CFDE.tables['collection'].id_namespace)
).groupby(CFDE.tables['collection'].id_namespace, CFDE.tables['collection'].local_id).count()
total = total_collections(CFDE)
value = (total_associated / total) if total else float('nan')
value = (total_associated / total) if total else None
return {
'value': value,
'comment': f"{total_associated} / {total}",
'numerator': total_associated,
'denominator': total,
}

0 comments on commit 8e07c66

Please sign in to comment.