Skip to content

Commit

Permalink
OmicsIntegrator 2.2 (2/4) -- full annotations (#85)
Browse files Browse the repository at this point in the history
* mv subcellular -> annotation

* Molecular function first pass done

* second pass at molecular function.

* Biological Process probably done.

* sketch out compartments notebook

* Create final annotation file

* just a few renames

* Fix stuff, run tests, run example_usage notebook
  • Loading branch information
alexlenail committed Jun 17, 2018
1 parent 4c63a84 commit 1100a83
Show file tree
Hide file tree
Showing 17 changed files with 11,203 additions and 1,934 deletions.
3,628 changes: 3,628 additions & 0 deletions annotation/biological_process.ipynb

Large diffs are not rendered by default.

Binary file not shown.
3,530 changes: 3,530 additions & 0 deletions annotation/cellular_compartment.ipynb

Large diffs are not rendered by default.

472 changes: 472 additions & 0 deletions annotation/final_annotation.ipynb

Large diffs are not rendered by default.

Binary file added annotation/final_annotation.pickle
Binary file not shown.
File renamed without changes.
3,474 changes: 3,474 additions & 0 deletions annotation/molecular_function.ipynb

Large diffs are not rendered by default.

Binary file not shown.
File renamed without changes.
File renamed without changes.
98 changes: 68 additions & 30 deletions example/Example_Usage.ipynb

Large diffs are not rendered by default.

29 changes: 18 additions & 11 deletions src/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,12 @@ def _reset_hyperparameters(self, params={}):
params (dict): params with which to run the program
"""

defaults = {"w": 5, "b": 1, "g": 3, "edge_noise": 0.1, "dummy_mode": "terminals", "seed": None, "skip_checks": False}
defaults = {"w": 5, "b": 1, "g": 3, "edge_noise": 0.1, "dummy_mode": "terminals", "seed": 0, "skip_checks": False}

# Overwrite the defaults with any user-specified parameters.
self.params = Options({**defaults, **params})

if not (isinstance(self.params.w, numbers.Number) && (self.params.w >= 0)): raise ValueError("parameter w must be a positive number. Was "+str(self.params.w))
if not (isinstance(self.params.b, numbers.Number) && (self.params.b >= 0)): raise ValueError("parameter b must be a positive number. Was "+str(self.params.b))
if not (isinstance(self.params.g, numbers.Number) && (self.params.g >= 0)): raise ValueError("parameter g must be a positive number. Was "+str(self.params.g))
if not (isinstance(self.params.edge_noise, numbers.Number) && (self.params.edge_noise >= 0)): raise ValueError("parameter edge_noise must be a positive number. Was "+str(self.params.edge_noise))
if not (self.params.dummy_mode in ['terminals', 'other', 'all']): raise ValueError("parameter dummy_mode must be one of 'terminals', 'other', or 'all'. Was "+str(self.params.dummy_mode))
if not (isinstance(self.params.seed, int)): raise ValueError("parameter seed must be a int. Was type "+str(type(self.params.seed)))
if not (isinstance(self.params.skip_checks, bool)): raise ValueError("parameter skip_checks must be a bool. Was type "+str(type(self.params.skip_checks)))
if not self.params.skip_checks: self._check_validity_of_hyperparameters()

# Add costs to each edge, proportional to the degrees of the nodes it connects, modulated by parameter g.
N = len(self.nodes)
Expand All @@ -140,6 +134,19 @@ def _reset_hyperparameters(self, params={}):
if hasattr(self, "bare_prizes"): self.prizes = self.bare_prizes * self.params.b


def _check_validity_of_hyperparameters(self):
"""
Assert that the hyperparameters passed to this program are valid, otherwise raise helpful error messages.
"""

if not (isinstance(self.params.w, numbers.Number) and (self.params.w >= 0)): raise ValueError("parameter w must be a positive number. Was "+str(self.params.w))
if not (isinstance(self.params.b, numbers.Number) and (self.params.b >= 0)): raise ValueError("parameter b must be a positive number. Was "+str(self.params.b))
if not (isinstance(self.params.g, numbers.Number) and (self.params.g >= 0)): raise ValueError("parameter g must be a positive number. Was "+str(self.params.g))
if not (isinstance(self.params.edge_noise, numbers.Number) and (self.params.edge_noise >= 0)): raise ValueError("parameter edge_noise must be a positive number. Was "+str(self.params.edge_noise))
if not (self.params.dummy_mode in ['terminals', 'other', 'all']): raise ValueError("parameter dummy_mode must be one of 'terminals', 'other', or 'all'. Was "+str(self.params.dummy_mode))
if not (isinstance(self.params.seed, int)): raise ValueError("parameter seed must be a int. Was type "+str(type(self.params.seed)))


def prepare_prizes(self, prize_file):
"""
Parses a prize file and adds prizes and other attributes to the graph object.
Expand Down Expand Up @@ -214,7 +221,7 @@ def _add_dummy_node(self, connected_to=[]):

def _check_validity_of_instance(self, edges, prizes, costs, root, num_clusters, pruning, verbosity_level):
"""
Assert that the parammeters and files passed to this program are valid, log useful error messages otherwise.
Assert that the data passed to this program are valid, otherwise raise helpful error messages.
"""

if not (isinstance(edges, np.ndarray)): raise ValueError("edges must be a numpy array, type was: "+str(type(edges)))
Expand Down Expand Up @@ -639,9 +646,9 @@ def annotate_graph_nodes(nxgraph):
"""

try:
annotation = pd.read_pickle(get_path('OmicsIntegrator', 'subcellular_compartments/subcellular.pickle'))
annotation = pd.read_pickle(get_path('OmicsIntegrator', 'annotation/final_annotation.pickle'))
except:
annotation = pd.read_pickle(Path.cwd().parent / 'subcellular' / 'subcellular.pickle')
annotation = pd.read_pickle(Path.cwd().parent / 'annotation' / 'final_annotation.pickle')

nx.set_node_attributes(nxgraph, annotation.reindex(list(nxgraph.nodes())).dropna(how='all').to_dict(orient='index'))

Expand Down
2 changes: 1 addition & 1 deletion src/gslr_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def gslr_macro(graph, dataset, sparsity_low=100, sparsity_high=200, num_steps=25
# Post-processing
betweenness(network)
louvain_clustering(network)
augment_with_subcellular_localization(network)
annotate_graph_nodes(network)

class_networks.append(network)

Expand Down
Loading

0 comments on commit 1100a83

Please sign in to comment.