Skip to content

Commit

Permalink
Implement combining of rankings
Browse files Browse the repository at this point in the history
  • Loading branch information
nictru committed Mar 18, 2024
1 parent 53d99c7 commit 2e099d3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bin/combine_rankings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3

import argparse
import pandas as pd

parser = argparse.ArgumentParser(description='Combine TF rankings')
parser.add_argument('--input', type=str, nargs='+', help='Assay specific score files', required=True)
parser.add_argument('--output', type=str, help='Output file', required=True)

args = parser.parse_args()

dfs = [pd.read_csv(f, sep='\t', header=0, index_col=0) for f in args.input]
df = pd.concat([df[['dcg']] for df in dfs])

df = df.groupby(df.index).sum()
df.sort_values(by=['dcg'], ascending=False, inplace=True)

df['rank'] = range(1, len(df.index) + 1)

df.to_csv(args.output, sep='\t', index=True)
8 changes: 8 additions & 0 deletions conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ process {
]
}

withName: COMBINE_RANKINGS {
publishDir = [
path: { "${params.outdir}" },
mode: params.publish_dir_mode,
saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
]
}

withName: CUSTOM_DUMPSOFTWAREVERSIONS {
publishDir = [
path: { "${params.outdir}/pipeline_info" },
Expand Down
29 changes: 29 additions & 0 deletions modules/local/ranking/combine_rankings.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
process COMBINE_RANKINGS {
tag "$meta.id"
label "process_single"

conda "bioconda::mulled-v2-cd5249a47f81a81b2e7785172c240f12497f55b4==c5c6cff7c28d3260400f938602ee600b1acf0323-0"
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/mulled-v2-cd5249a47f81a81b2e7785172c240f12497f55b4:c5c6cff7c28d3260400f938602ee600b1acf0323-0':
'biocontainers/mulled-v2-cd5249a47f81a81b2e7785172c240f12497f55b4:c5c6cff7c28d3260400f938602ee600b1acf0323-0' }"

input:
tuple val(meta), path(rankings)

output:
tuple val(meta), path("combined.ranking.tsv"), emit: ranking

path "versions.yml" , emit: versions

script:
"""
combine_rankings.py --input ${rankings} --output combined.ranking.tsv
cat <<-END_VERSIONS > versions.yml
"${task.process}":
python: \$(python --version | sed 's/Python //g')
pandas: \$(python -c "import pandas; print(pandas.__version__)")
numpy: \$(python -c "import numpy; print(numpy.__version__)")
END_VERSIONS
"""
}
5 changes: 5 additions & 0 deletions subworkflows/local/ranking.nf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include { TF_TG_SCORE } from '../../modules/local/ranking/tf_tg_score'
include { RANKING as CREATE_RANKING } from '../../modules/local/ranking/ranking'
include { COMBINE_RANKINGS } from '../../modules/local/ranking/combine_rankings'

workflow RANKING {

Expand All @@ -26,6 +27,10 @@ workflow RANKING {

TF_TG_SCORE(ch_combined)
CREATE_RANKING(TF_TG_SCORE.out.score, alpha)
COMBINE_RANKINGS(CREATE_RANKING.out.ranking .map{ meta, ranking -> ranking }
.collect()
.map{ rankings -> [[id: "all"], rankings]}
)


emit:
Expand Down

0 comments on commit 2e099d3

Please sign in to comment.