Skip to content

Commit 95320bc

Browse files
authored
fix: use updated chainfile crate to resolve liftover issues (#43)
1 parent fb9b1c9 commit 95320bc

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

rust/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ name = "agct"
88
crate-type = ["cdylib"]
99

1010
[dependencies]
11-
chainfile = "0.2.1"
11+
chainfile = "0.3.0"
1212
directories = "5.0"
13+
omics = { version = "0.2.0", features = ["coordinate"] }
1314

1415
[dependencies.pyo3]
1516
version = "0.20.2"

rust/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Provide Rust-based chainfile wrapping classes.
2-
use chain::core::{Coordinate, Interval, Strand};
32
use chainfile as chain;
3+
use omics::coordinate::{interbase::Coordinate, interval::interbase::Interval, Strand};
44
use pyo3::create_exception;
55
use pyo3::exceptions::{PyException, PyFileNotFoundError, PyValueError};
66
use pyo3::prelude::*;
@@ -40,7 +40,7 @@ impl Converter {
4040
}
4141

4242
/// Perform liftover
43-
pub fn lift(&self, chrom: &str, pos: usize, strand: &str) -> PyResult<Vec<Vec<String>>> {
43+
pub fn lift(&self, chrom: &str, pos: u64, strand: &str) -> PyResult<Vec<Vec<String>>> {
4444
let parsed_strand = if strand == "+" {
4545
Strand::Positive
4646
} else if strand == "-" {
@@ -52,8 +52,8 @@ impl Converter {
5252
)));
5353
};
5454
// safe to unwrap coordinates because `pos` is always an int
55-
let start = Coordinate::try_new(chrom, pos, parsed_strand.clone()).unwrap();
56-
let end = Coordinate::try_new(chrom, pos + 1, parsed_strand.clone()).unwrap();
55+
let start = Coordinate::new(chrom, parsed_strand.clone(), pos);
56+
let end = Coordinate::new(chrom, parsed_strand.clone(), pos + 1);
5757

5858
let Ok(interval) = Interval::try_new(start, end) else {
5959
return Err(ChainfileError::new_err(format!(
@@ -63,7 +63,7 @@ impl Converter {
6363
pos + 1
6464
)));
6565
};
66-
if let Some(liftover_result) = self.machine.liftover(&interval) {
66+
if let Some(liftover_result) = self.machine.liftover(interval.clone()) {
6767
Ok(liftover_result
6868
.iter()
6969
.map(|r| {

tests/data/ucsc-chainfile/chainfile_hg19_to_hg38_.chain

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
chain 24611930 chr1 249250621 + 206072707 206332221 chr1 248956422 - 42687778 42947276 254
2+
33374 0 21
3+
6406 0 1
4+
95162 1 0
5+
39481 2 0
6+
4456 0 1
7+
25212 55 16
8+
10374 0 1
9+
1898 0 2
10+
43093
11+
112
chain 14633688187 chr7 159138663 + 10000 159128663 chr7 159345973 + 10000 159335973 7
213
222484 50000 10034
314
183862 17 0

tests/test_liftover.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def test_hg19_to_hg38():
2323
assert len(result) == 1
2424
assert result[0] == ("chr7", 140753336, Strand.POSITIVE)
2525

26+
result = converter.convert_coordinate("chr1", 206072707)
27+
assert len(result) == 1
28+
assert result[0] == ("chr1", 206268644, Strand.NEGATIVE)
29+
2630
# coordinate exceeds bounds
2731
result = converter.convert_coordinate("chr7", 14040053136)
2832
assert result == []

0 commit comments

Comments
 (0)