Skip to content

Commit

Permalink
log combined contexts and with Fly to GO
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherMancuso committed Nov 25, 2024
1 parent c557d39 commit eb6adb1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
10 changes: 10 additions & 0 deletions geneplexus/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
BIOMART_DATA_TYPE = Dict[str, str]
PRETRAINED_DATA_TYPE = Dict[str, Dict[Literal["Name", "Weights", "PosGenes"], Union[str, np.ndarray]]]

COMBINED_CONTEXTS: Dict[str, Any] = {
"Human": "Combined - Gene Set Contexts Used [GO, Monarch, Mondo]",
"Mouse": "Combined - Gene Set Contexts Used [GO, Monarch]",
"Zebrafish": "Combined - Gene Set Contexts Used [GO, Monarch]",
"Worm": "Combined - Gene Set Contexts Used [GO, Monarch]",
"Yeast": "Combined - Gene Set Contexts Used [GO, Monarch]",
"Fly": "Combined - Gene Set Contexts Used [GO]",
}

__all__ = [
"URL_DICT",
"CONFIG_PATH",
Expand All @@ -86,4 +95,5 @@
"ID_CONVERSION_MAP_TYPE",
"GSC_DATA_TYPE",
"PRETRAINED_DATA_TYPE",
"COMBINED_CONTEXTS",
]
46 changes: 38 additions & 8 deletions geneplexus/geneplexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def __init__(
self.net_type = net_type
self.log_level = log_level
self.auto_download = auto_download
self.input_genes: List[str] = []
self.input_negatives: List[str] = []
self.input_genes: List[str] = input_genes
self.input_negatives: List[str] = input_negatives

if self.auto_download and self._is_custom:
warnings.warn(
Expand Down Expand Up @@ -103,13 +103,31 @@ def __init__(

if (
(self.sp_trn == "Fly" and self.gsc_trn == "Monarch")
or (self.sp_trn == "Fly" and self.gsc_trn == "Combined")
or (self.sp_res == "Fly" and self.gsc_res == "Monarch")
or (self.sp_res == "Fly" and self.gsc_res == "Combined")
):
raise FlyMonarchError(
f"Fly has no annotations for Monarch. Use GO for GSC",
f"Fly has no annotations for Monarch. Use either Combined or GO for GSC",
)


if (self.gsc_trn == "Combined"):
logger.info(f"For the training species, {self.sp_trn}, the GSC is set to "
f"Combined and here: {config.COMBINED_CONTEXTS[self.sp_trn]}")
if (self.gsc_res == "Combined"):
logger.info(f"For the results species, {self.sp_res}, the GSC is set to "
f"Combined and here: {config.COMBINED_CONTEXTS[self.sp_res]}")

# convert combined to GO so can read correct backend data
if (self.sp_trn == "Fly") and (self.gsc_trn == "Combined"):
self.gsc_trn = "GO"
self.gsc_trn_original = "Combined"
elif (self.sp_trn == "Fly") and (self.gsc_trn != "Combined"):
self.gsc_trn_original = self.gsc_trn
if (self.sp_res == "Fly") and (self.gsc_res == "Combined"):
self.gsc_res = "GO"
self.gsc_res_original = "Combined"
elif (self.sp_res == "Fly") and (self.gsc_res != "Combined"):
self.gsc_res_original = self.gsc_res

@property
def _params(self) -> List[str]:
Expand All @@ -132,6 +150,14 @@ def dump_config(self, outdir: str):
used with CLI.
"""
params_dict = {i: getattr(self, i) for i in self._params}
if params_dict["gsc_trn"] == "Combined":
params_dict["gsc_trn"] = config.COMBINED_CONTEXTS[params_dict["sp_trn"]]
if params_dict["gsc_res"] == "Combined":
params_dict["gsc_res"] = config.COMBINED_CONTEXTS[params_dict["sp_res"]]
if hasattr(self, "gsc_trn_original") and (self.gsc_trn_original == "Combined"):
params_dict["gsc_trn"] = config.COMBINED_CONTEXTS[params_dict["sp_trn"]]
if hasattr(self, "gsc_res_original") and (self.gsc_res_original == "Combined"):
params_dict["gsc_res"] = config.COMBINED_CONTEXTS[params_dict["sp_res"]]
path = osp.join(outdir, "config.yaml")
with open(path, "w") as f:
yaml.dump(params_dict, f)
Expand Down Expand Up @@ -472,6 +498,10 @@ def fit_and_predict(
relevance of the gene to the input gene list.
"""
if self.input_genes == None:
raise NoPositivesError(
f"There are no positive genes to train the model with.",
)
self._get_pos_and_neg_genes()
self.mdl_weights, self.probs, self.avgps = _geneplexus._run_sl(
self.file_loc,
Expand Down Expand Up @@ -541,11 +571,11 @@ def _get_pos_and_neg_genes(self):
f"There are no positive genes to train the model with.",
)

if len(self.input_negatives) > 0:
if (self.input_negatives == None) or (len(self.input_negatives) == 0):
user_negatives = None
else:
# remove genes from negatives if they are also positives
user_negatives = np.setdiff1d(self.convert_ids_negatives, self.convert_ids).tolist()
else:
user_negatives = None
self.negative_genes, self.neutral_gene_info = _geneplexus._get_negatives(
self.file_loc,
self.sp_trn,
Expand Down

0 comments on commit eb6adb1

Please sign in to comment.