Skip to content

Commit

Permalink
fix`
Browse files Browse the repository at this point in the history
  • Loading branch information
nh13 committed Dec 13, 2024
1 parent d7eec19 commit 9fa39c6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ jobs:
runs-on: ubuntu-24.04
strategy:
matrix:
PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12"]
# FIXME
#PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12"]
PYTHON_VERSION: ["3.12"]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
Expand Down
5 changes: 3 additions & 2 deletions bwapy/libbwapy.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from typing import List

from pysam import AlignedSegment
Expand All @@ -14,10 +15,10 @@ TEXT_ENCODING: str

class BwaIndex:
header: AlignmentHeader
def __init__(self, prefix: str) -> None: ...
def __init__(self, prefix: str | Path) -> None: ...

class Bwa:
def __init__(self, prefix: str) -> None: ...
def __init__(self, prefix: str | Path | None = None, index: BwaIndex | None = None) -> None: ...
def align(
self, opt: BwaOptions, max_hits: int, queries: List[FastxRecord]
) -> List[AlignedSegment]: ...
17 changes: 12 additions & 5 deletions bwapy/libbwapy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ cdef class BwaIndex:
cdef bntseq_t *_bns
cdef public object header

def __init__(self, prefix: str):
self._cinit(prefix)
def __init__(self, prefix: str | Path):
self._cinit(f"{prefix}")

cdef _cinit(self, prefix):
cdef char *local_prefix
Expand Down Expand Up @@ -103,9 +103,15 @@ cdef class Bwa:
cdef BwaIndex _index
cdef unsigned char* _pacseq

def __init__(self, prefix: str):
assert Path(prefix).exists()
self._index = BwaIndex(prefix=prefix)
def __init__(self, prefix: str | Path | None = None, index: BwaIndex | None = None):
if prefix is not None:
assert Path(prefix).exists()
self._index = BwaIndex(prefix=prefix)
elif index is not None:
self._index = index
else:
raise Exception("Either prefix or index must be given")

bwase_initialize()

# initialize the packed binary reference sequence
Expand Down Expand Up @@ -236,6 +242,7 @@ cdef class Bwa:
cigar = f"{cigar}{cigar_len}{cigar_op}"
elif s.type != BWA_TYPE_NO_MATCH:
cigar = f"{s.len}M"
rec.cigarstring = cigar

# tags
attrs = dict()
Expand Down
21 changes: 18 additions & 3 deletions tests/test_bwapy.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
from pathlib import Path

import pytest
from pysam import FastxRecord

from bwapy.libbwapy import Bwa
from bwapy.libbwapy import BwaIndex
from bwapy.libbwapy import BwaOptions


def test_bwapy() -> None:
@pytest.fixture()
def ref_fasta() -> Path:
cur_dir = Path(__file__).parent
fasta = cur_dir / "data" / "e_coli_k12.fasta"
fasta: Path = cur_dir / "data" / "e_coli_k12.fasta"
return fasta


def test_bwapy_options() -> None:
BwaOptions()


def test_bwapy_index(ref_fasta: Path) -> None:
BwaIndex(prefix=ref_fasta)


def test_bwapy(ref_fasta: Path) -> None:
opt = BwaOptions()
bwa = Bwa(prefix=f"{fasta}")
bwa = Bwa(prefix=ref_fasta)
sequence = "gttacctgccgtgagtaaattaaaattttattgacttaggtcactaaatactttaaccaatataggcatagcgcacagac"
fastqs = [FastxRecord(name="test", sequence=sequence)]

Expand Down

0 comments on commit 9fa39c6

Please sign in to comment.