Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ 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
exclude: ^docs/
args: [
-f, LICENSE,
]
types_or: [ python ]
types_or: [ python, cython, c ]
36 changes: 20 additions & 16 deletions src/designer_dna/_oligos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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[<unsigned char> sequence[j]]
sequence[end] = table[<unsigned char> sequence[end]]
sequence[j] = table[<ssize_t> sequence[j]]
sequence[end] = table[<ssize_t> sequence[end]]

if length % 2:
sequence[idx] = table[<unsigned char> sequence[idx]]
sequence[idx] = table[<ssize_t> 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)
Expand All @@ -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(
Expand All @@ -148,14 +152,14 @@ cdef void c_reverse_complement(

while end_ptr > sequence:
sequence[0], end_ptr[0] = (
table[<unsigned char> end_ptr[0]],
table[<unsigned char> sequence[0]]
table[<ssize_t> end_ptr[0]],
table[<ssize_t> sequence[0]]
)
end_ptr -= 1
sequence += 1

if length % 2:
sequence[0] = table[<unsigned char> sequence[0]]
sequence[0] = table[<ssize_t> sequence[0]]


cpdef str reverse_complement(str sequence, bint dna = True):
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 = <Py_ssize_t> n
Py_ssize_t v = view.size // t
Py_ssize_t i, j, k
Expand Down
58 changes: 30 additions & 28 deletions src/designer_dna/headers/oligos.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading