Skip to content

Commit

Permalink
Allow reference sequence to be returned always as upper case.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michele Mattioni committed Jul 28, 2015
1 parent cd0fdea commit 9e24c20
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pyfaidx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ class Faidx(object):
def __init__(self, filename, default_seq=None, key_function=None,
as_raw=False, strict_bounds=False, read_ahead=None,
mutable=False, split_char=None, filt_function=None,
one_based_attributes=True):
one_based_attributes=True,
sequence_always_upper=False):
"""
filename: name of fasta file
key_function: optional callback function which should return a unique
Expand All @@ -222,6 +223,7 @@ def __init__(self, filename, default_seq=None, key_function=None,
self.default_seq = default_seq
self.strict_bounds = strict_bounds
self.one_based_attributes = one_based_attributes
self.sequence_always_upper = sequence_always_upper
self.index = OrderedDict()
self.buffer = dict((('seq', None), ('name', None), ('start', None), ('end', None)))
if not read_ahead or isinstance(read_ahead, int):
Expand Down Expand Up @@ -422,7 +424,10 @@ def format_seq(self, seq, rname, start, end):
seq = ''.join([seq, pad_len * self.default_seq])
else: # Return less than requested range
end = start0 + len(seq)


if self.sequence_always_upper:
seq = seq.upper()

if self.as_raw:
return seq
else:
Expand Down Expand Up @@ -568,7 +573,10 @@ def __setitem__(self, n, value):


class Fasta(object):
def __init__(self, filename, default_seq=None, key_function=None, as_raw=False, strict_bounds=False, read_ahead=None, mutable=False, split_char=None, filt_function=None, one_based_attributes=True):
def __init__(self, filename, default_seq=None, key_function=None, as_raw=False,
strict_bounds=False, read_ahead=None, mutable=False, split_char=None,
filt_function=None, one_based_attributes=True,
sequence_always_upper=False):
"""
An object that provides a pygr compatible interface.
filename: name of fasta file
Expand All @@ -578,7 +586,8 @@ def __init__(self, filename, default_seq=None, key_function=None, as_raw=False,
self.faidx = Faidx(filename, key_function=key_function, as_raw=as_raw,
default_seq=default_seq, strict_bounds=strict_bounds,
read_ahead=read_ahead, mutable=mutable, split_char=split_char,
filt_function=filt_function, one_based_attributes=one_based_attributes)
filt_function=filt_function, one_based_attributes=one_based_attributes,
sequence_always_upper=sequence_always_upper)
self.keys = self.faidx.index.keys
if not self.mutable:
self.records = dict([(rname, FastaRecord(rname, self)) for rname in self.keys()])
Expand Down

0 comments on commit 9e24c20

Please sign in to comment.