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,160 @@
|
|
|
1
|
+
##########################################################################
|
|
2
|
+
##################### WORKFLOW VARIABLES AND CODE ########################
|
|
3
|
+
##########################################################################
|
|
4
|
+
|
|
5
|
+
from snakemake.exceptions import WorkflowError
|
|
6
|
+
from snakemake.utils import min_version
|
|
7
|
+
from snakemake.utils import validate
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from collections import Counter, defaultdict
|
|
10
|
+
from operator import itemgetter
|
|
11
|
+
from functools import partial
|
|
12
|
+
import yaml
|
|
13
|
+
import json
|
|
14
|
+
import sys
|
|
15
|
+
import os
|
|
16
|
+
import re
|
|
17
|
+
import numpy as np
|
|
18
|
+
import pandas as pd
|
|
19
|
+
import polars as pl
|
|
20
|
+
from more_itertools import last, one
|
|
21
|
+
from Bio import SeqIO
|
|
22
|
+
from Bio.SeqRecord import SeqRecord
|
|
23
|
+
from Bio import Entrez
|
|
24
|
+
|
|
25
|
+
sys.path.append((Path(workflow.basedir).parent / "src").as_posix())
|
|
26
|
+
|
|
27
|
+
from multi_seq_probes import group_probes, NoGrouping
|
|
28
|
+
|
|
29
|
+
SCHEMAS_DIR = Path(workflow.basedir) / "schemas"
|
|
30
|
+
|
|
31
|
+
# Read inputs
|
|
32
|
+
probes_path = Path(lookup("args/probes", within=config))
|
|
33
|
+
outdir = Path(lookup("args/output", within=config))
|
|
34
|
+
path_samples = Path(lookup("args/input", within=config))
|
|
35
|
+
probe_pattern = lookup("args/probe_pattern", within=config)
|
|
36
|
+
multi_probes = lookup("args/multi_probes", within=config)
|
|
37
|
+
max_threads = lookup("args/threads", within=config)
|
|
38
|
+
interseeds_use = lookup("args/interseeds", within=config)
|
|
39
|
+
reasm = lookup("args/reasm", within=config)
|
|
40
|
+
use_ploidy = lookup("args/use_ploidy", within=config)
|
|
41
|
+
|
|
42
|
+
blosum62 = Path(workflow.source_path(lookup("blosum62", within=config)))
|
|
43
|
+
|
|
44
|
+
# Check reference chloroplasts use for Filtering step
|
|
45
|
+
cp_refs_map = Path(workflow.source_path(lookup("cp_refs_map", within=config)))
|
|
46
|
+
use_ref_cps = lookup("args/use_ref_cps", within=config)
|
|
47
|
+
ref_cps = lookup("args/ref_cps", within=config)
|
|
48
|
+
|
|
49
|
+
if use_ref_cps:
|
|
50
|
+
kp2seqid = pl.read_csv(cp_refs_map, glob=False)
|
|
51
|
+
kps = set(ref_cps.split(","))
|
|
52
|
+
if len(extra := (set(kps) - set(kp2seqid["1kp"]))) > 0:
|
|
53
|
+
raise ValueError(
|
|
54
|
+
f"""Error: cps_seqids db does not contain: {extra}. Make sure to use only valid entries(1kp).
|
|
55
|
+
Use --no-ref-cps if you do not want to download any cp for filtering"""
|
|
56
|
+
)
|
|
57
|
+
seqids = kp2seqid.filter(pl.col("1kp").is_in(kps))["seqid"].to_list()
|
|
58
|
+
|
|
59
|
+
# Regex Patterns
|
|
60
|
+
SEED_PAT = lookup("regex_patterns/seed_pat", within=config)
|
|
61
|
+
SAUTE_PRE_FIX_PAT = lookup("regex_patterns/saute_pre_fix_pat", within=config)
|
|
62
|
+
SAUTE_POST_FIX_PAT = lookup("regex_patterns/saute_post_fix_pat", within=config)
|
|
63
|
+
COMP_FINAL_PAT = lookup("regex_patterns/comp_final_pat", within=config)
|
|
64
|
+
TARGET_COLLAPSE_PAT = lookup("regex_patterns/saute_target_pat", within=config)
|
|
65
|
+
|
|
66
|
+
## Read Workflow parameters:
|
|
67
|
+
pipeline = lookup("pipeline", within=config)
|
|
68
|
+
scf_ext = lookup("scaffolds_extension", within=pipeline)
|
|
69
|
+
seeds_filt_params = lookup("homolog_filtering/seeds", within=pipeline)
|
|
70
|
+
homologs_filt_params = lookup("homolog_filtering/homologs", within=pipeline)
|
|
71
|
+
reg_sep = lookup("region_separation", within=pipeline)
|
|
72
|
+
|
|
73
|
+
# Validate probes
|
|
74
|
+
probes = SeqIO.to_dict(SeqIO.parse(probes_path, "fasta"))
|
|
75
|
+
probes_list = list(probes.keys())
|
|
76
|
+
PROBES = pd.DataFrame({"probe_name": probes_list})
|
|
77
|
+
validate(PROBES, schema=(SCHEMAS_DIR / "probes.yaml").resolve())
|
|
78
|
+
|
|
79
|
+
# Validate Sample table
|
|
80
|
+
with open(SCHEMAS_DIR / "sample_table.yaml") as file:
|
|
81
|
+
sample_schema = yaml.safe_load(file)
|
|
82
|
+
|
|
83
|
+
# Build dtypes from the sample schema
|
|
84
|
+
dtype_map = {"string": str, "integer": "Int64", "number": float}
|
|
85
|
+
dtypes = {
|
|
86
|
+
col: dtype_map.get(spec.get("type", "string"), str)
|
|
87
|
+
for col, spec in sample_schema["properties"].items()
|
|
88
|
+
}
|
|
89
|
+
sample_table = pd.read_csv(path_samples, sep="\t", dtype=dtypes)
|
|
90
|
+
validate(sample_table, schema=(SCHEMAS_DIR / "sample_table.yaml").resolve())
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# Make paths absolute if they are not already, using the base of the sample table
|
|
94
|
+
def adjust_rel_path(path: str, base: Path) -> Path:
|
|
95
|
+
"""If path is not an absolute, make it absolute using base"""
|
|
96
|
+
return Path(path) if Path(path).is_absolute() else base / path
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
sample_table["path_forward"] = sample_table["path_forward"].apply(
|
|
100
|
+
partial(adjust_rel_path, base=path_samples.parent)
|
|
101
|
+
)
|
|
102
|
+
sample_table["path_reverse"] = sample_table["path_reverse"].apply(
|
|
103
|
+
partial(adjust_rel_path, base=path_samples.parent)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
has_ploidy = sample_table.eval("ploidy > 0").any()
|
|
107
|
+
if use_ploidy and not has_ploidy:
|
|
108
|
+
raise WorkflowError(
|
|
109
|
+
"Ploidy information is expected but no useful ploidy information was found in the sample table."
|
|
110
|
+
)
|
|
111
|
+
elif not use_ploidy and has_ploidy:
|
|
112
|
+
sample_table["ploidy"] = 0
|
|
113
|
+
|
|
114
|
+
sample_list = sample_table["sample"].to_list()
|
|
115
|
+
|
|
116
|
+
# Compute number of homologs expected according to ploidy information
|
|
117
|
+
copies_per_ploidy = lookup("saute/expected_homologs_per_ploidy", within=pipeline)
|
|
118
|
+
homologs = np.where(
|
|
119
|
+
sample_table["ploidy"] % 2 == 0,
|
|
120
|
+
sample_table["ploidy"] * copies_per_ploidy / 2,
|
|
121
|
+
(sample_table["ploidy"] + 1) * copies_per_ploidy / 2,
|
|
122
|
+
).astype(int)
|
|
123
|
+
homologs[homologs == 0] = lookup("saute/max_variants", within=pipeline)
|
|
124
|
+
sample_table["homologs"] = homologs
|
|
125
|
+
|
|
126
|
+
# Check grouping of the probe set
|
|
127
|
+
# Multi-seq probe set
|
|
128
|
+
if multi_probes:
|
|
129
|
+
try:
|
|
130
|
+
probe_hier = {
|
|
131
|
+
probe: [rec.id for rec in recs]
|
|
132
|
+
for probe, recs in group_probes(
|
|
133
|
+
list(probes.values()), probe_pattern
|
|
134
|
+
).items()
|
|
135
|
+
}
|
|
136
|
+
probes_list = list(probe_hier.keys())
|
|
137
|
+
except NoGrouping as e:
|
|
138
|
+
e.add_note(
|
|
139
|
+
"Either this is a single-probe set or the pattern is not appropiate for multi-probe"
|
|
140
|
+
)
|
|
141
|
+
raise
|
|
142
|
+
else:
|
|
143
|
+
pat = re.compile(probe_pattern)
|
|
144
|
+
try:
|
|
145
|
+
probes_list = [pat.search(probe)[1] for probe in probes]
|
|
146
|
+
except TypeError:
|
|
147
|
+
names = [probe.id for probe in probes if not pat.search(probe.id)]
|
|
148
|
+
raise Exception(
|
|
149
|
+
f"Error: pattern {probe_pattern} does not match all probes:\n{"\n".join(names)}"
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
pathvars:
|
|
153
|
+
rundir=outdir.as_posix(),
|
|
154
|
+
workdir="<rundir>/workflow",
|
|
155
|
+
logs="<rundir>/logs",
|
|
156
|
+
|
|
157
|
+
wildcard_constraints:
|
|
158
|
+
sample=r"\w+",
|
|
159
|
+
probe=r"\w+",
|
|
160
|
+
cluster=r"\d+",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
$schema: "https://json-schema.org/draft/2020-12/schema"
|
|
2
|
+
description: Probe naming schema definition
|
|
3
|
+
type: object
|
|
4
|
+
properties:
|
|
5
|
+
probe_name:
|
|
6
|
+
type: string
|
|
7
|
+
format: uri
|
|
8
|
+
pattern: "(^[A-Za-z0-9_]+$)"
|
|
9
|
+
description: Probe name (AlphaNumeric; the only special character allowed is '_')
|
|
10
|
+
|
|
11
|
+
required:
|
|
12
|
+
- probe_name
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
$schema: "https://json-schema.org/draft/2020-12/schema"
|
|
2
|
+
description: Sample table schema definition
|
|
3
|
+
type: object
|
|
4
|
+
properties:
|
|
5
|
+
sample:
|
|
6
|
+
type: string
|
|
7
|
+
format: uri
|
|
8
|
+
pattern: "(^[A-Za-z0-9_-]+$)"
|
|
9
|
+
description: sample identifier.
|
|
10
|
+
path_forward:
|
|
11
|
+
type: string
|
|
12
|
+
format: uri
|
|
13
|
+
description: path to fastq(compressed) file containing forward reads.
|
|
14
|
+
pattern: ".*(.fastq.gz|.fq.gz|.fastq|.fq)$"
|
|
15
|
+
path_reverse:
|
|
16
|
+
type: string
|
|
17
|
+
format: uri
|
|
18
|
+
description: path to fastq(compressed) file containing forward reads.
|
|
19
|
+
pattern: ".*(.fastq.gz|.fq.gz|.fastq|.fq)$"
|
|
20
|
+
ploidy:
|
|
21
|
+
type: integer
|
|
22
|
+
default: 0
|
|
23
|
+
minimum: 0
|
|
24
|
+
description: ploidy level of the sample (optional).
|
|
25
|
+
|
|
26
|
+
required:
|
|
27
|
+
- sample
|
|
28
|
+
- path_forward
|
|
29
|
+
- path_reverse
|