Snakefile 6.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os

# these can be set on runtime: 
# snakemake --config datafolder="mydata" outfolder="out" dataset="breast" target="ER" (...)
DATAFOLDER = config['datafolder']
OUTFOLDER = config['outfolder']
DATASET = config['dataset']
TARGET = config['target']
LAYER1 = config['layer1']
LAYER2 = config['layer2']

rule all:
    input:
        expand("{outfolder}/{dataset}/{target}/rSNFi/{layer1}_{layer2}_tr_MCC_scores.txt", 
        outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layer1=LAYER1, layer2=LAYER2),
        expand("{outfolder}/{dataset}/{target}/single/{layer}_tr_MCC_scores.txt", 
        outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layer=LAYER1),
        expand("{outfolder}/{dataset}/{target}/single/{layer}_tr_MCC_scores.txt", 
        outfolder=OUTFOLDER, dataset=DATASET, target=TARGET, layer=LAYER2)


rule ml_juxt_tr:
    input:
Alessia Marcolini's avatar
Alessia Marcolini committed
24
25
        os.path.join(DATAFOLDER, "{dataset}/{target}/{layer1}_{layer2}_tr.txt"),
        os.path.join(DATAFOLDER, "{dataset}/{target}/labels_{target}_tr.txt")
26
27
28
29
30
31
32
33
34
    output:
        "{outfolder}/{dataset}/{target}/juxt/{layer1}_{layer2}_tr_RandomForest_KBest.log"
    shell:
        "python sklearn_rf_training_fixrank.py {input} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/juxt --ranking KBest"


rule ml_juxt_val:
    input:
        "{outfolder}/{dataset}/{target}/juxt/{layer1}_{layer2}_tr_RandomForest_KBest.log",
Alessia Marcolini's avatar
Alessia Marcolini committed
35
36
        os.path.join(DATAFOLDER, "{dataset}/{target}/{layer1}_{layer2}_ts.txt"),
        os.path.join(DATAFOLDER, "{dataset}/{target}/labels_{target}_ts.txt")
37
38
39
40
41
42
43
    output:
        "{outfolder}/{dataset}/{target}/juxt/{layer1}_{layer2}_tr_MCC_scores.txt"
    shell:
        "python sklearn_rf_validation_writeperf.py {input[0]} {input[1]} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/juxt --tslab {input[2]}"

rule snf:
    input:
Alessia Marcolini's avatar
Alessia Marcolini committed
44
        os.path.join(DATAFOLDER, "{dataset}/{target}/{layer1}_tr.txt"),
Alessia Marcolini's avatar
Alessia Marcolini committed
45
46
        os.path.join(DATAFOLDER, "{dataset}/{target}{layer2}_tr.txt"),
        os.path.join(DATAFOLDER, "{dataset}/{target}/labels_{target}_tr.txt")
47
48
49
50
51
52
53
54
55
56
57
    threads: 8
    output:
        "{outfolder}/{dataset}/{target}/rSNF/INF_{layer1}_{layer2}_tr.txt"
    shell:
        "Rscript snf_integration.R --d1 {input[0]} --d2 {input[1]} --lab {input[2]} \
		--scriptDir SNFtools/ --clust spectral --threads {threads} \
		--outf {output}"


rule ml_rsnf_tr:
    input:
Alessia Marcolini's avatar
Alessia Marcolini committed
58
59
        os.path.join(DATAFOLDER, "{dataset}/{target}/{layer1}_{layer2}_tr.txt"),
        os.path.join(DATAFOLDER, "{dataset}/{target}/labels_{target}_tr.txt"),
60
61
62
63
64
65
66
67
68
69
        "{outfolder}/{dataset}/{target}/rSNF/INF_{layer1}_{layer2}_tr.txt"
    output:
        "{outfolder}/{dataset}/{target}/rSNF/{layer1}_{layer2}_tr_RandomForest_rankList.log"
    shell:
        "python sklearn_rf_training_fixrank.py {input[0]} {input[1]} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/rSNF --ranking rankList --rankFeats {input[2]}"


rule ml_rsnf_val:
    input:
        "{outfolder}/{dataset}/{target}/rSNF/{layer1}_{layer2}_tr_RandomForest_rankList.log",
Alessia Marcolini's avatar
Alessia Marcolini committed
70
71
        os.path.join(DATAFOLDER, "{dataset}/{target}/{layer1}_{layer2}_ts.txt"),
        os.path.join(DATAFOLDER, "{dataset}/{target}/labels_{target}_ts.txt")
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    output:
        "{outfolder}/{dataset}/{target}/rSNF/{layer1}_{layer2}_tr_MCC_scores.txt"
    shell:
        "python sklearn_rf_validation_writeperf.py {input[0]} {input[1]} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/rSNF --tslab {input[2]}"


rule myintersect:
    input:
        "{outfolder}/{dataset}/{target}/juxt/{layer1}_{layer2}_tr_RandomForest_KBest.log",
        "{outfolder}/{dataset}/{target}/rSNF/{layer1}_{layer2}_tr_RandomForest_rankList.log"
    output:
        "{outfolder}/{dataset}/{target}/rSNFi/{layer1}_{layer2}_intersect_tr.txt"
    shell:
        "python intersect_biomarkers.py {input} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/rSNFi/venn_{wildcards.layer1}_{wildcards.layer2}_tr.png {output} --title1 {wildcards.layer1} --title2 {wildcards.layer2}"


rule extract:
    input:
Alessia Marcolini's avatar
Alessia Marcolini committed
90
        os.path.join(DATAFOLDER, "{dataset}/{target}/{layer1}_{layer2}_tr.txt"),
91
92
93
94
95
96
97
98
99
100
        "{outfolder}/{dataset}/{target}/rSNFi/{layer1}_{layer2}_intersect_tr.txt"
    output:
        "{outfolder}/{dataset}/{target}/rSNFi/{layer1}_{layer2}_tr.txt"
    shell:
        "python extract_topfeats_onecol.py {input} {output}"


rule ml_rsnfi_tr:
    input:
        "{outfolder}/{dataset}/{target}/rSNFi/{layer1}_{layer2}_tr.txt",
Alessia Marcolini's avatar
Alessia Marcolini committed
101
        os.path.join(DATAFOLDER, "{dataset}/{target}/labels_{target}_tr.txt")
102
103
104
105
106
107
108
109
110
    output:
        "{outfolder}/{dataset}/{target}/rSNFi/{layer1}_{layer2}_tr_RandomForest_KBest.log"
    shell:
        "python sklearn_rf_training_fixrank.py {input} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/rSNFi --ranking KBest"


rule ml_rsnfi_val:
    input:
        "{outfolder}/{dataset}/{target}/rSNFi/{layer1}_{layer2}_tr_RandomForest_KBest.log",
Alessia Marcolini's avatar
Alessia Marcolini committed
111
112
        os.path.join(DATAFOLDER, "{dataset}/{target}/{layer1}_{layer2}_ts.txt"),
        os.path.join(DATAFOLDER, "{dataset}/{target}/labels_{target}_ts.txt")
113
114
115
116
117
118
119
120
    output:
        "{outfolder}/{dataset}/{target}/rSNFi/{layer1}_{layer2}_tr_MCC_scores.txt"
    shell:
        "python sklearn_rf_validation_writeperf.py {input[0]} {input[1]} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/rSNFi --tslab {input[2]}"


rule single_tr:
    input:
Alessia Marcolini's avatar
Alessia Marcolini committed
121
122
        os.path.join(DATAFOLDER, "{dataset}/{target}/{layer}_tr.txt"),
        os.path.join(DATAFOLDER, "{dataset}/{target}/labels_{target}_tr.txt")
123
124
125
126
127
128
129
130
    output:
        "{outfolder}/{dataset}/{target}/single/{layer}_tr_RandomForest_KBest.log"
    shell:
        "python sklearn_rf_training_fixrank.py {input} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/single --ranking KBest"

rule single_val:
    input:
        "{outfolder}/{dataset}/{target}/single/{layer}_tr_RandomForest_KBest.log",
Alessia Marcolini's avatar
Alessia Marcolini committed
131
132
        os.path.join(DATAFOLDER, "{dataset}/{target}/{layer}_ts.txt"),
        os.path.join(DATAFOLDER, "{dataset}/{target}/labels_{target}_ts.txt")
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    output:
        "{outfolder}/{dataset}/{target}/single/{layer}_tr_MCC_scores.txt"
    shell:
        "python sklearn_rf_validation_writeperf.py {input[0]} {input[1]} {wildcards.outfolder}/{wildcards.dataset}/{wildcards.target}/single --tslab {input[2]}"


# rule single_layer:
#     input:
#         "data/{layer}_tr.txt",
#         "data/labels_{target}_tr.txt",
#         "data/{layer}_ts.txt",
#         "data/labels_{target}_ts.txt"
#     output:
#         "out/{target}/single/{layer}_tr_MCC_scores.txt"
#     shell:
#         """
#         python sklearn_rf_training_fixrank.py {input[0]} {input[1]} out/{wildcards.target}/single --ranking KBest
#         python sklearn_rf_validation_writeperf.py out/{wildcards.target}/single/{wildcards.layer}_tr_RandomForest_KBest.log {input[2]} out/{wildcards.target}/single --tslab {input[3]}
#         """