Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 12, 2024
1 parent ae8c77e commit c10c9d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
20 changes: 14 additions & 6 deletions geneplexus/_geneplexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ def _initial_id_convert(input_genes, file_loc, species):
converted_gene_name = ", ".join(all_to_name)
logger.debug(f"Found mapping ({anIDtype}) {agene} -> {all_convert_dict[anIDtype][agene]}")
break
convert_out.append([agene, converted_gene or "Could Not be mapped to Entrez" ,converted_gene_name or "Could Not be mapped to Entrez"])
convert_out.append(
[
agene,
converted_gene or "Could Not be mapped to Entrez",
converted_gene_name or "Could Not be mapped to Entrez",
]
)

column_names = ["Original ID", "Entrez ID", "Gene Name"]
df_convert_out = pd.DataFrame(convert_out, columns=column_names).astype(str)
Expand Down Expand Up @@ -100,7 +106,7 @@ def _get_genes_in_network(file_loc, species, net_type, convert_ids):
return pos_genes_in_net, genes_not_in_net, net_genes


def _get_negatives(file_loc, species, net_type, gsc, pos_genes_in_net,user_negatives):
def _get_negatives(file_loc, species, net_type, gsc, pos_genes_in_net, user_negatives):
gsc_full = util.load_gsc(file_loc, species, gsc, net_type)
uni_genes = np.array(gsc_full["Universe"])
gsc_terms = gsc_full["Term_Order"]
Expand All @@ -118,9 +124,11 @@ def _get_negatives(file_loc, species, net_type, gsc, pos_genes_in_net,user_negat
pval = hypergeom.sf(k - 1, M, n, N)
if pval < 0.05:
genes_to_remove = np.union1d(genes_to_remove, n_set)
neutral_gene_info[akey] = {"Name": gsc_full[akey]["Name"],
"Task": gsc_full[akey]["Task"],
"Genes": n_set}
neutral_gene_info[akey] = {
"Name": gsc_full[akey]["Name"],
"Task": gsc_full[akey]["Task"],
"Genes": n_set,
}
neutral_gene_info["All Neutrals"] = np.setdiff1d(genes_to_remove, pos_genes_in_net).tolist()
negative_genes = np.setdiff1d(uni_genes, genes_to_remove)
return negative_genes, neutral_gene_info
Expand Down Expand Up @@ -230,7 +238,7 @@ def _make_prob_df(file_loc, sp_trn, sp_tst, net_type, probs, pos_genes_in_net, n

def _make_sim_dfs(file_loc, mdl_weights, species, gsc, net_type, features):
# make task conversion
task_convert = {"Mondo":"Disease", "Monarch":"Phenotype", "GO":"Biological Process"}
task_convert = {"Mondo": "Disease", "Monarch": "Phenotype", "GO": "Biological Process"}
weights_dict = util.load_pretrained_weights(file_loc, species, gsc, net_type, features)
gsc_full = util.load_gsc(file_loc, species, gsc, net_type)
gsc_terms = gsc_full["Term_Order"]
Expand Down
18 changes: 9 additions & 9 deletions geneplexus/geneplexus.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""GenePlexus API."""
import os
import os.path as osp
import numpy as np
import warnings
from typing import Any
from typing import Dict
from typing import List
from typing import Optional

import numpy as np
import pystow
import yaml

Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(
input_genes: Input gene list, can be mixed type. Can also be set
later if not specified at init time by simply calling
:meth:`load_genes` (default: :obj:`None`).
input_negatives: Input list of negative genes, can be mixed type.
input_negatives: Input list of negative genes, can be mixed type.
Can also be set later if not specified at init time by simply calling
:meth:`load_negatives` (default: :obj:`None`).
auto_download: Automatically download necessary files if set.
Expand Down Expand Up @@ -96,7 +96,7 @@ def __init__(

if input_genes is not None:
self.load_genes(input_genes)

if input_negatives is not None:
self.load_genes(load_negatives)

Expand Down Expand Up @@ -130,7 +130,7 @@ def _params(self) -> List[str]:
"auto_download",
"log_level",
"input_genes",
"input_negatives"
"input_negatives",
]

def dump_config(self, outdir: str):
Expand Down Expand Up @@ -254,7 +254,7 @@ def load_genes(self, input_genes: List[str]):
self.table_summary = load_genes_outputs[1]
self.selfinput_count = load_genes_outputs[2]
self.convert_ids = load_genes_outputs[3]

def load_negatives(self, input_negatives: List[str]):
"""Load gene list and convert to Entrez that will used as negatives.
Expand Down Expand Up @@ -409,8 +409,8 @@ def _get_pos_and_neg_genes(self):
self.convert_ids,
)
if len(self.input_negatives) > 0:
# remove genes from negatives if they are also positives
user_negatives = np.setdiff1d(self.convert_ids_negatives,self.convert_ids).tolist()
# remove genes from negatives if they are also positives
user_negatives = np.setdiff1d(self.convert_ids_negatives, self.convert_ids).tolist()
print(user_negatives)
else:
user_negatives = None
Expand All @@ -420,9 +420,9 @@ def _get_pos_and_neg_genes(self):
self.net_type,
self.gsc_trn,
self.pos_genes_in_net,
user_negatives
user_negatives,
)

return self.pos_genes_in_net, self.negative_genes, self.net_genes, self.neutral_gene_info

def make_sim_dfs(self):
Expand Down
3 changes: 2 additions & 1 deletion geneplexus/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ def load_gsc(
"""
file_name = f"GSC__{species}__{gsc}__{net_type}.json"
return _load_json_file(file_loc, file_name)



def load_biomart(
file_loc: str,
sp_trn: config.SPECIES_TYPE,
Expand Down

0 comments on commit c10c9d0

Please sign in to comment.