Skip to content

Commit

Permalink
Merge pull request #52 from mdshw5/mtime_reindex
Browse files Browse the repository at this point in the history
Changes for v0.3.6. Fixes #50 and adds testing improvements in #51.
  • Loading branch information
mdshw5 committed Mar 2, 2015
2 parents 716a2d1 + 7335c2d commit ac5e68c
Show file tree
Hide file tree
Showing 25 changed files with 419 additions and 1,294 deletions.
27 changes: 16 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
language: python
sudo: false
python:
- '3.4'
- '3.3'
- '3.2'
- '2.7'
- '2.6'
- pypy
- pypy3
- '3.4'
- '3.3'
- '3.2'
- '2.7'
- '2.6'
- pypy
- pypy3
install:
- pip install biopython || true
- pip install -e .
- pip install coveralls
- pip install biopython || true
- pip install -e .
- pip install coveralls
before_script:
- sudo apt-get update -qq
- sudo apt-get install -y python-biopython
- if [ ! -e "tests/data/genes.fasta" ]; then /usr/bin/python tests/data/download_gene_fasta.py; fi
script: nosetests --with-coverage --cover-package=pyfaidx
deploy:
provider: pypi
Expand All @@ -25,5 +28,7 @@ deploy:
repo: mdshw5/pyfaidx
cache:
- wheelhouse
- tests/data
- apt
after_success:
- coveralls
12 changes: 8 additions & 4 deletions pyfaidx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from __future__ import division
import os
from os.path import getmtime
from six import PY2, PY3, string_types
from six.moves import zip_longest
try:
Expand All @@ -20,7 +21,7 @@

dna_bases = re.compile(r'([ACTGNactgnYRWSKMDVHBXyrwskmdvhbx]+)')

__version__ = '0.3.5'
__version__ = '0.3.6'


class FastaIndexingError(Exception):
Expand All @@ -44,7 +45,7 @@ def __init__(self, msg=None):
class RegionError(Exception):
def __init__(self, msg=None):
self.msg = 'Malformed region! Format = rname:start-end.\n' if not msg else msg
super(RegionError, self).__init__(self.msg)
super(RegionError, self).__init__(self.msg)


class Sequence(object):
Expand Down Expand Up @@ -203,7 +204,7 @@ def __init__(self, filename, default_seq=None, key_function=None,

self.mutable = mutable

if os.path.exists(self.indexname):
if os.path.exists(self.indexname) and getmtime(self.indexname) > getmtime(self.filename):
self.read_fai(split_char)
else:
try:
Expand Down Expand Up @@ -295,7 +296,7 @@ def check_bad_lines(rname, bad_lines, i):
# only one short line should be allowed
# before we hit the next header, and it
# should be the last line in the entry
if line_blen != blen or line_blen == 0:
if line_blen != blen or line_blen == 1:
bad_lines.append(i)
offset += line_blen
rlen += line_clen
Expand Down Expand Up @@ -420,6 +421,9 @@ def to_file(self, rname, start, end, seq):
m += line_len
self.file.write(seq[n:].encode())

def close(self):
self.__exit__()

def __enter__(self):
return self

Expand Down
31 changes: 31 additions & 0 deletions tests/data/download_gene_fasta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python
import os.path

def fetch_fasta(filename):
from Bio import Entrez
Entrez.email = "mdshw5@gmail.com"

id_list = ['563317589', '557361099', '557361097', '543583796',
'543583795', '543583794', '543583788', '543583786',
'543583785', '543583740', '543583738', '530384540',
'530384538', '530384536', '530384534', '530373237',
'530373235', '530364726', '530364725', '530364724']

search_results = Entrez.read(Entrez.epost("nucleotide", id=",".join(id_list)))

webenv = search_results["WebEnv"]
query_key = search_results["QueryKey"]

records = Entrez.efetch(db="nucleotide", rettype="fasta", retmode="text", webenv=webenv, query_key=query_key)

with open(filename, 'w') as fasta:
for line in records:
if len(line) > 1: # skip lines with only \n
fasta.write(line)


if __name__ == "__main__":
path = os.path.dirname(__file__)
os.chdir(path)
fasta_name = "genes.fasta"
fetch_fasta(fasta_name)
20 changes: 0 additions & 20 deletions tests/data/expect/genes.fasta.fai

This file was deleted.

20 changes: 0 additions & 20 deletions tests/data/expect/genes.fasta.fai.samtools

This file was deleted.

Loading

0 comments on commit ac5e68c

Please sign in to comment.