Skip to content

Commit

Permalink
added per sample fasta rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
farchaab committed Oct 24, 2024
1 parent f987849 commit e9a0311
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
18 changes: 0 additions & 18 deletions mess/workflow/rules/preflight/functions.smk
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,6 @@ def get_value(value, wildcards):
return df.loc[vals, value]


fa_table_cache = {}
def get_random_start(wildcards):
table = checkpoints.split_contigs.get(**wildcards).output[0]
if table not in fa_table_cache:
df = pd.read_csv(
table,
sep="\t",
index_col=["fasta","contig","n"]
)
fa_table_cache[table] = df
vals=(f"{wildcards.fasta}",f"{wildcards.contig}",int(wildcards.n))
df = fa_table_cache[table]
return df.loc[vals, "random_start"]





def get_asm_summary(wildcards):
try:
table = checkpoints.download_assemblies.get(**wildcards).output[0]
Expand Down
13 changes: 7 additions & 6 deletions mess/workflow/rules/processing/fastas.smk
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,19 @@ if ROTATE > 1:

rule rotate_contigs:
input:
fa=os.path.join(dir.out.processing, "split", "{fasta}_{contig}.fna"),
df=get_cov_table,
os.path.join(dir.out.processing, "split", "{fasta}_{contig}.fna"),
output:
os.path.join(dir.out.processing, "rotate", "{fasta}_{contig}_{n}.fna"),
os.path.join(
dir.out.processing, "rotate", "{sample}", "{fasta}_{contig}_{n}.fna"
),
params:
get_random_start,
lambda wildcards: get_value("random_start", wildcards),
log:
os.path.join(
dir.out.logs,
"seqkit",
"restart",
"{sample}",
"{fasta}_{contig}_{n}.log",
),
resources:
Expand All @@ -88,7 +90,6 @@ if ROTATE > 1:
containers.seqkit
shell:
"""
seqkit restart -i {params} {input.fa} | \
seqkit seq -i | \
seqkit restart -i {params} {input} | \\
seqkit replace -p .+ -r {wildcards.contig}_{wildcards.n} > {output}
"""
4 changes: 3 additions & 1 deletion mess/workflow/rules/simulate/long_reads.smk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ prefix = os.path.join(dir.out.long, "{sample}", "{fasta}", "{contig}")
fasta = os.path.join(dir.out.processing, "split", "{fasta}_{contig}.fna")
if ROTATE > 1:
prefix = os.path.join(dir.out.long, "{sample}", "{fasta}", "{contig}_{n}")
fasta = os.path.join(dir.out.processing, "rotate", "{fasta}_{contig}_{n}.fna")
fasta = os.path.join(
dir.out.processing, "rotate", "{sample}", "{fasta}_{contig}_{n}.fna"
)
id_prefix = os.path.basename(prefix)

if PASSES > 1:
Expand Down
6 changes: 4 additions & 2 deletions mess/workflow/rules/simulate/short_reads.smk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ if not PAIRED:

fasta = os.path.join(dir.out.processing, "split", "{fasta}_{contig}.fna")
if ROTATE > 1:
fasta = os.path.join(dir.out.processing, "rotate", "{fasta}_{contig}_{n}.fna")
fasta = os.path.join(
dir.out.processing, "rotate", "{sample}", "{fasta}_{contig}_{n}.fna"
)


rule art_illumina:
Expand All @@ -56,7 +58,7 @@ rule art_illumina:
prefix=fq_prefix,
log:
os.path.join(dir.out.logs, "art", "{sample}", "{fasta}", "{contig}.log")
if ROTATE == 1
if not ROTATE == 1
else os.path.join(
dir.out.logs, "art", "{sample}", "{fasta}", "{contig}_{n}.log"
),
Expand Down

0 comments on commit e9a0311

Please sign in to comment.