Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Jan 18, 2024
2 parents 45f94ce + 6ce37da commit 08937cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
hooks:
- id: ruff-format
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
entry: bash -c 'cd rust'
entry: bash -c 'cd rust && cargo fmt'
args: ['--verbose', '--']
5 changes: 2 additions & 3 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ pub struct ChainLifter {
impl ChainLifter {
#[new]
pub fn new(chainfile_path: &str) -> PyResult<ChainLifter> {
let Ok(chainfile_file) = File::open(&chainfile_path) else {
let Ok(chainfile_file) = File::open(chainfile_path) else {
return Err(PyFileNotFoundError::new_err(format!(
"Unable to open chainfile located at \"{}\"",
&chainfile_path
)));
};
let data = BufReader::new(chainfile_file);
let reader = chain::Reader::new(data);
let Ok(machine) = chain::liftover::machine::Builder::default().try_build_from(reader)
else {
let Ok(machine) = chain::liftover::machine::Builder.try_build_from(reader) else {
return Err(ChainfileError::new_err(format!(
"Encountered error while reading chainfile at \"{}\"",
&chainfile_path
Expand Down
16 changes: 8 additions & 8 deletions tests/test_liftover.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,45 @@ def test_hg19_to_hg38():
ch = ChainLifter(Genome.HG19, Genome.HG38)

result = ch.convert_coordinate("chr7", 140439611)
assert result is not None
assert result
assert len(result) == 1
assert result[0] == ["chr7", "140739811", "+"]

result = ch.convert_coordinate("chr7", 140439746)
assert result is not None
assert result
assert len(result) == 1
assert result[0] == ["chr7", "140739946", "+"]

result = ch.convert_coordinate("chr7", 140439703)
assert result is not None
assert result
assert len(result) == 1
assert result[0] == ["chr7", "140739903", "+"]

result = ch.convert_coordinate("chr7", 140453136)
assert result is not None
assert result
assert len(result) == 1
assert result[0] == ["chr7", "140753336", "+"]

# coordinate exceeds bounds
result = ch.convert_coordinate("chr7", 14040053136)
assert result is None
assert result == []


def test_hg38_to_hg19():
"""Test hg38 to hg19 lifter."""
ch = ChainLifter(Genome.HG38, Genome.HG19)

result = ch.convert_coordinate("chr7", 140739811)
assert result is not None
assert result
assert len(result) == 1
assert result[0] == ["chr7", "140439611", "+"]

result = ch.convert_coordinate("chr7", 140759820)
assert result is not None
assert result
assert len(result) == 1
assert result[0] == ["chr7", "140459620", "+"]

result = ch.convert_coordinate("chr7", 60878240)
assert result is not None
assert result
assert len(result) == 1
assert result[0] == ["chr7", "61646115", "+"]

0 comments on commit 08937cb

Please sign in to comment.