Skip to content

Commit 31b4d41

Browse files
authored
Merge pull request #22 from Juke34/reditools3
add reditools3
2 parents 01301fb + 7074ee4 commit 31b4d41

File tree

8 files changed

+120
-23
lines changed

8 files changed

+120
-23
lines changed

bin/stats/pluviometer.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import numpy as np
1414
from numpy.typing import NDArray
1515
from typing import TextIO, NamedTuple, Optional, Generator
16-
from site_variant_readers import RNAVariantReader, ReditoolsReader
16+
from site_variant_readers import RNAVariantReader, Reditools2Reader, Reditools3Reader
1717
import argparse
1818
from contextlib import nullcontext
1919
import sys
@@ -52,8 +52,8 @@ def parse_cli_input() -> argparse.Namespace:
5252
"--format",
5353
"-f",
5454
type=str,
55-
choices=["reditools", "jacusa2", "sapin"],
56-
default="reditools",
55+
choices=["reditools2", "reditools3", "jacusa2", "sapin"],
56+
default="reditools3",
5757
help="Sites file format",
5858
)
5959
parser.add_argument(
@@ -437,7 +437,8 @@ def update_queues(self, pos: int) -> QueueUpdates:
437437
if item.feature.location.end < pos:
438438
skipped += 1
439439
item.manager.update_progress(self.output_handle)
440-
self.progress_bar.next()
440+
if self.use_progress_bar:
441+
self.progress_bar.next()
441442
else:
442443
self.load_active_queue(item)
443444
activated += 1
@@ -562,9 +563,12 @@ def scan_and_count(self, reader: RNAVariantReader, header=True) -> None:
562563
else nullcontext(sys.stdout) as output_handle,
563564
):
564565
match args.format:
565-
case "reditools":
566-
print("Reditools format\n")
567-
sv_reader: RNAVariantReader = ReditoolsReader(sv_handle)
566+
case "reditools2":
567+
print("Reditools2 format\n")
568+
sv_reader: RNAVariantReader = Reditools2Reader(sv_handle)
569+
case "reditools3":
570+
print("Reditools3 format\n")
571+
sv_reader: RNAVariantReader = Reditools3Reader(sv_handle)
568572
case _:
569573
raise Exception(f'Unimplemented format "{args.format}"')
570574

bin/stats/site_variant_readers.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def close(self) -> None:
5858
pass
5959

6060

61-
class ReditoolsReader(RNAVariantReader):
61+
class ReditoolsXReader(RNAVariantReader):
6262
header_strings = (
6363
"Region",
6464
"Position",
@@ -112,18 +112,12 @@ def _validate_header(self) -> None:
112112
)
113113

114114
return None
115+
116+
def parse_strand(self):
117+
pass
115118

116119
def _parse_parts(self) -> SiteVariantData:
117-
strand = int(self.parts[REDITOOLS_FIELD_INDEX["Strand"]])
118-
match strand:
119-
case 0:
120-
strand = -1
121-
case 1:
122-
strand = 1
123-
case 2:
124-
strand = 0
125-
case _:
126-
raise Exception(f"Invalid strand value: {strand}")
120+
strand = self.parse_strand()
127121

128122
reference_nuc_str: str = self.parts[REDITOOLS_FIELD_INDEX["Reference"]]
129123

@@ -153,3 +147,30 @@ def close(self) -> None:
153147
"""Close the file"""
154148
self.file_handle.close()
155149

150+
151+
class Reditools2Reader(ReditoolsXReader):
152+
def parse_strand(self) -> int:
153+
strand = int(self.parts[REDITOOLS_FIELD_INDEX["Strand"]])
154+
match strand:
155+
case 0:
156+
return -1
157+
case 1:
158+
return 1
159+
case 2:
160+
return 0
161+
case _:
162+
raise Exception(f"Invalid strand value: {strand}")
163+
164+
class Reditools3Reader(ReditoolsXReader):
165+
def parse_strand(self) -> int:
166+
strand_str = self.parts[REDITOOLS_FIELD_INDEX["Strand"]]
167+
match strand_str:
168+
case "-":
169+
return -1
170+
case "+":
171+
return 1
172+
case "*":
173+
return 0
174+
case _:
175+
raise Exception(f"Invalid strand value: {strand_str}")
176+

bin/stats/tiny_pluviometer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from BCBio import GFF
33
from Bio import SeqIO, SeqRecord
44
from Bio.SeqFeature import SeqFeature
5-
from site_variant_readers import ReditoolsReader
5+
from site_variant_readers import Reditools2Reader
66
from typing import Optional
77
from utils import SiteVariantData, NUC_STR_TO_IND
88
import numpy as np
@@ -61,7 +61,7 @@ def find_features(feature_id: str, feature: SeqFeature, found: list[SeqFeature])
6161

6262
for feature in target_features:
6363
with open(args.sites) as sites_handle:
64-
reader = ReditoolsReader(sites_handle)
64+
reader = Reditools2Reader(sites_handle)
6565
variant_data: SiteVariantData = reader.read()
6666

6767
while variant_data.position <= feature.location.end:

config/softwares.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ process {
3636
withLabel: "reditools2" {
3737
container = singularity.enabled ? "${sifPath}/reditools2.sif" : "reditools2"
3838
}
39+
withLabel: "reditools3" {
40+
container = singularity.enabled ? "${sifPath}/reditools3.sif" : "reditools3"
41+
}
3942
withLabel: 'rsem' {
4043
container = 'quay.io/biocontainers/rsem:1.3.3--pl5321h0033a41_7'
4144
}

docker/reditools3/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:slim-bullseye
2+
3+
RUN apt update
4+
5+
# Install procps to provide ps, required by Nextflow
6+
RUN apt install -y procps
7+
8+
RUN pip install REDItools3
9+
10+
CMD [ "bash" ]

modules/reditools3.nf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
process reditools3 {
2+
label "reditools3"
3+
publishDir("${params.outdir}/reditools3", mode: "copy")
4+
tag "${meta.id}"
5+
6+
input:
7+
tuple(val(meta), path(bam), path(bamindex))
8+
path genome
9+
10+
output:
11+
tuple(val(meta), path("edit_table.txt"), emit: tuple_sample_serial_table)
12+
13+
script:
14+
// Set the strand orientation parameter from the library type parameter
15+
// Terms explained in https://salmon.readthedocs.io/en/latest/library_type.html
16+
if (meta.libtype in ["ISR", "SR"]) {
17+
// First-strand oriented
18+
strand_orientation = "2"
19+
} else if (meta.libtype in ["ISF", "SF"]) {
20+
// Second-strand oriented
21+
strand_orientation = "1"
22+
} else if (meta.libtype in ["IU", "U"]) {
23+
// Unstranded
24+
strand_orientation = "0"
25+
} else {
26+
// Unsupported: Pass the library type string so that it's reported in
27+
// the reditools error message
28+
strand_orientation = meta.libtype
29+
}
30+
31+
"""
32+
python -m reditools analyze ${bam} --reference ${genome} --strand ${strand_orientation} --output-file edit_table.txt
33+
"""
34+
}

rain.nf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ params.library_type = "auto" // can be 'U', 'IU', 'MU', 'OU', 'ISF', 'ISR', 'MSF
2626
params.bam_library_type = null // can be 'U', 'IU', 'MU', 'OU', 'ISF', 'ISR', 'MSF', 'MSR', 'OSF', 'OSR', 'auto' - see https://github.com/Juke34/AliNe for more information
2727

2828
// Edit counting params
29-
edit_site_tools = ["reditools2", "jacusa2", "sapin"]
30-
params.edit_site_tool = "reditools2"
29+
edit_site_tools = ["reditools2", "reditools3", "jacusa2", "sapin"]
30+
params.edit_site_tool = "reditools3"
3131
params.edit_threshold = 1
3232
params.aggregation_mode = "all"
3333

@@ -140,6 +140,7 @@ include {multiqc} from './modules/multiqc.nf'
140140
include {fasta_uncompress} from "$baseDir/modules/pigz.nf"
141141
include {samtools_index; samtools_fasta_index; samtools_sort_bam} from './modules/samtools.nf'
142142
include {reditools2} from "./modules/reditools2.nf"
143+
include {reditools3} from "./modules/reditools3.nf"
143144
include {jacusa2} from "./modules/jacusa2.nf"
144145
include {sapin} from "./modules/sapin.nf"
145146
include {normalize_gxf} from "./modules/agat.nf"
@@ -465,7 +466,12 @@ workflow rain {
465466
case "reditools2":
466467
reditools2(samtools_index.out.tuple_sample_bam_bamindex, genome, params.region)
467468
normalize_gxf(annnotation)
468-
pluviometer(reditools2.out.tuple_sample_serial_table, normalize_gxf.out.gff, "reditools")
469+
pluviometer(reditools2.out.tuple_sample_serial_table, normalize_gxf.out.gff, "reditools2")
470+
break
471+
case "reditools3":
472+
reditools3(samtools_index.out.tuple_sample_bam_bamindex, genome)
473+
normalize_gxf(annnotation)
474+
pluviometer(reditools3.out.tuple_sample_serial_table, normalize_gxf.out.gff, "reditools3")
469475
break
470476
default:
471477
exit(1, "Wrong edit site tool was passed")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Bootstrap: docker
2+
From: python:slim-bullseye
3+
4+
%post
5+
apt-get update && apt-get install -y procps
6+
pip install REDItools3
7+
8+
%environment
9+
export PATH=/usr/local/bin/:$PATH
10+
11+
%runscript
12+
exec bash "$@"
13+
14+
%labels
15+
Author eascarrunz.dev@mailfence.com
16+
Tool REDItools3
17+
18+
%help
19+
Container for REDItools3.

0 commit comments

Comments
 (0)