Skip to content

Commit a6cc499

Browse files
committed
update
1 parent 200e05d commit a6cc499

File tree

5 files changed

+27
-34
lines changed

5 files changed

+27
-34
lines changed

.github/workflows/wheel.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252
with:
5353
python-version: "3.12"
5454

55+
- run: pip install setuptools
56+
5557
- name: Build sdist
5658
run: python setup.py sdist
5759

src/fasta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ PyObject *pyfastx_fasta_new(PyTypeObject *type, PyObject *args, PyObject *kwargs
121121
PYFASTX_SQLITE_CALL(
122122
sqlite3_prepare_v2(obj->index->index_db, "SELECT * FROM seq WHERE chrom=? LIMIT 1;", -1, &obj->index->seq_stmt, NULL);
123123
sqlite3_prepare_v2(obj->index->index_db, "SELECT * FROM seq WHERE ID=? LIMIT 1;", -1, &obj->index->uid_stmt, NULL);
124+
sqlite3_prepare_v2(obj->index->index_db, "SELECT * FROM comp WHERE ID=? LIMIT 1;", -1, &obj->index->comp_stmt, NULL);
124125
);
125126
}
126127

@@ -1060,7 +1061,6 @@ PyObject *pyfastx_fasta_gc_skew(pyfastx_Fasta *self, void* closure) {
10601061
}
10611062

10621063
PyObject *pyfastx_fasta_composition(pyfastx_Fasta *self, void* closure) {
1063-
int i;
10641064
int l;
10651065
int ret;
10661066
const char *sql;

src/index.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pyfastx_Index* pyfastx_init_index(PyObject *obj, PyObject* file_obj, PyObject* i
8484
index->iter_stmt = NULL;
8585
index->uid_stmt = NULL;
8686
index->seq_stmt = NULL;
87+
index->comp_stmt = NULL;
8788

8889
//cache sequence
8990
//index->cache_name = {0,0,0};
@@ -445,6 +446,10 @@ void pyfastx_index_free(pyfastx_Index *self){
445446
PYFASTX_SQLITE_CALL(sqlite3_finalize(self->seq_stmt));
446447
}
447448

449+
if (self->comp_stmt) {
450+
PYFASTX_SQLITE_CALL(sqlite3_finalize(self->comp_stmt));
451+
}
452+
448453
if (self->index_db) {
449454
PYFASTX_SQLITE_CALL(sqlite3_close(self->index_db));
450455
self->index_db = NULL;

src/index.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ typedef struct {
6565
sqlite3_stmt *iter_stmt;
6666
sqlite3_stmt *uid_stmt;
6767
sqlite3_stmt *seq_stmt;
68+
sqlite3_stmt *comp_stmt;
6869

6970
//parent fasta object
7071
PyObject *fasta;

src/sequence.c

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -564,25 +564,20 @@ PyObject *pyfastx_sequence_gc_content(pyfastx_Sequence *self, void* closure) {
564564
int ret;
565565
char *seq;
566566

567-
sqlite3_stmt *stmt;
568-
569567
Py_ssize_t i, n;
570568
Py_ssize_t a = 0, c = 0, g = 0, t = 0;
571-
572-
const char *sql = "SELECT * FROM comp WHERE seqid=?";
573569

574570
PYFASTX_SQLITE_CALL(
575-
sqlite3_prepare_v2(self->index->index_db, sql, -1, &stmt, NULL);
576-
sqlite3_bind_int64(stmt, 1, self->id);
577-
ret = sqlite3_step(stmt);
571+
sqlite3_bind_int64(self->index->comp_stmt, 1, self->id);
572+
ret = sqlite3_step(self->index->comp_stmt);
578573
);
579574

580575
if (ret == SQLITE_ROW && self->start == 1 && self->end == self->seq_len) {
581576
while (ret == SQLITE_ROW) {
582577
PYFASTX_SQLITE_CALL(
583-
l = sqlite3_column_int(stmt, 2);
584-
n = sqlite3_column_int64(stmt, 3);
585-
ret = sqlite3_step(stmt);
578+
l = sqlite3_column_int(self->index->comp_stmt, 2);
579+
n = sqlite3_column_int64(self->index->comp_stmt, 3);
580+
ret = sqlite3_step(self->index->comp_stmt);
586581
);
587582

588583
switch (l) {
@@ -635,7 +630,7 @@ PyObject *pyfastx_sequence_gc_content(pyfastx_Sequence *self, void* closure) {
635630
}
636631
}
637632

638-
PYFASTX_SQLITE_CALL(sqlite3_finalize(stmt));
633+
PYFASTX_SQLITE_CALL(sqlite3_reset(self->index->comp_stmt));
639634

640635
return Py_BuildValue("f", (float)(g+c)/(a+c+g+t)*100);
641636
}
@@ -644,25 +639,21 @@ PyObject *pyfastx_sequence_gc_skew(pyfastx_Sequence *self, void* closure) {
644639
int l;
645640
int ret;
646641
char *seq;
647-
sqlite3_stmt *stmt;
648642

649643
Py_ssize_t i, n;
650644
Py_ssize_t c = 0, g = 0;
651-
652-
const char *sql = "SELECT * FROM comp WHERE seqid=?";
653645

654646
PYFASTX_SQLITE_CALL(
655-
sqlite3_prepare_v2(self->index->index_db, sql, -1, &stmt, NULL);
656-
sqlite3_bind_int64(stmt, 1, self->id);
657-
ret = sqlite3_step(stmt);
647+
sqlite3_bind_int64(self->index->comp_stmt, 1, self->id);
648+
ret = sqlite3_step(self->index->comp_stmt);
658649
);
659650

660651
if (ret == SQLITE_ROW && self->start == 1 && self->end == self->seq_len) {
661652
while (ret == SQLITE_ROW) {
662653
PYFASTX_SQLITE_CALL(
663-
l = sqlite3_column_int(stmt, 2);
664-
n = sqlite3_column_int64(stmt, 3);
665-
ret = sqlite3_step(stmt);
654+
l = sqlite3_column_int(self->index->comp_stmt, 2);
655+
n = sqlite3_column_int64(self->index->comp_stmt, 3);
656+
ret = sqlite3_step(self->index->comp_stmt);
666657
);
667658

668659
switch (l) {
@@ -695,7 +686,7 @@ PyObject *pyfastx_sequence_gc_skew(pyfastx_Sequence *self, void* closure) {
695686
}
696687
}
697688

698-
PYFASTX_SQLITE_CALL(sqlite3_finalize(stmt));
689+
PYFASTX_SQLITE_CALL(sqlite3_reset(self->index->comp_stmt));
699690

700691
return Py_BuildValue("f", (float)(g-c)/(g+c));
701692
}
@@ -705,8 +696,6 @@ PyObject *pyfastx_sequence_composition(pyfastx_Sequence *self, void* closure) {
705696
int l;
706697
int ret;
707698
char *seq;
708-
709-
sqlite3_stmt *stmt;
710699

711700
Py_ssize_t n;
712701
Py_ssize_t seq_comp[128] = {0};
@@ -715,22 +704,19 @@ PyObject *pyfastx_sequence_composition(pyfastx_Sequence *self, void* closure) {
715704
PyObject *b;
716705
PyObject *c;
717706

718-
const char *sql = "SELECT * FROM comp WHERE ID=?";
719-
720707
PYFASTX_SQLITE_CALL(
721-
sqlite3_prepare_v2(self->index->index_db, sql, -1, &stmt, NULL);
722-
sqlite3_bind_int64(stmt, 1, self->id);
723-
ret = sqlite3_step(stmt);
708+
sqlite3_bind_int64(self->index->stmt, 1, self->id);
709+
ret = sqlite3_step(self->index->stmt);
724710
);
725711

726712
d = PyDict_New();
727713

728714
if (ret == SQLITE_ROW && self->start == 1 && self->end == self->seq_len) {
729715
while (ret == SQLITE_ROW) {
730716
PYFASTX_SQLITE_CALL(
731-
l = sqlite3_column_int(stmt, 2);
732-
n = sqlite3_column_int64(stmt, 3);
733-
ret = sqlite3_step(stmt);
717+
l = sqlite3_column_int(self->index->stmt, 2);
718+
n = sqlite3_column_int64(self->index->stmt, 3);
719+
ret = sqlite3_step(self->index->stmt);
734720
);
735721

736722
if (n > 0 && l >= 32 && l < 127) {
@@ -761,8 +747,7 @@ PyObject *pyfastx_sequence_composition(pyfastx_Sequence *self, void* closure) {
761747
}
762748
}
763749

764-
PYFASTX_SQLITE_CALL(sqlite3_finalize(stmt));
765-
750+
PYFASTX_SQLITE_CALL(sqlite3_reset(self->index->stmt));
766751
return d;
767752
}
768753

0 commit comments

Comments
 (0)