Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
TOBIAS_snakemake/snakefiles/wilson.snake
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
93 lines (82 sloc)
3.65 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from snakemake.remote.HTTP import RemoteProvider as HTTPRemoteProvider | |
HTTP = HTTPRemoteProvider() | |
#Download the wilson app | |
rule wilson_app: | |
input: | |
HTTP.remote("https://github.molgen.mpg.de/loosolab/wilson-apps/archive/master.zip", keep_local = True) | |
output: | |
app = os.path.join(OUTPUTDIR, "wilson", "app.R") | |
log: | |
os.path.join(OUTPUTDIR, "logs", "wilson_installation.log") | |
params: | |
wilsondir = os.path.join(OUTPUTDIR, "wilson"), | |
scripts = scripts_dir | |
conda: | |
"../environments/wilson.yaml" | |
shell: | |
"mkdir -p {params.wilsondir}; " | |
"unzip -o {input} -d {params.wilsondir}; " | |
"cp -a {params.wilsondir}/wilson-apps-master/wilson-basic/. {params.wilsondir}; " | |
"rm -rf {params.wilsondir}/wilson-apps-master/; " | |
"rm -rf {params.wilsondir}/data/*;" | |
"Rscript {params.scripts}/install_wilson.R &> {log} " | |
#Make file of condition names to use for wilson conversion | |
rule get_condition_names: | |
output: | |
os.path.join(OUTPUTDIR, "wilson", "condition_names.txt") #will be deleted when all .clarion were made | |
params: | |
"\"{0}\"".format("\n".join(CONDITION_IDS) + "\n") | |
shell: | |
"printf {params} > {output}" | |
#Convert TF-specific overviews | |
rule convert_individual_overview: | |
input: | |
overview = os.path.join(OUTPUTDIR, "TFBS", "{TF}", "{TF}_overview.txt"), | |
condition_names = os.path.join(OUTPUTDIR, "wilson", "condition_names.txt"), | |
app = os.path.join(OUTPUTDIR, "wilson", "app.R") | |
params: | |
scripts = scripts_dir | |
conda: | |
"../environments/wilson.yaml" | |
output: | |
os.path.join(OUTPUTDIR, "wilson", "data", "{TF}_overview.clarion") | |
shell: | |
"Rscript {params.scripts}/convert_data.R --input {input.overview} --output {output} --condition_names {input.condition_names} &> /dev/null " | |
#Convert global bindetect-output: | |
rule convert_global_overview: | |
input: | |
overview = lambda wildcards: glob_wildcards(os.path.join(checkpoints.bindetect.get(**wildcards).output[0], "bindetect_overview.txt")), | |
condition_names = os.path.join(OUTPUTDIR, "wilson", "condition_names.txt"), | |
app = os.path.join(OUTPUTDIR, "wilson", "app.R") | |
output: | |
os.path.join(OUTPUTDIR, "wilson", "data", "bindetect_results.clarion") | |
params: | |
overview = os.path.join(OUTPUTDIR, "overview", "*_results.txt"), | |
scripts = scripts_dir | |
conda: | |
"../environments/wilson.yaml" | |
shell: | |
"Rscript {params.scripts}/convert_data.R --input {params.overview} --output {output} --condition_names {input.condition_names} &> /dev/null " | |
rule wilson_howto: | |
input: | |
individual_overview = lambda wildcards: expand(os.path.join(OUTPUTDIR, "wilson", "data", "{TF}_overview.clarion"), TF=get_TF_ids(wildcards)), | |
global_overview = os.path.join(OUTPUTDIR, "wilson", "data", "bindetect_results.clarion"), | |
app = os.path.join(OUTPUTDIR, "wilson", "app.R") | |
output: | |
os.path.join(OUTPUTDIR, "wilson", "HOW_TO_WILSON.txt") | |
run: | |
f = open(output[0], "w") | |
howto = """The wilson app (https://github.molgen.mpg.de/loosolab/wilson-apps) can be started by running the app.R within the wilson directory. | |
To do so, run the following code in R (or RStudio): | |
'' | |
if (!require(shiny)) install.packages("shiny"); library(shiny) | |
""" | |
howto += "runApp(\"{0}\")\n''\n".format(os.path.abspath(input.app)) | |
howto += """ | |
Now your browser will open and you can start using the app. If this is not the case try opening the link displayed in your console manually. | |
Note that unlike normal scripts the app will not terminate on its own so please make sure to close the respective process after you are done. | |
Furthermore, Windows users should install Rtools (https://cran.r-project.org/bin/windows/Rtools/) to enable plot downloading. | |
""" | |
f.write(howto) | |
f.close() |