Skip to content

Commit

Permalink
Merge pull request #175 from mdshw5/develop
Browse files Browse the repository at this point in the history
Make FASTA index creation atomic
  • Loading branch information
mdshw5 authored Jun 29, 2021
2 parents 313e66d + 9a4c320 commit d35a73c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ python:
- 'pypy'
- 'pypy3'
install:
- pip install cython pysam requests coverage pyfasta pyvcf numpy
- pip install cython pysam requests coverage pyfasta pyvcf numpy nose-ignore-docstring
- pip install biopython || true
- python setup.py install
- if [ ! -f samtools-1.2 ]; then curl -sL https://github.com/samtools/samtools/releases/download/1.2/samtools-1.2.tar.bz2 | tar -xjv; fi
Expand Down
8 changes: 5 additions & 3 deletions pyfaidx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import string
import sys
import shutil
import warnings
from collections import namedtuple
from itertools import islice
Expand All @@ -29,7 +30,7 @@

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

__version__ = '0.5.9.5'
__version__ = '0.6.0'


class KeyFunctionError(ValueError):
Expand Down Expand Up @@ -437,8 +438,8 @@ def __init__(self,
self.read_fai()

except FastaIndexingError:
os.remove(self.indexname)
self.file.close()
os.remove(self.indexname + '.tmp')
raise
except Exception:
# Handle potential exceptions other than 'FastaIndexingError'
Expand Down Expand Up @@ -515,7 +516,7 @@ def read_fai(self):
def build_index(self):
try:
with self._fasta_opener(self.filename, 'rb') as fastafile:
with open(self.indexname, 'w') as indexfile:
with open(self.indexname + '.tmp', 'w') as indexfile:
rname = None # reference sequence name
offset = 0 # binary offset of end of current line
rlen = 0 # reference character length
Expand Down Expand Up @@ -596,6 +597,7 @@ def build_index(self):
"Inconsistent line found in >{0} at "
"line {1:n}.".format(rname,
bad_lines[0][0] + 1))
shutil.move(self.indexname + '.tmp', self.indexname)
except (IOError, FastaIndexingError) as e:
if isinstance(e, IOError):
raise IOError(
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[nosetests]
with-doctest=1
verbosity=2
with-ignore-docstrings=1

0 comments on commit d35a73c

Please sign in to comment.