From c28aca9c0d71de531cce105ea568da89ae1f4dad Mon Sep 17 00:00:00 2001 From: Spill-Tea Date: Fri, 27 Jun 2025 16:24:52 -0700 Subject: [PATCH 1/3] chore(_oligos): Directly import from commons header. Use size_t coercion in complement methods to acces table. --- src/designer_dna/_oligos.pyx | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/designer_dna/_oligos.pyx b/src/designer_dna/_oligos.pyx index 4d0d412..13c0786 100644 --- a/src/designer_dna/_oligos.pyx +++ b/src/designer_dna/_oligos.pyx @@ -37,7 +37,11 @@ cdef extern from "Python.h": bytes PyUnicode_AsUTF8String(object) Py_ssize_t PyBytes_GET_SIZE(object) -cimport common +from common cimport ( + StringView, + str_to_view, + to_str +) cdef extern from "oligos.h": const unsigned char DNA[0x100] @@ -92,14 +96,14 @@ cdef void c_complement(char* sequence, Py_ssize_t length, unsigned char[] table) for j in range(idx): end = (length - 1) - j - sequence[j] = table[ sequence[j]] - sequence[end] = table[ sequence[end]] + sequence[j] = table[ sequence[j]] + sequence[end] = table[ sequence[end]] if length % 2: - sequence[idx] = table[ sequence[idx]] + sequence[idx] = table[ sequence[idx]] -cdef void v_complement(common.StringView view, bint dna): +cdef void v_complement(StringView view, bint dna): """Handle complement on StringView directly, in place.""" if dna: c_complement(view.ptr, view.size, DNA) @@ -124,10 +128,10 @@ cpdef str complement(str sequence, bint dna = True): complement("ATGC", False) == "UACG" """ - cdef common.StringView view = common.str_to_view(sequence) + cdef StringView view = str_to_view(sequence) v_complement(view, dna) - return common.to_str(view) + return to_str(view) cdef void c_reverse_complement( @@ -148,14 +152,14 @@ cdef void c_reverse_complement( while end_ptr > sequence: sequence[0], end_ptr[0] = ( - table[ end_ptr[0]], - table[ sequence[0]] + table[ end_ptr[0]], + table[ sequence[0]] ) end_ptr -= 1 sequence += 1 if length % 2: - sequence[0] = table[ sequence[0]] + sequence[0] = table[ sequence[0]] cpdef str reverse_complement(str sequence, bint dna = True): @@ -175,14 +179,14 @@ cpdef str reverse_complement(str sequence, bint dna = True): reverse_complement("ATGC", False) == "GCAU" """ - cdef common.StringView view = common.str_to_view(sequence) + cdef StringView view = str_to_view(sequence) if dna: c_reverse_complement(view.ptr, view.size, DNA) else: c_reverse_complement(view.ptr, view.size, RNA) - return common.to_str(view) + return to_str(view) cdef void _center( @@ -224,8 +228,8 @@ cpdef str palindrome(str sequence, bint dna = True): """ cdef: - common.StringView seq = common.str_to_view(sequence) - common.StringView com = common.str_to_view(sequence) + StringView seq = str_to_view(sequence) + StringView com = str_to_view(sequence) Py_ssize_t i, left, right, current, length = 0, start = 0, end = 0 v_complement(com, dna) @@ -263,7 +267,7 @@ cpdef int stretch(str sequence): """ cdef: - common.StringView view = common.str_to_view(sequence) + StringView view = str_to_view(sequence) Py_ssize_t j int longest = 0, current = 0 char prev = view.ptr[0] @@ -327,7 +331,7 @@ cpdef int nrepeats(str sequence, int n): """ cdef: - common.StringView view = common.str_to_view(sequence) + StringView view = str_to_view(sequence) Py_ssize_t t = n Py_ssize_t v = view.size // t Py_ssize_t i, j, k From 503db150563e77f19d2e0db3a38b6cd4147006ff Mon Sep 17 00:00:00 2001 From: Spill-Tea Date: Fri, 27 Jun 2025 17:21:45 -0700 Subject: [PATCH 2/3] chore(pre-commit): Upgrade addlicense pre-commit hook to latest version to support cython. --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b8723e5..084909c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: requirements-txt-fixer - repo: https://github.com/Spill-Tea/addlicense-pre-commit - rev: v1.1.2 + rev: v1.1.3 hooks: - id: addlicense language: golang @@ -22,4 +22,4 @@ repos: args: [ -f, LICENSE, ] - types_or: [ python ] + types_or: [ python, cython, c ] From 6a81cb885c9923adfe7ebdaf384308d0ee44480f Mon Sep 17 00:00:00 2001 From: Spill-Tea Date: Fri, 27 Jun 2025 17:22:07 -0700 Subject: [PATCH 3/3] chore(headers.oligos): Update format of license displayed in file. --- src/designer_dna/headers/oligos.h | 58 ++++++++++++++++--------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/designer_dna/headers/oligos.h b/src/designer_dna/headers/oligos.h index 89527e2..0072c4d 100644 --- a/src/designer_dna/headers/oligos.h +++ b/src/designer_dna/headers/oligos.h @@ -1,31 +1,33 @@ -// BSD 3-Clause License - -// Copyright (c) 2025, Spill-Tea - -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: - -// 1. Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. - -// 2. Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// 3. Neither the name of the copyright holder nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. - -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* + * BSD 3-Clause License + * + * Copyright (c) 2025, Spill-Tea + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ #ifndef __LDPY_LDHELPERS_H #define __LDPY_LDHELPERS_H