Skip to content

Commit

Permalink
Add updated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdshw5 committed Oct 22, 2015
1 parent 1be38aa commit bb98adc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
26 changes: 13 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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 ###
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions tests/test_feature_bounds_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions tests/test_sequence_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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

0 comments on commit bb98adc

Please sign in to comment.