Skip to content

Commit

Permalink
Update export
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Mar 15, 2019
1 parent 94525b5 commit 7ae0b8b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 52 deletions.
8 changes: 2 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,12 @@ docs =
[options.entry_points]
console_scripts =
bio2bel_adeptus = bio2bel_adeptus.cli:main
bio2bel =
adeptus = bio2bel_adeptus

[options.packages.find]
where = src

#######################
# Wheel Configuration #
#######################
[bdist_wheel]
python-tag = py36

##########################
# Coverage Configuration #
# (.coveragerc) #
Expand Down
121 changes: 75 additions & 46 deletions src/bio2bel_adeptus/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,108 @@

from tqdm import tqdm

import pybel.dsl
from bio2bel.manager.bel_manager import BELManagerMixin
from pybel import BELGraph
from pybel.constants import NEGATIVE_CORRELATION, POSITIVE_CORRELATION
from pybel.dsl import Pathology, Rna
from .constants import MODULE_NAME
from .models import Base
from .parser import get_adeptus_df


class Manager(BELManagerMixin):
"""Manages the Bio2BEL ADEPTUS database."""
"""Disease-specific differential gene expression."""

module_name = MODULE_NAME
_base = Base

def __init__(self, *args, **kwargs): # noqa: D107
pass
self.graph = get_graph()

@classmethod
def _get_connection(cls):
return ''
pass

def is_populated(self) -> bool:
@staticmethod
def is_populated() -> bool:
"""Check if the Bio2BEL ADEPTUS database is populated."""
raise NotImplementedError
return True

def summarize(self) -> Mapping[str, int]:
"""Summarize the contents of the Bio2BEL ADEPTUS database."""
raise NotImplementedError
return dict(
correlations=self.count_relations(),
diseases=self.count_diseases(),
rnas=self.count_rnas(),
)

def populate(self) -> None:
"""Populate the Bio2BEL ADEPTUS database."""
raise NotImplementedError

def count_diseases(self) -> int:
"""Count the number of diseases."""
return sum(
isinstance(node, Pathology)
for node in self.graph
)

def count_rnas(self) -> int:
"""Count the number of RNAs."""
return sum(
isinstance(node, Rna)
for node in self.graph
)

def count_relations(self) -> int:
"""Count the number of disease-differential expressed gene relations."""
return self.graph.number_of_edges()

def to_bel(self) -> BELGraph:
"""Output ADEPTUS as a BEL graph."""
graph = BELGraph(
name='ADEPTUS',
version='0.0.0',
description="""ADEPTUS conversion to BEL using Daniel Himmelstein's data at https://raw.githubusercontent.com/dhimmel/adeptus/master/data/gene-sets.tsv"""
return self.graph


def get_graph(use_tqdm: bool = False) -> BELGraph:
graph = BELGraph(
name='ADEPTUS',
version='0.0.0',
description="""ADEPTUS conversion to BEL using Daniel Himmelstein's data at https://raw.githubusercontent.com/dhimmel/adeptus/master/data/gene-sets.tsv"""
)
graph.annotation_pattern['Database'] = '.*'
graph.annotation_pattern['ADEPTUS_PB_ROC'] = '.*'
graph.annotation_pattern['ADEPTUS_PN_ROC'] = '.*'

df = get_adeptus_df()

it = df.iterrows()
if use_tqdm:
it = tqdm(it, desc='ADEPTUS to BEL', total=len(df.index))
for _, (disease_doid, disease_name, entrez_id, entrez_name, pb_roc, pn_roc, direction) in it:
disease = Pathology(
namespace='doid',
name=disease_name,
identifier=disease_doid,
)
gene = Rna(
namespace='ncbigene',
name=entrez_name,
identifier=entrez_id,
)
graph.annotation_pattern['Database'] = '.*'
graph.annotation_pattern['ADEPTUS_PB_ROC'] = '.*'
graph.annotation_pattern['ADEPTUS_PN_ROC'] = '.*'

df = get_adeptus_df()

it = tqdm(df.iterrows(), desc='ADEPTUS to BEL', total=len(df.index))
for _, (disease_doid, disease_name, entrez_id, entrez_name, pb_roc, pn_roc, direction) in it:
disease = pybel.dsl.Pathology(
namespace='doid',
name=disease_name,
identifier=disease_doid,
)
gene = pybel.dsl.Gene(
namespace='ncbigene',
name=entrez_name,
identifier=entrez_id,
)

relation = POSITIVE_CORRELATION if direction == 'up' else NEGATIVE_CORRELATION

graph.add_qualified_edge(
disease,
gene,
relation=relation,
citation='26261215',
evidence='ADEPTUS database',
annotations={
'Database': 'ADEPTUS',
'ADEPTUS_PB_ROC': pb_roc,
'ADEPTUS_PN_ROC': pn_roc,
}
)

return graph

relation = POSITIVE_CORRELATION if direction == 'up' else NEGATIVE_CORRELATION

graph.add_qualified_edge(
disease,
gene,
relation=relation,
citation='26261215',
evidence='ADEPTUS database',
annotations={
'bio2bel': 'adeptus',
'ADEPTUS_PB_ROC': pb_roc,
'ADEPTUS_PN_ROC': pn_roc,
}
)

return graph

0 comments on commit 7ae0b8b

Please sign in to comment.