NextPyper 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nextpyper/__init__.py +0 -0
- nextpyper/__main__.py +429 -0
- nextpyper/config/config.yaml +80 -0
- nextpyper/config/rich_config.yaml +54 -0
- nextpyper/config/system_config.yaml +10 -0
- nextpyper/data/blosum62.csv +32 -0
- nextpyper/data/cps_seqids.csv +674 -0
- nextpyper/data/mock/mock_args.yaml +17 -0
- nextpyper/data/mock/probes.fasta +56 -0
- nextpyper/data/mock/reads/sample1_R1.fastq +20 -0
- nextpyper/data/mock/reads/sample1_R2.fastq +20 -0
- nextpyper/data/mock/reads/sample2_R1.fastq +20 -0
- nextpyper/data/mock/reads/sample2_R2.fastq +20 -0
- nextpyper/data/mock/reads/sample3_R1.fastq +20 -0
- nextpyper/data/mock/reads/sample3_R2.fastq +20 -0
- nextpyper/data/mock/sample.tsv +4 -0
- nextpyper/nextpyper.CITATION +9 -0
- nextpyper/nextpyper.LICENSE +19 -0
- nextpyper/nextpyper.VERSION +1 -0
- nextpyper/src/divergence_estimation.py +131 -0
- nextpyper/src/diversity.py +93 -0
- nextpyper/src/exon_discovery.py +294 -0
- nextpyper/src/exon_intron.py +197 -0
- nextpyper/src/fix_headers.py +107 -0
- nextpyper/src/gfa2fasta.py +71 -0
- nextpyper/src/gfa_graph.py +1245 -0
- nextpyper/src/gff_parser.py +344 -0
- nextpyper/src/graph_utils.py +201 -0
- nextpyper/src/homolog_filtering.py +411 -0
- nextpyper/src/miniprot.py +1008 -0
- nextpyper/src/multi_seq_probes.py +292 -0
- nextpyper/src/run_orfipy.py +493 -0
- nextpyper/src/sample_table.py +63 -0
- nextpyper/src/seeds_collection.py +387 -0
- nextpyper/src/summarize_results.py +507 -0
- nextpyper/src/union_find.py +65 -0
- nextpyper/src/var_asm_parser.py +229 -0
- nextpyper/test/.gitkeep +0 -0
- nextpyper/workflow/Snakefile +62 -0
- nextpyper/workflow/envs/alignment.yaml +7 -0
- nextpyper/workflow/envs/assembly.yaml +8 -0
- nextpyper/workflow/envs/clustering.yaml +9 -0
- nextpyper/workflow/envs/matching.yaml +8 -0
- nextpyper/workflow/envs/preprocessing.yaml +11 -0
- nextpyper/workflow/envs/saute.yaml +7 -0
- nextpyper/workflow/envs/translating.yaml +8 -0
- nextpyper/workflow/rules/0_preprocessing/0.1_reads.smk +90 -0
- nextpyper/workflow/rules/0_preprocessing/0.2_probes.smk +16 -0
- nextpyper/workflow/rules/1_seeds_assembly/1.1_assembly_spades.smk +48 -0
- nextpyper/workflow/rules/1_seeds_assembly/1.2_seeds_extension.smk +90 -0
- nextpyper/workflow/rules/1_seeds_assembly/1.3_seeds_filtering.smk +64 -0
- nextpyper/workflow/rules/1_seeds_assembly/1.4_seeds_clustering.smk +73 -0
- nextpyper/workflow/rules/2_homologs_assembly/2.1_saute_assembly.smk +228 -0
- nextpyper/workflow/rules/3_homolog_prospection/3.1_allele_collapsing.smk +23 -0
- nextpyper/workflow/rules/3_homolog_prospection/3.2_homologs_filtering.smk +76 -0
- nextpyper/workflow/rules/3_homolog_prospection/3.3_region_separation.smk +189 -0
- nextpyper/workflow/rules/common.smk +160 -0
- nextpyper/workflow/schemas/probes.yaml +12 -0
- nextpyper/workflow/schemas/sample_table.yaml +29 -0
- nextpyper/workflow/scripts/bench_busco.py +572 -0
- nextpyper/workflow/scripts/categories_bench.sh +92 -0
- nextpyper/workflow/scripts/end_recs_parser.py +146 -0
- nextpyper/workflow/scripts/tribble_stats.py +131 -0
- nextpyper-0.1.0.dist-info/METADATA +231 -0
- nextpyper-0.1.0.dist-info/RECORD +69 -0
- nextpyper-0.1.0.dist-info/WHEEL +5 -0
- nextpyper-0.1.0.dist-info/entry_points.txt +3 -0
- nextpyper-0.1.0.dist-info/licenses/nextpyper/nextpyper.LICENSE +19 -0
- nextpyper-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
pathvars:
|
|
2
|
+
stage="1_assembly/13_clustering",
|
|
3
|
+
results="<workdir>/<stage>",
|
|
4
|
+
inter="1_assembly/12_filtering/122_filt_seeds/1221_filtered_scfs"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
rule distribute_seeds:
|
|
8
|
+
input:
|
|
9
|
+
expand("<workdir>/<inter>/{sample}.fasta", sample=sample_list),
|
|
10
|
+
output:
|
|
11
|
+
expand("<results>/130_sample_merged_input/{probe}.fasta", probe=probes_list),
|
|
12
|
+
log:
|
|
13
|
+
"<logs>/<stage>/seed_distribution.log",
|
|
14
|
+
params:
|
|
15
|
+
pattern=lambda wildcards: r"-(?P<probe>.*?)_EDGE_",
|
|
16
|
+
probes=probes_list,
|
|
17
|
+
mode="scfs",
|
|
18
|
+
script:
|
|
19
|
+
"../../../src/multi_seq_probes.py"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
rule vsearch_clustering:
|
|
23
|
+
input:
|
|
24
|
+
"<results>/130_sample_merged_input/{probe}.fasta"
|
|
25
|
+
output:
|
|
26
|
+
"<results>/131_cluster_tables/{probe}.tsv",
|
|
27
|
+
log:
|
|
28
|
+
"<logs>/<stage>/131_vsearch/{probe}.log",
|
|
29
|
+
conda:
|
|
30
|
+
"../../envs/clustering.yaml"
|
|
31
|
+
threads: 4
|
|
32
|
+
params:
|
|
33
|
+
"--id 0.95 --iddef 3 --minseqlength 5 --qmask none --strand both",
|
|
34
|
+
shell:
|
|
35
|
+
"""
|
|
36
|
+
vsearch --threads {threads} {params} \
|
|
37
|
+
--cluster_fast {input} \
|
|
38
|
+
--uc {output} \
|
|
39
|
+
2> {log}
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
rule seeds_collection:
|
|
44
|
+
input:
|
|
45
|
+
probes=probes_path.resolve(),
|
|
46
|
+
cluster_tables=expand("<results>/131_cluster_tables/{probe}.tsv", probe=probes_list),
|
|
47
|
+
samples=expand("<workdir>/<inter>/{sample}.fasta", sample=sample_list),
|
|
48
|
+
spades_graphs=expand(
|
|
49
|
+
"<workdir>/1_assembly/10_raw_assembly/100_spades/{sample}/assembly_graph_with_scaffolds.gfa",
|
|
50
|
+
sample=sample_list,
|
|
51
|
+
),
|
|
52
|
+
covs=expand(
|
|
53
|
+
"<workdir>/1_assembly/12_filtering/121_coverage/{sample}.metabat",
|
|
54
|
+
sample=sample_list,
|
|
55
|
+
),
|
|
56
|
+
read_stats=expand(
|
|
57
|
+
"<logs>/0_preprocessing/01_trimming_fastp/{sample}.json", sample=sample_list
|
|
58
|
+
),
|
|
59
|
+
output:
|
|
60
|
+
seeds=expand("<workdir>/2_saute/21_seeds/{sample}.fasta", sample=sample_list),
|
|
61
|
+
saute_params=expand("<workdir>/2_saute/20_params_and_stats/200_kmer_params/{sample}.json", sample=sample_list),
|
|
62
|
+
log:
|
|
63
|
+
"<logs>/2_saute/seeds_collection.log",
|
|
64
|
+
params:
|
|
65
|
+
pattern=probe_pattern,
|
|
66
|
+
is_multi=multi_probes,
|
|
67
|
+
interseeds_use=interseeds_use,
|
|
68
|
+
min_sister_freq=lookup("seeds/min_sister_sample_freq", within=pipeline),
|
|
69
|
+
cov_by_mapping=lookup("seeds/cov_by_mapping", within=pipeline),
|
|
70
|
+
heuristic_params=lookup("saute/heuristic", within=pipeline),
|
|
71
|
+
sister_samples_dir=outdir / "workflow/2_saute/20_params_and_stats/201_sister_samples",
|
|
72
|
+
script:
|
|
73
|
+
"../../../src/seeds_collection.py"
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
pathvars:
|
|
2
|
+
stage="2_saute",
|
|
3
|
+
results="<workdir>/<stage>",
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def read_kmer_params(kmer_params: Path) -> tuple[int, int]:
|
|
7
|
+
kmer_params = json.loads(kmer_params.read_text())
|
|
8
|
+
k1 = int(kmer_params["k1"])
|
|
9
|
+
k2 = int(kmer_params["k2"])
|
|
10
|
+
return k1, k2
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def saute_kmer(wildcards, input):
|
|
14
|
+
"""Set the Kmer sizes for saute assembly"""
|
|
15
|
+
|
|
16
|
+
k1, k2 = read_kmer_params(Path(input.kmer_params))
|
|
17
|
+
return f"--kmer {k1} --secondary_kmer {k2}"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def saute_kmer_expl(wildcards, input):
|
|
21
|
+
"""Set the Kmer sizes for saute reassembly rescaling the primary kmer"""
|
|
22
|
+
|
|
23
|
+
k1rescale = lookup("saute/reassembly/k1_rescaling", within=pipeline)
|
|
24
|
+
k1, k2 = read_kmer_params(Path(input.kmer_params))
|
|
25
|
+
|
|
26
|
+
## For reassembly, scale the primary kmer
|
|
27
|
+
if k1rescale:
|
|
28
|
+
k1 = int(k1 * k1rescale)
|
|
29
|
+
k1 = k1 - 1 if k1 % 2 == 0 else k1
|
|
30
|
+
|
|
31
|
+
return f"--kmer {k1} --secondary_kmer {k2}"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
rule saute_assembly:
|
|
35
|
+
input:
|
|
36
|
+
reads1="<workdir>/0_preprocessing/02_cleaning/{sample}_R1.fastq.gz",
|
|
37
|
+
reads2="<workdir>/0_preprocessing/02_cleaning/{sample}_R2.fastq.gz",
|
|
38
|
+
seeds="<results>/21_seeds/{sample}.fasta",
|
|
39
|
+
kmer_params="<results>/20_params_and_stats/200_kmer_params/{sample}.json",
|
|
40
|
+
output:
|
|
41
|
+
# all_vars=outdir / "saute/target_assembly/{sample}/all_vars.fasta",
|
|
42
|
+
target_vars="<results>/22_homologs_assembly/{sample}/target_vars.fasta",
|
|
43
|
+
graph="<results>/22_homologs_assembly/{sample}/graph.gfa",
|
|
44
|
+
params:
|
|
45
|
+
extra="--extend_ends --remove_homopolymer_indels ",
|
|
46
|
+
kmer_threshold=lookup(
|
|
47
|
+
"saute/assembly/secondary_kmer_threshold", within=pipeline
|
|
48
|
+
),
|
|
49
|
+
max_var=lookup(query="sample=='{sample}'", cols="homologs", within=sample_table),
|
|
50
|
+
target_cov=lookup("saute/assembly/target_cov", within=pipeline),
|
|
51
|
+
kmers=saute_kmer,
|
|
52
|
+
log:
|
|
53
|
+
"<logs>/<stage>/22_homologs_assembly_saute/{sample}.log",
|
|
54
|
+
threads: 8
|
|
55
|
+
conda:
|
|
56
|
+
"../../envs/saute.yaml"
|
|
57
|
+
shell:
|
|
58
|
+
"""saute --cores {threads} {params.extra} {params.kmers} \
|
|
59
|
+
--target_coverage {params.target_cov} \
|
|
60
|
+
--max_variants {params.max_var} \
|
|
61
|
+
--secondary_kmer_threshold {params.kmer_threshold} \
|
|
62
|
+
--reads {input.reads1},{input.reads2} \
|
|
63
|
+
--targets {input.seeds} \
|
|
64
|
+
--gfa {output.graph} \
|
|
65
|
+
--selected_variants {output.target_vars} > {log} 2>&1
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
checkpoint split_saute_assembly:
|
|
70
|
+
input:
|
|
71
|
+
target_vars="<results>/22_homologs_assembly/{sample}/target_vars.fasta",
|
|
72
|
+
output:
|
|
73
|
+
normal="<results>/22_homologs_assembly/{sample}/normal_vars.fasta",
|
|
74
|
+
tribbles="<results>/22_homologs_assembly/{sample}/tribble_vars.fasta",
|
|
75
|
+
params:
|
|
76
|
+
mode="split",
|
|
77
|
+
pattern=TARGET_COLLAPSE_PAT,
|
|
78
|
+
max_vars=lookup(
|
|
79
|
+
query="sample=='{sample}'", cols="homologs", within=sample_table
|
|
80
|
+
),
|
|
81
|
+
log:
|
|
82
|
+
"<logs>/<stage>/23_tribbles_reassembly/230_split/{sample}.log",
|
|
83
|
+
script:
|
|
84
|
+
"../../../src/var_asm_parser.py"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
rule collect_tribble_reads:
|
|
88
|
+
input:
|
|
89
|
+
scfs="<results>/22_homologs_assembly/{sample}/tribble_vars.fasta",
|
|
90
|
+
reads1="<workdir>/0_preprocessing/02_cleaning/{sample}_R1.fastq.gz",
|
|
91
|
+
reads2="<workdir>/0_preprocessing/02_cleaning/{sample}_R2.fastq.gz",
|
|
92
|
+
output:
|
|
93
|
+
reads1="<results>/23_tribbles_reassembly/{sample}/trib_reads_R1.fastq.gz",
|
|
94
|
+
reads2="<results>/23_tribbles_reassembly/{sample}/trib_reads_R2.fastq.gz",
|
|
95
|
+
log:
|
|
96
|
+
"<logs>/<stage>/23_tribbles_reassembly/232_read_collection/{sample}.log",
|
|
97
|
+
threads: 4
|
|
98
|
+
conda:
|
|
99
|
+
"../../envs/preprocessing.yaml"
|
|
100
|
+
shell:
|
|
101
|
+
"""minimap2 -t {threads} -ax sr {input.scfs} {input.reads1} {input.reads2} 2> {log} | \
|
|
102
|
+
samtools view -@ {threads} -uhf 2 2>> {log} | samtools sort -n -u -@ {threads} 2>> {log} | \
|
|
103
|
+
samtools fastq -1 {output.reads1} -2 {output.reads2} - 2>> {log}
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
rule collect_tribble_seeds:
|
|
108
|
+
input:
|
|
109
|
+
seeds="<results>/21_seeds/{sample}.fasta",
|
|
110
|
+
tribbles="<results>/22_homologs_assembly/{sample}/tribble_vars.fasta",
|
|
111
|
+
output:
|
|
112
|
+
seeds="<results>/23_tribbles_reassembly/{sample}/tribbles_seeds.fasta",
|
|
113
|
+
seqids=temp("<results>/23_tribbles_reassembly/{sample}/seqids.txt"),
|
|
114
|
+
log:
|
|
115
|
+
"<logs>/<stage>/23_tribbles_reassembly/231_seed_collection/{sample}.log",
|
|
116
|
+
conda:
|
|
117
|
+
"../../envs/preprocessing.yaml"
|
|
118
|
+
shell:
|
|
119
|
+
"""awk '/>/{{match($0,/-(.*?)_EDGE/, m); print "-"m[1]"_"}}' {input.tribbles} | sort | uniq > {output.seqids}
|
|
120
|
+
seqkit grep -rf {output.seqids} {input.seeds} > {output.seeds}
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
checkpoint tribble_reassembly:
|
|
125
|
+
input:
|
|
126
|
+
reads1="<results>/23_tribbles_reassembly/{sample}/trib_reads_R1.fastq.gz",
|
|
127
|
+
reads2="<results>/23_tribbles_reassembly/{sample}/trib_reads_R2.fastq.gz",
|
|
128
|
+
seeds="<results>/23_tribbles_reassembly/{sample}/tribbles_seeds.fasta",
|
|
129
|
+
kmer_params="<results>/20_params_and_stats/200_kmer_params/{sample}.json",
|
|
130
|
+
# kmer_params=outdir / "logs/saute/kmer_params/{sample}.json",
|
|
131
|
+
output:
|
|
132
|
+
# all_vars="<results>/23_tribbles_reassembly/{sample}/all_vars.fasta",
|
|
133
|
+
target_vars="<results>/23_tribbles_reassembly/{sample}/target_vars.fasta",
|
|
134
|
+
graph="<results>/23_tribbles_reassembly/{sample}/graph.gfa",
|
|
135
|
+
params:
|
|
136
|
+
extra="--extend_ends --remove_homopolymer_indels ",
|
|
137
|
+
kmer_threshold=lookup(
|
|
138
|
+
"saute/reassembly/secondary_kmer_threshold", within=pipeline
|
|
139
|
+
),
|
|
140
|
+
max_var=lookup(query="sample=='{sample}'", cols="homologs", within=sample_table),
|
|
141
|
+
target_cov=lookup("saute/reassembly/target_cov", within=pipeline),
|
|
142
|
+
k1rescale=lookup("saute/reassembly/k1_rescaling", within=pipeline),
|
|
143
|
+
kmers=saute_kmer_expl,
|
|
144
|
+
log:
|
|
145
|
+
"<logs>/<stage>/23_tribbles_reassembly/233_saute/{sample}.log",
|
|
146
|
+
threads: 8
|
|
147
|
+
conda:
|
|
148
|
+
"../../envs/saute.yaml"
|
|
149
|
+
shell:
|
|
150
|
+
"""saute --cores {threads} {params.extra} {params.kmers} \
|
|
151
|
+
--target_coverage {params.target_cov} \
|
|
152
|
+
--max_variants {params.max_var} \
|
|
153
|
+
--secondary_kmer_threshold {params.kmer_threshold} \
|
|
154
|
+
--reads {input.reads1},{input.reads2} \
|
|
155
|
+
--targets {input.seeds} \
|
|
156
|
+
--gfa {output.graph} \
|
|
157
|
+
--selected_variants {output.target_vars} > {log} 2>&1 || \
|
|
158
|
+
touch {output.graph} {output.target_vars}
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
rule normal_vars_check:
|
|
163
|
+
input:
|
|
164
|
+
"<results>/22_homologs_assembly/{sample}/tribble_vars.fasta",
|
|
165
|
+
output:
|
|
166
|
+
touch("<results>/23_tribbles_reassembly/{sample}/all_normal.chkp"),
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
# All probes are normal, no need to do reassembly.
|
|
170
|
+
def all_normal(wildcards):
|
|
171
|
+
out_trib = checkpoints.split_saute_assembly.get(sample=wildcards.sample).output.tribbles
|
|
172
|
+
return Path(out_trib).stat().st_size == 0
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
# Reassembly yield nothing, so take back the original results.
|
|
176
|
+
def empty_tribble_asm(wildcards):
|
|
177
|
+
out_trib = checkpoints.tribble_reassembly.get(
|
|
178
|
+
sample=wildcards.sample
|
|
179
|
+
).output.target_vars
|
|
180
|
+
return Path(out_trib).stat().st_size == 0
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
rule collect_saute_assemblies:
|
|
184
|
+
input:
|
|
185
|
+
normal="<results>/22_homologs_assembly/{sample}/normal_vars.fasta",
|
|
186
|
+
expl=branch(
|
|
187
|
+
all_normal,
|
|
188
|
+
then="<results>/23_tribbles_reassembly/{sample}/all_normal.chkp",
|
|
189
|
+
otherwise=branch(
|
|
190
|
+
not reasm or empty_tribble_asm,
|
|
191
|
+
then="<results>/22_homologs_assembly/{sample}/tribble_vars.fasta",
|
|
192
|
+
otherwise="<results>/23_tribbles_reassembly/{sample}/target_vars.fasta",
|
|
193
|
+
),
|
|
194
|
+
),
|
|
195
|
+
output:
|
|
196
|
+
"<results>/24_postprocessing/240_merging/{sample}.fasta",
|
|
197
|
+
pathvars:
|
|
198
|
+
results="<workdir>/2_saute",
|
|
199
|
+
shell:
|
|
200
|
+
"cat {input.normal} {input.expl} > {output}"
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
rule cap_tribble_variants:
|
|
204
|
+
input:
|
|
205
|
+
"<results>/24_postprocessing/240_merging/{sample}.fasta",
|
|
206
|
+
output:
|
|
207
|
+
tribble_stats="<results>/24_postprocessing/241_capping/2410_tribbles/{sample}.tsv",
|
|
208
|
+
normal="<results>/24_postprocessing/241_capping/2411_sequences/{sample}.fasta",
|
|
209
|
+
params:
|
|
210
|
+
mode="cap",
|
|
211
|
+
max_var=lookup(query="sample=='{sample}'", cols="homologs", within=sample_table),
|
|
212
|
+
pattern=TARGET_COLLAPSE_PAT,
|
|
213
|
+
log:
|
|
214
|
+
"<logs>/<stage>/24_postprocessing/241_capping/{sample}.log",
|
|
215
|
+
script:
|
|
216
|
+
"../../../src/var_asm_parser.py"
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
rule fix_homologs_header:
|
|
220
|
+
input:
|
|
221
|
+
"<results>/24_postprocessing/241_capping/2411_sequences/{sample}.fasta",
|
|
222
|
+
output:
|
|
223
|
+
"<results>/24_postprocessing/242_reheading/{sample}.fasta",
|
|
224
|
+
params:
|
|
225
|
+
pattern=SAUTE_PRE_FIX_PAT,
|
|
226
|
+
sample=lambda wildcards: wildcards.sample,
|
|
227
|
+
script:
|
|
228
|
+
"../../../src/fix_headers.py"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
pathvars:
|
|
2
|
+
stage="3_homolog_prospection/30_allele_collapsing",
|
|
3
|
+
results="<workdir>/<stage>",
|
|
4
|
+
|
|
5
|
+
rule allele_clustering:
|
|
6
|
+
input:
|
|
7
|
+
"<workdir>/2_saute/24_postprocessing/242_reheading/{sample}.fasta",
|
|
8
|
+
output:
|
|
9
|
+
"<results>/{sample}.fasta",
|
|
10
|
+
log:
|
|
11
|
+
"<logs>/<stage>/{sample}.log",
|
|
12
|
+
params:
|
|
13
|
+
"--id 0.99 --minseqlength 5 --qmask none",
|
|
14
|
+
threads: 4
|
|
15
|
+
conda:
|
|
16
|
+
"../../envs/clustering.yaml"
|
|
17
|
+
shell:
|
|
18
|
+
"""
|
|
19
|
+
vsearch --threads {threads} {params} \
|
|
20
|
+
--cluster_fast {input} \
|
|
21
|
+
--centroids {output} \
|
|
22
|
+
2> {log}
|
|
23
|
+
"""
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
pathvars:
|
|
2
|
+
stage="3_homolog_prospection/31_homologs_filtering",
|
|
3
|
+
results="<workdir>/<stage>",
|
|
4
|
+
inter="3_homolog_prospection/30_allele_collapsing",
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
rule gather_matching_probes:
|
|
8
|
+
input:
|
|
9
|
+
probes="<workdir>/0_preprocessing/longest_cds.fasta",
|
|
10
|
+
tables=expand(
|
|
11
|
+
"<workdir>/1_assembly/12_filtering/122_filt_seeds/1220_summary_tables/{sample}.tsv",
|
|
12
|
+
sample=sample_list,
|
|
13
|
+
),
|
|
14
|
+
output:
|
|
15
|
+
"<workdir>/3_homolog_prospection/matching_probes.fasta",
|
|
16
|
+
shadow:
|
|
17
|
+
"shallow"
|
|
18
|
+
conda:
|
|
19
|
+
"../../envs/preprocessing.yaml"
|
|
20
|
+
shell:
|
|
21
|
+
"""
|
|
22
|
+
cat {input.tables} | cut -f 2 | sort | uniq > probe_ids.txt
|
|
23
|
+
seqkit grep -f probe_ids.txt {input.probes} > {output}
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
use rule make_diamond_probes_db as make_diamond_matching_probes_db with:
|
|
28
|
+
input:
|
|
29
|
+
"<workdir>/3_homolog_prospection/matching_probes.fasta",
|
|
30
|
+
output:
|
|
31
|
+
"<results>/matching_probes.dmnd",
|
|
32
|
+
log:
|
|
33
|
+
"<logs>/<stage>/make_probes_db.log",
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
use rule raw_assembly_to_probes_matching as homologs_to_probes_matching with:
|
|
37
|
+
input:
|
|
38
|
+
probes="<results>/matching_probes.dmnd",
|
|
39
|
+
query="<workdir>/<inter>/{sample}.fasta",
|
|
40
|
+
output:
|
|
41
|
+
"<results>/310_matching_tables/{sample}.tsv",
|
|
42
|
+
log:
|
|
43
|
+
"<logs>/<stage>/310_matching_diamond/{sample}.log",
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
use rule seeds_coverage as homologs_coverage with:
|
|
47
|
+
input:
|
|
48
|
+
scfs="<workdir>/<inter>/{sample}.fasta",
|
|
49
|
+
clean1="<workdir>/0_preprocessing/02_cleaning/{sample}_R1.fastq.gz",
|
|
50
|
+
clean2="<workdir>/0_preprocessing/02_cleaning/{sample}_R2.fastq.gz",
|
|
51
|
+
output:
|
|
52
|
+
counts="<results>/311_coverage/{sample}.counts",
|
|
53
|
+
metabat="<results>/311_coverage/{sample}.metabat",
|
|
54
|
+
log:
|
|
55
|
+
"<logs>/<stage>/311_coverage/{sample}.log",
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
use rule seeds_filtering as homologs_filtering with:
|
|
59
|
+
input:
|
|
60
|
+
scfs="<workdir>/<inter>/{sample}.fasta",
|
|
61
|
+
hits="<results>/310_matching_tables/{sample}.tsv",
|
|
62
|
+
covs="<results>/311_coverage/{sample}.metabat",
|
|
63
|
+
output:
|
|
64
|
+
metrics="<results>/312_filt_homologs/3120_summary_tables/{sample}.tsv",
|
|
65
|
+
scfs="<results>/312_filt_homologs/3121_sequences/{sample}.fasta",
|
|
66
|
+
log:
|
|
67
|
+
"<logs>/<stage>/312_filt_homologs/{sample}.log",
|
|
68
|
+
params:
|
|
69
|
+
min_cov=lookup("scf_min_cov", within=homologs_filt_params),
|
|
70
|
+
min_idt=lookup("scf_min_idt", within=homologs_filt_params),
|
|
71
|
+
max_gc=lookup("max_gc", within=homologs_filt_params),
|
|
72
|
+
min_gc=lookup("min_gc", within=homologs_filt_params),
|
|
73
|
+
cov_threshold=lookup("cov_threshold", within=homologs_filt_params),
|
|
74
|
+
cov_dynamic_filt=lookup("cov_dynamic_filt", within=homologs_filt_params),
|
|
75
|
+
tag_scfs=lambda wildcards: False,
|
|
76
|
+
qpat=lambda wildcards: SAUTE_POST_FIX_PAT,
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
pathvars:
|
|
2
|
+
stage="3_homolog_prospection/32_region_separation",
|
|
3
|
+
results="<workdir>/<stage>",
|
|
4
|
+
inter="3_homolog_prospection/31_homologs_filtering/312_filt_homologs",
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
rule estimate_divergence:
|
|
8
|
+
input:
|
|
9
|
+
expand("<workdir>/<inter>/3120_summary_tables/{sample}.tsv", sample=sample_list),
|
|
10
|
+
output:
|
|
11
|
+
"<results>/divergence_thresholds.json",
|
|
12
|
+
log:
|
|
13
|
+
"<logs>/<stage>/divergence_estimates.tsv",
|
|
14
|
+
params:
|
|
15
|
+
min_idt=lookup("scf_min_idt", within=homologs_filt_params),
|
|
16
|
+
min_cov=lookup("divergence_estimation/min_cov", within=pipeline),
|
|
17
|
+
flattening_prop=lookup("divergence_estimation/flatenning_prop", within=pipeline),
|
|
18
|
+
script:
|
|
19
|
+
"../../../src/divergence_estimation.py"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
rule estimate_intron_ceiling:
|
|
23
|
+
input:
|
|
24
|
+
expand(
|
|
25
|
+
"<logs>/0_preprocessing/01_trimming_fastp/{sample}.json",
|
|
26
|
+
sample=sample_list,
|
|
27
|
+
),
|
|
28
|
+
output:
|
|
29
|
+
"<results>/intron_ceilings.json",
|
|
30
|
+
run:
|
|
31
|
+
max_intron = {
|
|
32
|
+
file.stem: read_insert_size(file) * 2 for file in map(Path, input)
|
|
33
|
+
}
|
|
34
|
+
Path(output[0]).write_text(json.dumps(max_intron, indent=4))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
rule gather_tribbles:
|
|
38
|
+
input:
|
|
39
|
+
expand(
|
|
40
|
+
"<workdir>/2_saute/24_postprocessing/241_capping/2410_tribbles/{sample}.tsv",
|
|
41
|
+
sample=sample_list,
|
|
42
|
+
),
|
|
43
|
+
output:
|
|
44
|
+
"<results>/tribbles_summary.tsv",
|
|
45
|
+
log:
|
|
46
|
+
"<logs>/<stage>/tribbles_summary.log",
|
|
47
|
+
run:
|
|
48
|
+
dfs = [
|
|
49
|
+
pl.read_csv(sample, separator="\t").with_columns(
|
|
50
|
+
sample=pl.lit(sample.stem)
|
|
51
|
+
)
|
|
52
|
+
for sample in map(Path, input)
|
|
53
|
+
]
|
|
54
|
+
pl.concat(df for df in dfs if not df.is_empty()).write_csv(
|
|
55
|
+
output[0], separator="\t"
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
use rule distribute_seeds as per_probe_scaffold_grouping with:
|
|
60
|
+
input:
|
|
61
|
+
expand("<workdir>/<inter>/3121_sequences/{sample}.fasta", sample=sample_list),
|
|
62
|
+
output:
|
|
63
|
+
expand("<results>/320_inputs/3201_scfs/{probe}.fasta", probe=probes_list),
|
|
64
|
+
log:
|
|
65
|
+
"<logs>/<stage>/scfs_grouping.log",
|
|
66
|
+
params:
|
|
67
|
+
pattern=lambda wildcards: SAUTE_POST_FIX_PAT,
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
use rule distribute_seeds as split_matching_probes with:
|
|
71
|
+
input:
|
|
72
|
+
probes="<workdir>/3_homolog_prospection/matching_probes.fasta",
|
|
73
|
+
tables=expand(
|
|
74
|
+
"<workdir>/<inter>/3120_summary_tables/{sample}.tsv", sample=sample_list
|
|
75
|
+
),
|
|
76
|
+
output:
|
|
77
|
+
expand("<results>/320_inputs/3200_probes/{probe}.fasta", probe=probes_list),
|
|
78
|
+
log:
|
|
79
|
+
"<logs>/<stage>/probe_grouping.log",
|
|
80
|
+
params:
|
|
81
|
+
pattern=lambda wildcards: probe_pattern,
|
|
82
|
+
mode="multi_probes" if multi_probes else "single_probes",
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
rule separate_cds_by_regions:
|
|
86
|
+
input:
|
|
87
|
+
probes="<results>/320_inputs/3200_probes/{probe}.fasta",
|
|
88
|
+
scfs="<results>/320_inputs/3201_scfs/{probe}.fasta",
|
|
89
|
+
div_map="<results>/divergence_thresholds.json",
|
|
90
|
+
max_intron_map="<results>/intron_ceilings.json",
|
|
91
|
+
tribbles="<results>/tribbles_summary.tsv",
|
|
92
|
+
output:
|
|
93
|
+
directory("<results>/321_output/3211_scfs/{probe}"),
|
|
94
|
+
log:
|
|
95
|
+
"<logs>/<stage>/321_miniprot/{probe}.log",
|
|
96
|
+
conda:
|
|
97
|
+
"../../envs/clustering.yaml"
|
|
98
|
+
threads: 2
|
|
99
|
+
params:
|
|
100
|
+
force_global_idt=lookup("enforce_global_idt_threshold", within=reg_sep),
|
|
101
|
+
min_global_identity=lookup("min_global_identity", within=reg_sep),
|
|
102
|
+
min_fragment_cov=lookup("min_fragment_cov", within=reg_sep),
|
|
103
|
+
min_exonic_length=lookup("min_exonic_length", within=reg_sep),
|
|
104
|
+
max_intron_length=lookup("max_intron_length", within=reg_sep),
|
|
105
|
+
substitution_matrix=blosum62,
|
|
106
|
+
# pattern=COMP_FINAL_PAT,
|
|
107
|
+
probes_outdir=outdir
|
|
108
|
+
/ "workflow/3_homolog_prospection/32_region_separation/321_output/3210_probes",
|
|
109
|
+
script:
|
|
110
|
+
"../../../src/miniprot.py"
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
rule align_regions:
|
|
114
|
+
input:
|
|
115
|
+
"<results>/321_output/3211_scfs/{probe}",
|
|
116
|
+
output:
|
|
117
|
+
directory("<workdir>/3_homolog_prospection/33_alns/{probe}"),
|
|
118
|
+
log:
|
|
119
|
+
"<logs>/3_homolog_prospection/33_alns/{probe}.log",
|
|
120
|
+
conda:
|
|
121
|
+
"../../envs/alignment.yaml"
|
|
122
|
+
threads: 2
|
|
123
|
+
params:
|
|
124
|
+
lookup("mafft_params", within=pipeline),
|
|
125
|
+
shell:
|
|
126
|
+
"""
|
|
127
|
+
rm -f {log}
|
|
128
|
+
mkdir -p {output}
|
|
129
|
+
|
|
130
|
+
for file in $(find {input} -name "*.fasta"); do
|
|
131
|
+
name=$(basename $file)
|
|
132
|
+
nseqs=$(grep -c "^>" $file)
|
|
133
|
+
|
|
134
|
+
if [ "$nseqs" -gt 1 ]; then
|
|
135
|
+
mafft --thread {threads} {params} $file >{output}/$name 2>>{log}
|
|
136
|
+
else
|
|
137
|
+
cp $file {output}/$name
|
|
138
|
+
fi
|
|
139
|
+
done
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
for kind in ("exons", "genetigs", "supercontigs"):
|
|
144
|
+
|
|
145
|
+
rule:
|
|
146
|
+
name:
|
|
147
|
+
f"collect_{kind}"
|
|
148
|
+
input:
|
|
149
|
+
scfs=expand("<results>/321_output/3211_scfs/{probe}", probe=probes_list),
|
|
150
|
+
output:
|
|
151
|
+
expand(
|
|
152
|
+
f"<workdir>/3_homolog_prospection/34_collating_homologs/340_per_sample/{kind}/{{sample}}.fasta",
|
|
153
|
+
sample=sample_list,
|
|
154
|
+
),
|
|
155
|
+
log:
|
|
156
|
+
f"<logs>/3_homolog_prospection/34_collating_homologs/340_grouping/{kind}.log",
|
|
157
|
+
params:
|
|
158
|
+
pattern=lambda wildcards: COMP_FINAL_PAT,
|
|
159
|
+
probes=probes_list,
|
|
160
|
+
mode=kind,
|
|
161
|
+
script:
|
|
162
|
+
"../../../src/multi_seq_probes.py"
|
|
163
|
+
|
|
164
|
+
rule:
|
|
165
|
+
name:
|
|
166
|
+
f"{kind}_coverage"
|
|
167
|
+
input:
|
|
168
|
+
scfs=f"<workdir>/3_homolog_prospection/34_collating_homologs/340_per_sample/{kind}/{{sample}}.fasta",
|
|
169
|
+
clean1="<workdir>/0_preprocessing/02_cleaning/{sample}_R1.fastq.gz",
|
|
170
|
+
clean2="<workdir>/0_preprocessing/02_cleaning/{sample}_R2.fastq.gz",
|
|
171
|
+
output:
|
|
172
|
+
counts=f"<workdir>/3_homolog_prospection/34_collating_homologs/341_coverage/{kind}/{{sample}}.counts",
|
|
173
|
+
metabat=f"<workdir>/3_homolog_prospection/34_collating_homologs/341_coverage/{kind}/{{sample}}.metabat",
|
|
174
|
+
log:
|
|
175
|
+
f"<logs>/3_homolog_prospection/34_collating_homologs/341_coverage/{kind}/{{sample}}.log",
|
|
176
|
+
shadow:
|
|
177
|
+
"shallow"
|
|
178
|
+
conda:
|
|
179
|
+
"../../envs/preprocessing.yaml"
|
|
180
|
+
threads: 4
|
|
181
|
+
params:
|
|
182
|
+
extra="--proper-pairs-only --exclude-supplementary",
|
|
183
|
+
shell:
|
|
184
|
+
"""
|
|
185
|
+
minimap2 -t {threads} -ax sr {input.scfs} {input.clean1} {input.clean2} 2>{log} \
|
|
186
|
+
| samtools sort -u -@ {threads} >tmp_{wildcards.sample}.bam 2>>{log}
|
|
187
|
+
coverm contig -m count {params.extra} -b tmp_{wildcards.sample}.bam >{output.counts} 2>>{log}
|
|
188
|
+
coverm contig -m metabat {params.extra} -b tmp_{wildcards.sample}.bam >{output.metabat} 2>>{log}
|
|
189
|
+
"""
|