Skip to content

Commit

Permalink
catch import errors
Browse files Browse the repository at this point in the history
  • Loading branch information
grst committed Aug 29, 2024
1 parent abcc512 commit 5e5cd07
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
python -m pip install --upgrade pip wheel
- name: Install dependencies
run: |
pip install ${{ matrix.pip-flags }} ".[dev,test,rpack,dandelion,diversity]"
pip install ${{ matrix.pip-flags }} ".[dev,test,rpack,dandelion,diversity,parasail]"
- name: Test
env:
MPLBACKEND: agg
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ and this project adheres to [Semantic Versioning][].
### Other changes

- Make `parasail` an optional dependency since it is hard to install it on ARM CPUs. `TCRdist` is now the
recommended default distance metric which is much faster than parasail-based pairwise sequence alignments.
recommended default distance metric which is much faster than parasail-based pairwise sequence alignments while
providing very similar results ([#547](https://github.com/scverse/scirpy/pull/547)).

## v0.17.2

Expand Down
32 changes: 28 additions & 4 deletions src/scirpy/ir_dist/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,13 @@ def __init__(
self.gap_extend = gap_extend

def _compute_block(self, seqs1, seqs2, origin):
import parasail
try:
import parasail
except ImportError:
raise ImportError(
"Using the alignment distance requires the installation of `parasail`. "
"You can install it with `pip install parasail`."
) from None

subst_mat = parasail.Matrix(self.subst_mat)
origin_row, origin_col = origin
Expand Down Expand Up @@ -1071,7 +1077,13 @@ def _self_alignment_scores(self, seqs: Sequence) -> dict:
"""Calculate self-alignments. We need them as reference values
to turn scores into dists
"""
import parasail
try:
import parasail
except ImportError:
raise ImportError(
"Using the alignment distance requires the installation of `parasail`. "
"You can install it with `pip install parasail`."
) from None

return np.fromiter(
(
Expand Down Expand Up @@ -1218,7 +1230,13 @@ def __init__(
self.estimated_penalty = estimated_penalty if estimated_penalty is not None else penalty_dict[subst_mat]

def _compute_block(self, seqs1, seqs2, origin):
import parasail
try:
import parasail
except ImportError:
raise ImportError(
"Using the alignment distance requires the installation of `parasail`. "
"You can install it with `pip install parasail`."
) from None

subst_mat = parasail.Matrix(self.subst_mat)
origin_row, origin_col = origin
Expand Down Expand Up @@ -1267,7 +1285,13 @@ def _self_alignment_scores(self, seqs: Sequence) -> dict:
"""Calculate self-alignments. We need them as reference values
to turn scores into dists
"""
import parasail
try:
import parasail
except ImportError:
raise ImportError(
"Using the alignment distance requires the installation of `parasail`. "
"You can install it with `pip install parasail`."
) from None

return np.fromiter(
(
Expand Down

0 comments on commit 5e5cd07

Please sign in to comment.