I am mostly working as 0-based. Specifying "one_based=False" every sequence() call is not very convenient.
A default behavior should be setup when Fasta is instantiated. Please consider applying the following patch:
diff --git a/pyfasta/fasta.py b/pyfasta/fasta.py
index 05d1fa1..1f510ef 100644
--- a/pyfasta/fasta.py
+++ b/pyfasta/fasta.py
@@ -41,7 +41,7 @@ class DuplicateHeaderException(Exception):
class Fasta(Mapping):
def __init__(self, fasta_name, record_class=NpyFastaRecord,
- flatten_inplace=False, key_fn=None):
+ flatten_inplace=False, key_fn=None, one_based=True):
"""
>>> from pyfasta import Fasta, FastaRecord
@@ -68,6 +68,7 @@ class Fasta(Mapping):
self.fasta_name = fasta_name
self.record_class = record_class
self.key_fn = key_fn
+ self.one_based = one_based
self.index, self.prepared = self.record_class.prepare(self,
self.gen_seqs_with_headers(key_fn),
flatten_inplace)
@@ -130,7 +131,7 @@ class Fasta(Mapping):
return self.chr[i]
def sequence(self, f, asstring=True, auto_rc=True
- , exon_keys=None, one_based=True):
+ , exon_keys=None, one_based=None):
"""
take a feature and use the start/stop or exon_keys to return
the sequence from the assocatied fasta file:
@@ -197,6 +198,8 @@ class Fasta(Mapping):
assert 'chr' in f and f['chr'] in self, (f, f['chr'], self.keys())
fasta = self[f['chr']]
sequence = None
+ if one_based is None:
+ one_based = self.one_based
if not exon_keys is None:
sequence = self._seq_from_keys(f, fasta, exon_keys, one_based=one_based)
@@ -210,7 +213,7 @@ class Fasta(Mapping):
if asstring: return sequence
return np.array(sequence, dtype='c')
- def _seq_from_keys(self, f, fasta, exon_keys, base='locations', one_based=True):
+ def _seq_from_keys(self, f, fasta, exon_keys, base='locations', one_based=None):
"""Internal:
f: a feature dict
fasta: a Fasta object
@@ -222,6 +225,8 @@ class Fasta(Mapping):
{'CDS': [(25210018, 25210251)]}, 'start': 25210018, 'chr':
'11', 'strand': -1} set(['TRNA', 'CDS'])
"""
+ if one_based is None:
+ one_based = self.one_based
fbase = f.get(base, f)
for ek in exon_keys:
if not ek in fbase: continue
Hi,
I am mostly working as 0-based. Specifying "one_based=False" every sequence() call is not very convenient.
A default behavior should be setup when Fasta is instantiated. Please consider applying the following patch: