From bb98adcd8d9579f14108d0bb75b2a30e0b3808fe Mon Sep 17 00:00:00 2001 From: Matt Shirley Date: Thu, 22 Oct 2015 11:29:07 -0400 Subject: [PATCH] Add updated tests. --- README.rst | 26 +++++++++++++------------- setup.py | 1 + tests/test_feature_bounds_check.py | 25 +++++++++++++++++++++++++ tests/test_sequence_class.py | 6 ------ 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/README.rst b/README.rst index 24dc972..fff6480 100644 --- a/README.rst +++ b/README.rst @@ -78,7 +78,7 @@ Acts like a dictionary. >>> len(genes['NM_001282543.1']) 5466 -Note that start and end coordinates of Sequence objects are [1, 0]. This can be changed to [0, 0] by passing ``one_based_attributes=False`` to ``Fasta`` or ``Faidx``. +Note that start and end coordinates of Sequence objects are [1, 0]. This can be changed to [0, 0] by passing ``one_based_attributes=False`` to ``Fasta`` or ``Faidx``. This argument only affects the ``Sequence .start/.end`` attributes, and has no effect on slicing coordinates. Indexes like a list: @@ -181,18 +181,18 @@ Or just get a Python string: >>> genes['NM_001282543.1'][200:230] CTCGTTCCGCGCCCGCCATGGAACCGGATG - + You can make sure that you always receive an uppercase sequence, even if your fasta file has lower case .. code:: python - + >>> from pyfaidx import Fasta >>> reference = Fasta('tests/data/genes.fasta.lower', sequence_always_upper=True) >>> reference['gi|557361099|gb|KF435150.1|'][1:70] - + >gi|557361099|gb|KF435150.1|:2-70 TGACATCATTTTCCACCTCTGCTCAGTGTTCAACATCTGACAGTGCTTGCAGGATCTCTCCTGGACAAA - + You can also perform line-based iteration, receiving the sequence lines as they appear in the FASTA file: @@ -386,11 +386,11 @@ For usage type ``faidx -h``. CCCCGCCCCTCTGGCGGCCCGCCGTCCCAGACGCGGGAAGAGCTTGGCCGGTTTCGAGTCGCTGGCCTGC AGCTTCCCTGTGGTTTCCCGAGGCTTCCTTGCTTCCCGCTCTGCGAGGAGCCTTTCATCCGAAGGCGGGA ....... - - $ faidx -m --bed regions.bed tests/data/genes.fasta + + $ faidx -m --bed regions.bed tests/data/genes.fasta ### Modifies tests/data/genes.fasta by masking regions using --default-seq character ### - - $ faidx -M --bed regions.bed tests/data/genes.fasta + + $ faidx -M --bed regions.bed tests/data/genes.fasta ### Modifies tests/data/genes.fasta by masking regions using lowercase characters ### @@ -431,16 +431,16 @@ comprehensive list of version changes. Contributing ------------ -Create a new Pull Request with one feauture. If you add a new feature, please +Create a new Pull Request with one feauture. If you add a new feature, please create also the relevant test. To get test running on your machine: - - Create a new virtualenv and install the `dev-requirements.txt`. + - Create a new virtualenv and install the `dev-requirements.txt`. - Download the test data running: python tests/data/download_gene_fasta.py - - - Run the tests with + + - Run the tests with nosetests --with-coverage --cover-package=pyfaidx diff --git a/setup.py b/setup.py index ba1a122..c299cdc 100644 --- a/setup.py +++ b/setup.py @@ -35,6 +35,7 @@ def get_version(string): "Intended Audience :: Science/Research", "Natural Language :: English", "Operating System :: Unix", + "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.2", diff --git a/tests/test_feature_bounds_check.py b/tests/test_feature_bounds_check.py index ef411b9..5f583a5 100644 --- a/tests/test_feature_bounds_check.py +++ b/tests/test_feature_bounds_check.py @@ -101,3 +101,28 @@ def test_slice_from_beginning(self): def test_slice_from_end(self): fasta = Fasta('data/genes.fasta', as_raw=True) assert fasta['gi|557361099|gb|KF435150.1|'][-4:] == 'ACTC' + + def test_issue_74_start(self): + f0 = Fasta('data/genes.fasta', one_based_attributes=False) + f1 = Fasta('data/genes.fasta', one_based_attributes=True) + assert f0['gi|557361099|gb|KF435150.1|'][0:90].start == f1['gi|557361099|gb|KF435150.1|'][0:90].start - 1 + + def test_issue_74_consistency(self): + f0 = Fasta('data/genes.fasta', one_based_attributes=False) + f1 = Fasta('data/genes.fasta', one_based_attributes=True) + assert str(f0['gi|557361099|gb|KF435150.1|'][0:90]) == str(f1['gi|557361099|gb|KF435150.1|'][0:90]) + + def test_issue_74_end_faidx(self): + f0 = Faidx('data/genes.fasta', one_based_attributes=False) + f1 = Faidx('data/genes.fasta', one_based_attributes=True) + end0 = f0.fetch('gi|557361099|gb|KF435150.1|', 1, 90).end + end1 = f1.fetch('gi|557361099|gb|KF435150.1|', 1, 90).end + assert end0 == end1 + + def test_issue_74_end_fasta(self): + f0 = Fasta('data/genes.fasta', one_based_attributes=False) + f1 = Fasta('data/genes.fasta', one_based_attributes=True) + end0 = f0['gi|557361099|gb|KF435150.1|'][1:90].end + end1 = f1['gi|557361099|gb|KF435150.1|'][1:90].end + print((end0, end1)) + assert end0 == end1 diff --git a/tests/test_sequence_class.py b/tests/test_sequence_class.py index 4af62da..8379a23 100644 --- a/tests/test_sequence_class.py +++ b/tests/test_sequence_class.py @@ -6,9 +6,6 @@ seq_invalid = Sequence(name='gi|557361099|gb|KF435150.1|', seq='TTGAAGATTTPGCATGCAGCAGGTGCGCAAGGTGAAATNTTCACTGTTAAA', start=100, end=150) - -seq_0 = Sequence(name='gi|557361099|gb|KF435150.1|', seq='TTGAAGATTTTGCATGCAGCAGGTGCGCAAGGTGAAATGTTCACTGTTAAA', - start=100, end=150, one_based_attributes=False) comp_valid = 'TTGAAGATTTnGCATGCAGCAGGtgccaAGGTGAAATGTTNACTGTTAAA' @@ -37,6 +34,3 @@ def test_comp_invalid(): def test_comp_valid(): complement(comp_valid) - -def test_zero_start(): - assert seq_0.start == seq.start - 1