-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMapping.Snakefile
94 lines (84 loc) · 7.52 KB
/
Mapping.Snakefile
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
import os
import glob
import re
import paramiko
import pandas as pd
import minus80 as m80
from urllib.parse import urlparse
# ----------------------------------------------------------
# Set up Minus80 Objects
# ----------------------------------------------------------
MFCohort = m80.Cohort('MuscleFat')
SAMPLES = MFCohort.names
# ----------------------------------------------------------
# One ring to Rule them all
# ----------------------------------------------------------
rule all:
input:
'data/SalmonQuant/MFCohort.tsv'
#expand('data/SalmonQuant/{sample}',sample=SAMPLES)
# ----------------------------------------------------------
# Rules
# ----------------------------------------------------------
rule trim_reads:
input:
R1 = lambda wc: sorted([urlparse(x).path for x in MFCohort[wc.sample].files if 'R1' in x]),
R2 = lambda wc: sorted([urlparse(x).path for x in MFCohort[wc.sample].files if 'R2' in x])
output:
R1 = 'data/trimmedfastq/{sample}.R1.fastq.gz',
R2 = 'data/trimmedfastq/{sample}.R2.fastq.gz'
run:
shell('''
AdapterRemoval \
--file1 {input.R1} \
--file2 {input.R2} \
--combined-output \
--output1 {output.R1} \
--output2 {output.R2} \
--gzip \
--trimns \
--trimqualities \
--minquality 10 \
''')
rule SALMON_mapping:
input:
R1 = 'data/trimmedfastq/{sample}.R1.fastq.gz',
R2 = 'data/trimmedfastq/{sample}.R2.fastq.gz'
output:
directory('data/SalmonQuant/{sample}'),
'data/SalmonQuant/{sample}/quant.sf'
run:
shell('''
salmon quant \
-i data/RefGen/SALMON_INDEX \
-l A \
-1 {input.R1} \
-2 {input.R2} \
--validateMappings \
-o {output}
''')
rule make_TPM_matrix:
input:
quant_files = expand('data/SalmonQuant/{sample}/quant.sf',sample=SAMPLES)
output:
tpm_matrix = 'data/SalmonQuant/MFCohort_TPM.tsv',
fat_matrix = 'data/SalmonQuant/Fat_TPM.tsv',
muscle_matrix = 'data/SalmonQuant/Muscle_TPM.tsv'
run:
tpm = None
for n in input.quant_files:
name = n.split('/')[2]
#x = pd.read_table(f"data/SalmonQuant/{n}/quant.sf")
x = pd.read_table(n)
x = x.loc[:,['Name','TPM']]
x.rename(columns={'Name':'gene','TPM':name},inplace=True)
x.set_index('gene',inplace=True)
if tpm is None:
tpm = x
else:
tpm = tpm.join(x)
# Create the whole matrix
tpm.to_csv(output.tpm_matrix,sep='\t')
# Create the Fat & Muscle Matrix
tpm.loc[:,[x.endswith('F') for x in tpm.columns]].to_csv(output.fat_matrix,sep='\t')
tpm.loc[:,[x.endswith('M') for x in tpm.columns]].to_csv(output.muscle_matrix,sep='\t')