Skip to content

Commit

Permalink
Add: merge_pvalues and create_consensus modules
Browse files Browse the repository at this point in the history
  • Loading branch information
dileep-kishore committed Oct 7, 2021
1 parent 5bfa231 commit 1a7ef3b
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 2 deletions.
7 changes: 7 additions & 0 deletions micone/pipelines/configs/network_inference.config
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ params {
// FIXME: This should ideally be passed through the sample_sheet
metadata_file = ""
}
'merge_pvalues' {}
'create_consensus' {
method = 'scaled_sum'
parameter = 0.3
pvalue_filter = "true"
interaction_filter = "true"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
include { getHierarchy } from '../../../functions/functions.nf'

process create_consensus {
label 'micone'
tag "${meta.id}"
publishDir "${params.output_dir}/${f[0]}/network/${f[1]}/${directory}/${meta.id}",
mode: 'copy',
overwrite: true
input:
tuple val(meta), file('*_network.json')
output:
tuple val(meta), file('*_network.json')
script:
String task_process = "${task.process}"
f = getHierarchy(task_process)
directory = "${meta.denoise_cluster}-${meta.chimera_checking}-${meta.tax_assignment}-${meta.tax_level}-${meta.network_inference}"
method = params.network_inference.network['create_consensus']['method']
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']
template 'network_inference/network/create_consensus.py'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
include { getHierarchy } from '../../../functions/functions.nf'

process merge_pvalues {
label 'micone'
tag "${meta.id}"
publishDir "${params.output_dir}/${f[0]}/network/${f[1]}/${directory}/${meta.id}",
mode: 'copy',
overwrite: true
input:
tuple val(meta), file('*_network.json')
output:
tuple val(meta), file('*_network.json')
script:
String task_process = "${task.process}"
f = getHierarchy(task_process)
directory = "${meta.denoise_cluster}-${meta.chimera_checking}-${meta.tax_assignment}-${meta.tax_level}-${meta.network_inference}"
template 'network_inference/network/merge_pvalues.py'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ include { mldm_workflow } from './direct/mldm_workflow.nf'
// Network imports
include { make_network_with_pvalue } from './network/make_network_with_pvalue.nf'
include { make_network_without_pvalue } from './network/make_network_without_pvalue.nf'
include { merge_pvalues } from './network/merge_pvalues.nf'
include { create_consensus } from './network/create_consensus.nf'

// Main workflow
workflow network_inference_workflow {
Expand Down Expand Up @@ -46,13 +48,20 @@ workflow network_inference_workflow {
mldm_workflow.out
)

// Correlation method output
make_network_with_pvalue(corr_output)
merge_pvalues(make_network_with_pvalue.out.collect())

// Direct method output
make_network_without_pvalue(direct_output)

network_channel = make_network_with_pvalue.out.mix(make_network_without_pvalue.out)
// Create consensus
network_channel = merge_pvalues.out.flatten().mix(make_network_without_pvalue.out)
create_consensus(network_channel.out.collect())


emit:
// all processes have publishDir
// tuple val(meta), file("*.json")
network_channel
create_consensus.out
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3

import pathlib
from typing import List

from micone import Network, NetworkGroup


def main(
base_name: str,
network_files: List[pathlib.Path],
method: str,
parameter: float,
pvalue_filter: bool,
interaction_filter: bool,
) -> None:
networks: List[Network] = []
for network_file in network_files:
networks.append(Network.load_json(str(network_file)))
network_group = NetworkGroup(networks)
cids = [ctx["cid"] for ctx in network_group.contexts]
filtered_network_group = network_group.filter(
pvalue_filter=pvalue_filter, interaction_filter=interaction_filter
)
consensus_network_group = filtered_network_group.get_consensus_network(
cids, method=method, parameter=parameter
)
consensus_network_group.write(base_name + "_network.json")


if __name__ == "__main__":
BASE_NAME = "${meta.id}"
METHOD = "${method}"
PARAMETER = float("${parameter}")
PVALUE_FILTER = True if "${pvalue_filter}" == "true" else False
INTERACTION_FILTER = True if "${interaction_filter}" == "true" else False
NETWORK_FILES = list(pathlib.Path().glob("*.json"))
main(BASE_NAME, NETWORK_FILES, METHOD, PARAMETER, PVALUE_FILTER, INTERACTION_FILTER)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3

import pathlib
from typing import List

from micone import Network, NetworkGroup


def main(base_name: str, network_files: List[pathlib.Path]) -> None:
networks: List[Network] = []
for network_file in network_files:
networks.append(Network.load_json(str(network_file)))
network_group = NetworkGroup(networks)
cids = [ctx["cid"] for ctx in network_group.contexts]
merged_network_group = network_group.combine_pvalues(cids)
merged_network_group.write(base_name + "_network.json", split_files=True)


if __name__ == "__main__":
BASE_NAME = "${meta.id}"
NETWORK_FILES = list(pathlib.Path().glob("*.json"))
main(BASE_NAME, NETWORK_FILES)

0 comments on commit 1a7ef3b

Please sign in to comment.