Skip to content

Commit

Permalink
Add: Allow id_field support for merge_pvalues and create_consensus
Browse files Browse the repository at this point in the history
  • Loading branch information
dileep-kishore committed Dec 1, 2021
1 parent ae385eb commit a9f3e92
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion micone/pipelines/configs/network_inference.config
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ params {
interaction_threshold = 0.3
metadata_file = ""
}
// 'merge_pvalues' {}
'merge_pvalues' {
id_field = "taxid"
}
'create_consensus' {
method = 'scaled_sum'
parameter = 0.3
pvalue_filter = "true"
interaction_filter = "true"
id_field = "taxid"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ process create_consensus {
parameter = params.network_inference.network['create_consensus']['parameter']
pvalue_filter = params.network_inference.network['create_consensus']['pvalue_filter']
interaction_filter = params.network_inference.network['create_consensus']['interaction_filter']
id_field = params.network_inference.network['create_consensus']['id_field']
template 'network_inference/network/create_consensus.py'
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ process merge_pvalues {
script:
String task_process = "${task.process}"
f = getHierarchy(task_process)
id_field = params.network_inference.network['merge_pvalues']['id_field']
template 'network_inference/network/merge_pvalues.py'
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ def main(
parameter: float,
pvalue_filter: bool,
interaction_filter: bool,
id_field: str,
) -> None:
networks: List[Network] = []
for network_file in network_files:
networks.append(Network.load_json(str(network_file)))
network_group = NetworkGroup(networks)
network_group = NetworkGroup(networks, id_field=id_field)
pathlib.Path("consensus/").mkdir(parents=True, exist_ok=True)
cids = list(range(len(network_group.contexts)))
filtered_network_group = network_group.filter(
Expand All @@ -35,5 +36,14 @@ def main(
PARAMETER = float("${parameter}")
PVALUE_FILTER = True if "${pvalue_filter}" == "true" else False
INTERACTION_FILTER = True if "${interaction_filter}" == "true" else False
ID_FIELD = "${id_field}"
NETWORK_FILES = list(pathlib.Path().glob("*_network.json"))
main(BASE_NAME, NETWORK_FILES, METHOD, PARAMETER, PVALUE_FILTER, INTERACTION_FILTER)
main(
BASE_NAME,
NETWORK_FILES,
METHOD,
PARAMETER,
PVALUE_FILTER,
INTERACTION_FILTER,
ID_FIELD,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from micone import Network, NetworkGroup


def main(base_name: str, network_files: List[pathlib.Path]) -> None:
def main(base_name: str, network_files: List[pathlib.Path], id_field: str) -> None:
networks: List[Network] = []
for network_file in network_files:
networks.append(Network.load_json(str(network_file)))
network_group = NetworkGroup(networks)
network_group = NetworkGroup(networks, id_field=id_field)
pathlib.Path("merged/").mkdir(parents=True, exist_ok=True)
cids = list(range(len(network_group.contexts)))
merged_network_group = network_group.combine_pvalues(cids)
Expand All @@ -21,5 +21,6 @@ def main(base_name: str, network_files: List[pathlib.Path]) -> None:

if __name__ == "__main__":
BASE_NAME = "merged"
ID_FIELD = "${id_field}"
NETWORK_FILES = list(pathlib.Path().glob("*_network.json"))
main(BASE_NAME, NETWORK_FILES)
main(BASE_NAME, NETWORK_FILES, ID_FIELD)

0 comments on commit a9f3e92

Please sign in to comment.