Skip to content

Commit

Permalink
update gene selection to include me-type (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkilic authored Jun 20, 2024
1 parent 6f12c01 commit 3f23764
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
20 changes: 10 additions & 10 deletions bluepyemodel/icselector/icselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,29 @@ def __set_parameters_from_gene(self, gene_name):
else:
logging.warning("Could not determine mechanism for gene %s", gene_name)

def _set_parameters_from_ttype(self):
def _set_parameters_from_mettype(self):
"""Copy parameters from selected genes to mechanims."""

for gene_name in self._gene_selector.selected_genes:
self.__set_parameters_from_gene(gene_name)

def _select_genes_from_ttype(self, key_words):
def _select_genes_from_mettype(self, mettype):
"""Select genes from key words.
Args:
key_words (list [str]): list of keys to select genes
mettype (dict): dict containing the etype, mtype and ttype
"""

# === Get genes from gene mapping file
logging.info("\n===============\nGenes Selection\n===============")
genes = self._gene_selector.select_from_ttype(key_words)
genes = self._gene_selector.select_from_mettype(mettype)
logging.info(str(self._gene_selector))

# === Map genes to channels
for gene, info in genes.items():
if gene in self._gene_to_ic:
info["channel"] = self._gene_to_ic[gene]

def _select_mechanisms_from_ttype(self):
def _select_mechanisms_from_mettype(self):
"""Select mechanisms from previously selected genes."""

logging.info("\n==================\nChannels Selection\n==================")
Expand Down Expand Up @@ -259,12 +259,12 @@ def _get_cell_config(self):
logging.info(str(config))
return config

def get_cell_config_from_ttype(self, key_words):
def get_cell_config_from_mettype(self, mettype):
"""Get all information related to cell model configuration from
mechanisms selected based on genetic expression profiles.
Args:
key_words: keys to select MET-types
mettype (dict): Dictionary containing the MET-types
Returns:
parameters (list [dict,]): mechanism parameters per compartment
Expand All @@ -274,9 +274,9 @@ def get_cell_config_from_ttype(self, key_words):
"""

# Perform selections
self._select_genes_from_ttype(key_words)
self._set_parameters_from_ttype()
self._select_mechanisms_from_ttype()
self._select_genes_from_mettype(mettype)
self._set_parameters_from_mettype()
self._select_mechanisms_from_mettype()

# Get configuration
mechs = self._model_selector.get_mechanisms()
Expand Down
34 changes: 19 additions & 15 deletions bluepyemodel/icselector/modules/gene_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ def get(self, gene_name):
return self.selected_genes[gene_name]
raise KeyError("Gene not available for the selected ttype.")

def select_from_ttype(self, keys=None, group_compartments=False):
def select_from_mettype(self, mettype, group_compartments=False):
"""Returns selected genes and distributions associated with provided
key words.
mettype.
Args:
keys (list [str]): List of keywords
mettype (dict): Dictionary containing the etype, mtype and ttype
group_compartments: Option to combine compartments into groups
(e.g. 'all', or 'alldend')
Expand All @@ -197,19 +197,23 @@ def select_from_ttype(self, keys=None, group_compartments=False):
"""

df = self._gene_map
if isinstance(keys, str):
keys = [keys]
if keys:
df = self._filter(df, keys)

me_type = f"{mettype['mtype']}_{mettype['etype']}"
t_type = mettype["ttype"]

# replace double underscores with spaces
t_type = t_type.replace("__", " ")

try:
genes = df.loc[(me_type, t_type)]
except KeyError as exc:
raise ValueError(
f"No records found for me-type: {me_type} \
and t-type: {t_type}"
) from exc

# Store result
self.selected_met_types = np.unique([f"{v[0]} - {v[1]}" for v in df.index.values])
df = df.droplevel([0, 1])
# Apply filter also to genes
if keys:
genes = self._filter(df.T, keys)
genes = genes.T
else:
genes = df
self.selected_met_types = [f"{me_type} - {t_type}"]

names = genes.columns.values
for name in names:
Expand Down
9 changes: 7 additions & 2 deletions bluepyemodel/model/model_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,13 @@ def get_gene_based_parameters(self):
ic_map_path = self.access_point.load_ic_map()

selector = icselector.ICSelector(ic_map_path, gene_map_path)
parameters, mechanisms, distributions, nexus_keys = selector.get_cell_config_from_ttype(
self.access_point.emodel_metadata.ttype
mettype = {
"etype": self.access_point.emodel_metadata.etype,
"mtype": self.access_point.emodel_metadata.mtype,
"ttype": self.access_point.emodel_metadata.ttype,
}
parameters, mechanisms, distributions, nexus_keys = selector.get_cell_config_from_mettype(
mettype
)

return parameters, mechanisms, distributions, nexus_keys
Expand Down

0 comments on commit 3f23764

Please sign in to comment.