-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile_error
152 lines (127 loc) · 5.59 KB
/
Snakefile_error
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"""
BUSTED-PH SNAKEFILE TO RUN OG BUSTED TO EMULATE BUSTED-PH
USED BUSTED'S 'ERROR SINK MODE'
@Author: Avery Selberg
2023
"""
#----------------------------------------------------------------------------
# Description
#----------------------------------------------------------------------------
import os
import sys
import json
import csv
from pathlib import Path
import glob
#----------------------------------------------------------------------------
# Declares
#----------------------------------------------------------------------------
with open('config_error.json', 'r') as input_cf:
config = json.load(input_cf)
#----------------------------------------------------------------------------
# Settings
#----------------------------------------------------------------------------
BASEDIR = os.getcwd()
# Which project are we analyzing?
DATA_DIRECTORY = config["data_directory"]
gene_names = ["ATPalpha1", "GH19_chitinase", "lysozyme", "og3737", "og9103", "og9298", "PAP", "PCK", "PEPC2", "prestin", "RNASE1", "RNaseT2"]
#gene_names = ['mitogene']
#print(gene_names)
HYPHY = config["hyphy"]
RES = config["res"]
HYPHY_ANALYSES = config["hyphy-analyses"]
OUTDIR = config["results_directory"]
#print(OUTDIR)
BUSTED_PH_BF = os.path.join(HYPHY_ANALYSES, "BUSTED-PH", "BUSTED-PH.bf")
#FILTER_OUTLIERS_BF = os.path.join(HYPHY_ANALYSES, "find-outliers", "find-outliers-slac.bf")
#LAB_MRCA_BF = os.path.join(DATA_DIRECTORY, "label-tree.bf")
LAB_TREE = os.path.join(HYPHY_ANALYSES, "LabelTrees", "label-tree.bf")
# Create output directories
Path(OUTDIR).mkdir(parents=True, exist_ok=True)
#----------------------------------------------------------------------------
# rule all
#----------------------------------------------------------------------------
rule all:
input:
expand(os.path.join(OUTDIR, "{GENE}-lab.nwk"), GENE = gene_names),
expand(os.path.join(OUTDIR, "{GENE}-fg.BUSTED-E.json"), GENE = gene_names),
expand(os.path.join(OUTDIR, "{GENE}-bg.BUSTED-E.json"), GENE = gene_names),
expand(os.path.join(OUTDIR, "{GENE}-fg.BUSTED.json"), GENE = gene_names),
expand(os.path.join(OUTDIR, "{GENE}-bg.BUSTED.json"), GENE = gene_names)
#end input
#end rule
#----------------------------------------------------------------------------
# Run LABEL TREE
#----------------------------------------------------------------------------
rule label_tree:
input:
#seq = os.path.join(DATA_DIRECTORY, "{GENE}", 'alignment.fa'),
tree = os.path.join(DATA_DIRECTORY, "{GENE}", "tree.nwk"),
list = os.path.join(DATA_DIRECTORY, "{GENE}", "foreground_species.txt")
output:
tree = os.path.join(OUTDIR, "{GENE}-lab.nwk")
shell:
"""
{HYPHY} LIBPATH={RES} {LAB_TREE} --tree {input.tree} --list {input.list} --output {output.tree} --label FOREGROUND
"""
#----------------------------------------------------------------------------
# Run BUSTED WITH ERROR SINK COMPONENET
#----------------------------------------------------------------------------
## RUN BUSTED ON FOREGROUND BRANCHES##
rule busted_e_fg:
input:
seq = os.path.join(DATA_DIRECTORY, "{GENE}", 'alignment.fa'),
tree = rules.label_tree.output.tree
output:
json = os.path.join(OUTDIR, "{GENE}-fg.BUSTED-E.json"),
fits = os.path.join(OUTDIR, "{GENE}-fg.BUSTED-E-fit.lf")
shell:
"""
{HYPHY} LIBPATH={RES} BUSTED --alignment {input.seq} --tree {input.tree} --branches FOREGROUND --srv Yes --starting-points 5 --output {output.json} --error-sink Yes --save-fit {output.fits}
"""
## RUN BUSTED ON BACKGROUND BRANCHES##
###end rule
rule busted_e_bg:
input:
seq = os.path.join(DATA_DIRECTORY, "{GENE}", 'alignment.fa'),
tree = rules.label_tree.output.tree
output:
json = os.path.join(OUTDIR, "{GENE}-bg.BUSTED-E.json"),
fits = os.path.join(OUTDIR, "{GENE}-bg.BUSTED-E.fit.lf")
shell:
"""
{HYPHY} LIBPATH={RES} BUSTED --alignment {input.seq} --tree {input.tree} --branches 'Unlabeled branches' --srv Yes --starting-points 5 --output {output.json} --error-sink Yes --save-fit {output.fits}
"""
###end rule
#----------------------------------------------------------------------------
# Run BUSTED WITHOUT ERROR SINK COMPONENET
#----------------------------------------------------------------------------
## RUN BUSTED ON FOREGROUND BRANCHES##
rule busted_fg:
input:
seq = os.path.join(DATA_DIRECTORY, "{GENE}", 'alignment.fa'),
tree = rules.label_tree.output.tree
output:
json = os.path.join(OUTDIR, "{GENE}-fg.BUSTED.json"),
fits = os.path.join(OUTDIR, "{GENE}-fg.BUSTED-fit.lf")
shell:
"""
{HYPHY} LIBPATH={RES} BUSTED --alignment {input.seq} --tree {input.tree} --branches FOREGROUND --srv Yes --starting-points 5 --output {output.json} --save-fit {output.fits}
"""
## RUN BUSTED ON BACKGROUND BRANCHES##
###end rule
rule busted_bg:
input:
seq = os.path.join(DATA_DIRECTORY, "{GENE}", 'alignment.fa'),
tree = rules.label_tree.output.tree
output:
json = os.path.join(OUTDIR, "{GENE}-bg.BUSTED.json"),
fits = os.path.join(OUTDIR, "{GENE}-bg.BUSTED.fit.lf")
shell:
"""
{HYPHY} LIBPATH={RES} BUSTED --alignment {input.seq} --tree {input.tree} --branches 'Unlabeled branches' --srv Yes --starting-points 5 --output {output.json} --save-fit {output.fits}
"""
###end rule
#----------------------------------------------------------------------------
# End of file
#----------------------------------------------------------------------------