-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnakeVariants.smk
82 lines (80 loc) · 3.66 KB
/
snakeVariants.smk
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
#snakemake -s snakeVariants.smk -j 12 --cluster "qsub -l walltime={params.run_time} -l nodes=1:ppn={params.cores} -q home-yeo -e {params.error_out_file} -o {params.out_file}" --configfile config/preprocess_config/oligose_k562.yaml --use-conda --conda-prefix /home/hsher/snakeconda -np
import pandas as pd
workdir: config['WORKDIR']
SCRIPT_PATH = config['SCRIPT_PATH']
manifest = pd.read_table(config['MANIFEST'], index_col = False, sep = ',')
print(manifest)
barcode_df = pd.read_csv(config['barcode_csv'], header = None, sep = ':', names = ['barcode', 'RBP'])
# basic checking
assert not barcode_df['barcode'].duplicated().any()
assert not barcode_df['RBP'].duplicated().any() # cannot have any duplicated RBP names
assert not barcode_df['RBP'].str.contains(' ').any() # DO NOT CONTAIN white space lah
assert not manifest['fastq'].duplicated().any()
assert not manifest['libname'].str.contains(' ').any()
libnames = manifest['libname'].tolist()
config['libnames'] = libnames
experiments = manifest['experiment'].tolist()
config['experiments'] = experiments
rbps = barcode_df['RBP'].tolist()
config['rbps'] = rbps
seq_df = '/home/hsher/scratch/ABC_DL/output/tsv/K562_rep6.RBFOX2.tsv' # need to be of the same as the feature annotatiions
rule all:
input:
expand("variants/{signal_type}/{libname}.{sample_label}.csv",
signal_type = ['CITS'],
libname = ['K562_rep6'],
sample_label = ['RBFOX2', 'SF3B4', 'PRPF8'],
)
rule fetch_SNP:
input:
finemapped_windows = "DMM/finemapping/mapped_sites/{signal_type}/{libname}.{sample_label}.finemapped_windows.bed.gz"
output:
"variants/{signal_type}/{libname}.{sample_label}.{chr}.vcf"
params:
error_out_file = "error_files/fetch_snp.{signal_type}.{libname}.{sample_label}.{chr}",
out_file = "stdout/fetch_snp.{signal_type}.{libname}.{sample_label}.{chr}",
run_time = "1:20:00",
cores = 1,
shell:
"""
module load bcftools
bcftools query -R {input.finemapped_windows} -f '%CHROM\t%POS\t%ID\t%REF\t%ALT\t%INFO/AC\t%INFO/AN\n' \
https://gnomad-public-us-east-1.s3.amazonaws.com/release/3.1.2/vcf/genomes/gnomad.genomes.v3.1.2.sites.{wildcards.chr}.vcf.bgz > {output}
"""
rule fetch_sequence:
input:
subset_vcf="variants/{signal_type}/{libname}.{sample_label}.{chr}.vcf",
seq_df=seq_df,
feature_annotation=config['FEATURE_ANNOTATIONS'],
output:
temp("variants/{signal_type}/{libname}.{sample_label}.{chr}.csv")
params:
error_out_file = "error_files/fetch_sequence.{signal_type}.{libname}.{sample_label}.{chr}",
out_file = "stdout/fetch_sequence.{signal_type}.{libname}.{sample_label}.{chr}",
run_time = "01:20:00",
cores = 1
conda:
"/home/hsher/projects/oligoCLIP/rules/envs/metadensity.yaml"
shell:
"""
python {SCRIPT_PATH}/generate_variant_sequence.py {input.subset_vcf} {input.seq_df} {input.feature_annotation} \
{output}
"""
rule combine_csv:
input:
expand("variants/{signal_type}/{libname}.{sample_label}.{chr}.csv",
signal_type = ['{signal_type}'],
libname = ['{libname}'],
sample_label = ['{sample_label}'],
chr = [f'chr{i}' for i in list(range(1,23))+['X','Y']])
output:
"variants/{signal_type}/{libname}.{sample_label}.csv"
params:
error_out_file = "error_files/combine.{signal_type}.{libname}.{sample_label}",
out_file = "stdout/combine.{signal_type}.{libname}.{sample_label}",
run_time = "01:20:00",
cores = 1
shell:
"""
awk 'FNR==1 && NR!=1{{next;}}{{print}}' {input} > {output}
"""