From aa5c9ba9d1081be9aa8f92fe3fd03c7dc1be8fb7 Mon Sep 17 00:00:00 2001 From: Chang Ye Date: Tue, 2 Jul 2024 00:06:32 -0500 Subject: [PATCH] release 0.0.49 --- cutseq/run.py | 27 +++++++++++++++++++++++---- pyproject.toml | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cutseq/run.py b/cutseq/run.py index 8d30826..dca6ff7 100644 --- a/cutseq/run.py +++ b/cutseq/run.py @@ -23,6 +23,7 @@ SuffixAdapter, ) from cutadapt.files import InputPaths, OutputFiles +from cutadapt.info import ModificationInfo from cutadapt.modifiers import ( AdapterCutter, PairedEndRenamer, @@ -79,6 +80,24 @@ def test(self, read, info): return False +class ConditionalCutter(SingleEndModifier): + def __init__(self, length: int): + self.length = length + + def __repr__(self): + return f"ConditionalCutter(length={self.length})" + + def __call__(self, read, info: ModificationInfo): + if not info.matches: + return read + if self.length > 0: + info.cut_prefix = read.sequence[: self.length] + return read[self.length :] + elif self.length < 0: + info.cut_suffix = read.sequence[self.length :] + return read[: self.length] + + class ReverseComplementConverter(SingleEndModifier): def __init__(self): self.rcd = False @@ -548,7 +567,7 @@ def pipeline_paired( UnconditionalCutter(barcode.umi5.len), UnconditionalCutter(-barcode.umi5.len) if settings.read_through - else None, + else ConditionalCutter(-barcode.umi5.len), ), ) if barcode.umi3.len > 0: @@ -556,7 +575,7 @@ def pipeline_paired( ( UnconditionalCutter(-barcode.umi3.len) if settings.read_through - else None, + else ConditionalCutter(-barcode.umi3.len), UnconditionalCutter(barcode.umi3.len), ) ) @@ -572,7 +591,7 @@ def pipeline_paired( UnconditionalCutter(barcode.mask5.len), UnconditionalCutter(-barcode.mask5.len) if settings.read_through - else None, + else ConditionalCutter(-barcode.mask5.len), ) ) if barcode.mask3.len > 0: @@ -580,7 +599,7 @@ def pipeline_paired( ( UnconditionalCutter(-barcode.mask3.len) if settings.read_through - else None, + else ConditionalCutter(-barcode.mask3.len), UnconditionalCutter(barcode.mask3.len), ) ) diff --git a/pyproject.toml b/pyproject.toml index e520a0b..0e930b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cutseq" -version = "0.0.48" +version = "0.0.49" description = "Automatically cut adapter / barcode / UMI from NGS data" authors = ["Ye Chang "] license = "MIT"