[med-svn] [Git][med-team/python-pyfaidx][upstream] New upstream version 0.7.1
Andreas Tille (@tille)
gitlab at salsa.debian.org
Thu Aug 25 16:42:32 BST 2022
Andreas Tille pushed to branch upstream at Debian Med / python-pyfaidx
Commits:
ef2f5ad8 by Andreas Tille at 2022-08-25T14:03:17+02:00
New upstream version 0.7.1
- - - - -
3 changed files:
- README.rst
- pyfaidx/__init__.py
- + tests/test_Path.py
Changes:
=====================================
README.rst
=====================================
@@ -26,7 +26,7 @@ If you use pyfaidx in your publication, please cite:
Installation
------------
-This package is tested under Linux and macOS using Python 3.6+, and and is available from the PyPI:
+This package is tested under Linux and macOS using Python 3.7+, and and is available from the PyPI:
::
@@ -335,6 +335,17 @@ The FastaVariant class provides a way to integrate single nucleotide variant cal
>>> consensus = FastaVariant('tests/data/chr22.fasta', 'tests/data/chr22.vcf.gz', sample='NA06984', het=True, hom=True, call_filter='GT == "0/1"')
>>> consensus['22'].variant_sites
(16042793, 29187373, 29187448, 29194610, 29821332)
+
+You can also specify paths using ``pathlib.Path`` objects.
+
+.. code:: python
+
+ #new in v0.7.1
+ >>> from pyfaidx import Fasta
+ >>> from pathlib import Path
+ >>> genes = Fasta(Path('tests/data/genes.fasta'))
+ >>> genes
+ Fasta("tests/data/genes.fasta")
Accessing fasta files from `filesystem_spec <https://filesystem-spec.readthedocs.io>`_ filesystems:
=====================================
pyfaidx/__init__.py
=====================================
@@ -353,7 +353,7 @@ class Faidx(object):
Sequence() object or as a raw string.
Default: False (i.e. return a Sequence() object).
"""
-
+
if fsspec and isinstance(filename, fsspec.core.OpenFile):
self.filename = filename.path
assert getattr(filename, 'mode', 'rb') == 'rb'
@@ -1061,7 +1061,6 @@ class Fasta(object):
filename: name of fasta file or fsspec.core.OpenFile instance
indexname: name of index file or fsspec.core.OpenFile instance
"""
- self.filename = filename
self.mutable = mutable
self.faidx = Faidx(
filename,
@@ -1081,6 +1080,8 @@ class Fasta(object):
rebuild=rebuild,
build_index=build_index)
+ self.filename = self.faidx.filename
+
_record_constructor = MutableFastaRecord if self.mutable else FastaRecord
self.records = OrderedDict([(rname, _record_constructor(rname, self)) for rname in self.faidx.index.keys()])
@@ -1175,10 +1176,6 @@ class FastaVariant(Fasta):
call_filter=None,
**kwargs):
super(FastaVariant, self).__init__(filename, **kwargs)
- try:
- import pysam
- except ImportError:
- raise ImportError("pysam must be installed for FastaVariant.")
try:
import vcf
except ImportError:
=====================================
tests/test_Path.py
=====================================
@@ -0,0 +1,29 @@
+import os
+import pytest
+from pathlib import Path
+from pyfaidx import Faidx, Fasta
+
+path = os.path.dirname(__file__)
+os.chdir(path)
+
+ at pytest.fixture
+def remove_index():
+ yield
+ try:
+ os.remove('data/genes.fasta.fai')
+ except EnvironmentError:
+ pass # some tests may delete this file
+
+def test_Faidx(remove_index):
+ """ Ensures that Faidx can be created with a pathlib.Path as filename """
+ filename = 'data/genes.fasta'
+ faidx = Faidx(filename)
+ faidx_w_path = Faidx(Path(filename))
+ assert faidx.filename == faidx_w_path.filename
+
+def test_Fasta(remove_index):
+ """ Ensures that Fasta can be created with a pathlib.Path as filename """
+ filename = 'data/genes.fasta'
+ fasta = Fasta(filename)
+ fasta_w_path = Fasta(Path(filename))
+ assert fasta.filename == fasta_w_path.filename
View it on GitLab: https://salsa.debian.org/med-team/python-pyfaidx/-/commit/ef2f5ad8f9d966e431c5f68625097c5c791bf1a6
--
View it on GitLab: https://salsa.debian.org/med-team/python-pyfaidx/-/commit/ef2f5ad8f9d966e431c5f68625097c5c791bf1a6
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20220825/368a1060/attachment-0001.htm>
More information about the debian-med-commit
mailing list