Skip to content
This repository was archived by the owner on Jun 16, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pyfasta/fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import os.path
from collections import Mapping
import sys
import numpy as np

from records import NpyFastaRecord
from records import np, DefaultRecord

# string.maketrans is bytes.maketrans in Python 3, but
# we want to deal with strings instead of bytes
Expand Down Expand Up @@ -40,7 +39,7 @@ def __init__(self, header):
Exception.__init__(self, 'headers must be unique: %s is duplicated' % header)

class Fasta(Mapping):
def __init__(self, fasta_name, record_class=NpyFastaRecord,
def __init__(self, fasta_name, record_class=DefaultRecord,
flatten_inplace=False, key_fn=None):
"""
>>> from pyfasta import Fasta, FastaRecord
Expand Down
21 changes: 19 additions & 2 deletions pyfasta/records.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import cPickle
import numpy as np
import sys
import os

__all__ = ['FastaRecord', 'NpyFastaRecord', 'MemoryRecord']
try:
import numpy as np
except ImportError as err:
class NotAvailable:
def __getattr__(self, key):
raise err
def __nonzero__(self):
return False
def __bool__(self):
return False
np = NotAvailable()

__all__ = ['FastaRecord', 'NpyFastaRecord', 'MemoryRecord', 'DefaultRecord']

MAGIC = "@flattened@"

Expand Down Expand Up @@ -293,3 +304,9 @@ def prepare(klass, fasta_obj, seqinfo_generator, flatten_inplace):
__all__.append('TCRecord')
except ImportError:
pass

if np:
DefaultRecord = NpyFastaRecord
else:
DefaultRecord = MemoryRecord