Snakefile 8.8 KB
Newer Older
Nicole Bussola's avatar
Nicole Bussola committed
1
#%%
2
import os
3
import subprocess
Nicole Bussola's avatar
Nicole Bussola committed
4
#%%
5
# these can be set on runtime: 
Alessia Marcolini's avatar
Alessia Marcolini committed
6
# snakemake --config datafolder="mydata" outfolder="out" dataset="breast" target="ER" layer1="gene" layer2="cnv" layer3="prot" split_id="1"(...)
7
8
9
10
DATAFOLDER = config['datafolder']
OUTFOLDER = config['outfolder']
DATASET = config['dataset']
TARGET = config['target']
Alessia Marcolini's avatar
Alessia Marcolini committed
11
SPLIT_ID = config['split_id']
12
13
14

LAYERS = [config[k] for k in config.keys() if k.startswith('layer')]
LAYERS_CONCAT = "_".join(LAYERS)
15

Alessia Marcolini's avatar
Alessia Marcolini committed
16

17
18
rule all:
    input:
19
20
21
22
        expand("{outfolder}/{dataset}/{target}/{split_id}/juxt/{layers}_tr_MCC_scores.txt", 
        outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID),
        expand("{outfolder}/{dataset}/{target}/{split_id}/rSNF/{layers}_tr_MCC_scores.txt", 
        outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID),
23
        expand("{outfolder}/{dataset}/{target}/{split_id}/rSNFi/{layers}_tr_MCC_scores.txt", 
Alessia Marcolini's avatar
Alessia Marcolini committed
24
        outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID),
25
        expand("{outfolder}/{dataset}/{target}/{split_id}/single/{layer}_tr_MCC_scores.txt", 
Alessia Marcolini's avatar
Alessia Marcolini committed
26
        outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layer=LAYERS, split_id=SPLIT_ID)
27
28
29

rule ml_juxt_tr:
    input:
30
        os.path.join(DATAFOLDER, "{dataset}/{target}/{split_id}/{layers}_tr.txt"),
31
        os.path.join(DATAFOLDER, "{dataset}/{target}/{split_id}/labels_{target}_tr.txt")
32
    output:
33
        "{outfolder}/{dataset}/{target}/{split_id}/juxt/{layers}_tr_RandomForest_KBest.log"
34
    shell:
Nicole Bussola's avatar
Nicole Bussola committed
35
        "python sklearn_rf_training_fixrank.py {input} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/{wildcards.split_id}/juxt --ranking KBest"
36
37
38
39


rule ml_juxt_val:
    input:
40
41
        "{outfolder}/{dataset}/{target}/{split_id}/juxt/{layers}_tr_RandomForest_KBest.log",
        os.path.join(DATAFOLDER, "{dataset}/{target}/{split_id}/{layers}_ts.txt"),
42
        os.path.join(DATAFOLDER, "{dataset}/{target}/{split_id}/labels_{target}_ts.txt")
43
    output:
44
        "{outfolder}/{dataset}/{target}/{split_id}/juxt/{layers}_tr_MCC_scores.txt"
45
    shell:
46
        "python sklearn_rf_validation_writeperf.py {input[0]} {input[1]} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/{wildcards.split_id}/juxt --tslab {input[2]}"
47

48

49
50
rule snf:
    input:
51
        expand("{datafolder}/{dataset}/{target}/{split_id}/{layer}_tr.txt", 
Alessia Marcolini's avatar
Alessia Marcolini committed
52
            datafolder=DATAFOLDER, dataset=DATASET, target=TARGET, layer=LAYERS, split_id=SPLIT_ID),
53
        expand("{datafolder}/{dataset}/{target}/{split_id}/labels_{target}_tr.txt", 
Alessia Marcolini's avatar
Alessia Marcolini committed
54
            datafolder=DATAFOLDER, dataset=DATASET, target=TARGET, split_id=SPLIT_ID)
55
56
    threads: 8
    output:
57
        expand("{outfolder}/{dataset}/{target}/{split_id}/rSNF/INF_{layers}_tr.txt", 
Alessia Marcolini's avatar
Alessia Marcolini committed
58
        outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID)
59
60
61
62
63
    run:
        all_input = [i[1] for i in input.allitems()]
        inputfiles = " ".join(all_input[:-1])
        labfile = all_input[-1]
        subprocess.call(f"Rscript snf_integration.R --data {inputfiles} --lab {labfile} \
64
		--scriptDir SNFtools/ --clust spectral --threads {threads} \
65
		--outf {output}", shell=True)
66
67
68
69


rule ml_rsnf_tr:
    input:
Alessia Marcolini's avatar
Alessia Marcolini committed
70
71
72
73
74
        expand("{datafolder}/{dataset}/{target}/{split_id}/{layers}_tr.txt", 
            datafolder=DATAFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID),
        expand("{datafolder}/{dataset}/{target}/{split_id}/labels_{target}_tr.txt",
            datafolder=DATAFOLDER, dataset=DATASET, target=TARGET, split_id=SPLIT_ID),
        "{outfolder}/{dataset}/{target}/{split_id}/rSNF/INF_{layers}_tr.txt", 
75
    output:
Alessia Marcolini's avatar
Alessia Marcolini committed
76
        "{outfolder}/{dataset}/{target}/{split_id}/rSNF/{layers}_tr_RandomForest_rankList.log",
77
    shell:
78
        "python sklearn_rf_training_fixrank.py {input[0]} {input[1]} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/{wildcards.split_id}/rSNF --ranking rankList --rankFeats {input[2]}"
79
80
81
82


rule ml_rsnf_val:
    input:
Alessia Marcolini's avatar
Alessia Marcolini committed
83
84
85
86
87
88
89
        expand("{outfolder}/{dataset}/{target}/{split_id}/rSNF/{layers}_tr_RandomForest_rankList.log",
            outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID),
        expand("{datafolder}/{dataset}/{target}/{split_id}/{layers}_ts.txt", 
            datafolder=DATAFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID),
        expand("{datafolder}/{dataset}/{target}/{split_id}/labels_{target}_ts.txt",
            datafolder=DATAFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID),
    output:
Alessia Marcolini's avatar
Alessia Marcolini committed
90
        "{outfolder}/{dataset}/{target}/{split_id}/rSNF/{layers}_tr_MCC_scores.txt",
91
    shell:
92
        "python sklearn_rf_validation_writeperf.py {input[0]} {input[1]} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/{wildcards.split_id}/rSNF --tslab {input[2]}"
93
94
95
96


rule myintersect:
    input:
Alessia Marcolini's avatar
Alessia Marcolini committed
97
98
99
100
        expand("{outfolder}/{dataset}/{target}/{split_id}/juxt/{layers}_tr_RandomForest_KBest.log",
            outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID),
        expand("{outfolder}/{dataset}/{target}/{split_id}/rSNF/{layers}_tr_RandomForest_rankList.log",
            outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID)
101
    output:
Alessia Marcolini's avatar
Alessia Marcolini committed
102
103
        expand("{outfolder}/{dataset}/{target}/{split_id}/rSNFi/{layers}_intersect_tr.txt",
            outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID)
104
    shell:
Alessia Marcolini's avatar
Alessia Marcolini committed
105
        "python intersect_biomarkers.py {input}  {output}"  ######## 
106
107
108
109


rule extract:
    input:
Alessia Marcolini's avatar
Alessia Marcolini committed
110
111
112
113
        expand("{datafolder}/{dataset}/{target}/{split_id}/{layers}_tr.txt",
            datafolder=DATAFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID),
        expand("{outfolder}/{dataset}/{target}/{split_id}/rSNFi/{layers}_intersect_tr.txt",
            outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID)
114
    output:
Alessia Marcolini's avatar
Alessia Marcolini committed
115
116
        expand("{outfolder}/{dataset}/{target}/{split_id}/rSNFi/{layers}_tr.txt",
            outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layers=LAYERS_CONCAT, split_id=SPLIT_ID)
117
118
119
120
121
122
    shell:
        "python extract_topfeats_onecol.py {input} {output}"


rule ml_rsnfi_tr:
    input:
Alessia Marcolini's avatar
Alessia Marcolini committed
123
124
125
126
        expand("{outfolder}/{dataset}/{target}/{split_id}/rSNFi/{layers}_tr.txt",
            outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, split_id=SPLIT_ID, layers=LAYERS_CONCAT),
        expand("{datafolder}/{dataset}/{target}/{split_id}/labels_{target}_tr.txt",
            datafolder=DATAFOLDER, dataset=DATASET, target=TARGET, split_id=SPLIT_ID, layers=LAYERS_CONCAT),
127
    output:
Alessia Marcolini's avatar
Alessia Marcolini committed
128
        "{outfolder}/{dataset}/{target}/{split_id}/rSNFi/{layers}_tr_RandomForest_KBest.log"
129
    shell:
130
        "python sklearn_rf_training_fixrank.py {input} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/{wildcards.split_id}/rSNFi --ranking KBest"
131
132
133
134


rule ml_rsnfi_val:
    input:
Alessia Marcolini's avatar
Alessia Marcolini committed
135
136
137
138
139
140
        expand("{outfolder}/{dataset}/{target}/{split_id}/rSNFi/{layers}_tr_RandomForest_KBest.log",
            outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, split_id=SPLIT_ID, layers=LAYERS_CONCAT),
        expand("{datafolder}/{dataset}/{target}/{split_id}/{layers}_ts.txt",
            datafolder=DATAFOLDER, dataset=DATASET, target=TARGET, split_id=SPLIT_ID, layers=LAYERS_CONCAT),
        expand("{datafolder}/{dataset}/{target}/{split_id}/labels_{target}_ts.txt",
            datafolder=DATAFOLDER, dataset=DATASET, target=TARGET, split_id=SPLIT_ID, layers=LAYERS_CONCAT)
141
    output:
Alessia Marcolini's avatar
Alessia Marcolini committed
142
        "{outfolder}/{dataset}/{target}/{split_id}/rSNFi/{layers}_tr_MCC_scores.txt"
143
    shell:
144
        "python sklearn_rf_validation_writeperf.py {input[0]} {input[1]} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/{wildcards.split_id}/rSNFi --tslab {input[2]}"
145
146
147
148


rule single_tr:
    input:
149
150
        os.path.join(DATAFOLDER, "{dataset}/{target}/{split_id}/{layer}_tr.txt"),
        os.path.join(DATAFOLDER, "{dataset}/{target}/{split_id}/labels_{target}_tr.txt")
151
    output:
152
        "{outfolder}/{dataset}/{target}/{split_id}/single/{layer}_tr_RandomForest_KBest.log"
153
    shell:
154
        "python sklearn_rf_training_fixrank.py {input} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/{wildcards.split_id}/single --ranking KBest"
155
156
157

rule single_val:
    input:
158
159
160
        "{outfolder}/{dataset}/{target}/{split_id}/single/{layer}_tr_RandomForest_KBest.log",
        os.path.join(DATAFOLDER, "{dataset}/{target}/{split_id}/{layer}_ts.txt"),
        os.path.join(DATAFOLDER, "{dataset}/{target}/{split_id}/labels_{target}_ts.txt")
161
    output:
162
        "{outfolder}/{dataset}/{target}/{split_id}/single/{layer}_tr_MCC_scores.txt"
163
    shell:
164
        "python sklearn_rf_validation_writeperf.py {input[0]} {input[1]} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/{wildcards.split_id}/single --tslab {input[2]}"