minorg.functions module
- minorg.functions.adjusted_feature_ranges(seq, seq_range, feature_ranges, strand='+', sort=True, **kwargs)[source]
returns feature ranges, adjusted for strand and gaps in alignment 0-indexed, start inclusive, end exclusive
- minorg.functions.adjusted_pos(seq, pos, gap_char='-')[source]
Return 0-indexed position adjusted for gaps in alignment
- Parameters
seq (str or Biopython Seq.Seq) – gapped sequence
pos (int) – ungapped position
gap_char (str) – gap character
- Returns
pos
adjusted for gaps in sequence- Return type
int
- minorg.functions.append(fname, string, insert_newline_if_absent=True, insert_trailing_newline=True)[source]
- minorg.functions.convert_range(ranges, index_in=0, index_out=1, start_incl_in=True, start_incl_out=True, end_incl_in=False, end_incl_out=True)[source]
Convert range(s) from one indexing system to another.
Default values converts from 0-index [start, end) ranges to 1-index [start, end] ranges.
- Parameters
ranges (list or tuple) – range(s) to convert. Ranges may nested and discontiuous (e.g. [(1, 3), (5, 8)]) or single level (e.g. (1, 3)).
index_in (int) – index of input range(s)
index_out (int) – index of output range(s)
start_incl_in (bool) – whether input range(s) is/are start-inclusive
start_incl_out (bool) – whether output range(s) is/are start-inclusive
end_incl_in (bool) – whether input range(s) is/are end_inclusive
end_incl_out (bool) – whether output range(s) is/are end_inclusive
- Returns
In same structure as input.
- Return type
tuple or list
- minorg.functions.imap_progress(f, args, threads=1, overwrite=True, overwrite_last=True, return_output=True, msg=<function <lambda>>, lvl=0, quiet=False)[source]
- minorg.functions.pos_to_ranges(pos) list [source]
Convert an iterable of integer positions to range(s). E.g. pos_to_range({1, 2, 6, 7, 8, 9}) –> [(1, 3), (6, 10)]
- Parameters
pos (iterable) – iterable of integer positions
- Returns
Of 0-index, start-inclusive, end-exclusive ranges
- Return type
list
- minorg.functions.ranges_subtract(r1, r2)[source]
Subtract second range(s) from first range(s). Ranges should only be of integer values.
Ranges are converted to sets of integer values so set operations can be applied. Resultant set is then converted back to a list of range(s).
- Parameters
r1 (list) – range(s) to be subtracted from. Range(s) may nested and discontiuous (e.g. [(1, 3), (5, 8)]) or single level (e.g. (1, 3)).
r2 (list) – range(s) to subtract from
r1
. Range(s) may nested and discontiuous (e.g. [(1, 3), (5, 8)]) or single level (e.g. (1, 3)).
- Returns
Of range(s)
- Return type
list
- minorg.functions.ranges_to_pos(r)[source]
Convert integer start-inclusive & end-exclusive range(s) to set of integer values in the range.
- Parameters
r (tuple or list) – range(s) to convert. Ranges may nested and discontiuous (e.g. [(1, 3), (5, 8)]) or single level (e.g. (1, 3)).
- Returns
Of integer values within range
- Return type
set
- minorg.functions.tsv_entries_as_dict(fname, header, f_filter=<function <lambda>>, fields=None)[source]
- minorg.functions.within(a, b) bool [source]
Return whether range
a
is within or equal to rangeb
.- Parameters
a (tuple or list) – single-level range (e.g. (4, 6))
b (tuple or list) – single-level range (e.g. (2, 7))
- Returns
Whether range
a
is within or equal to rangeb
.- Return type
bool
- minorg.functions.within_any(a, ranges) bool [source]
Return whether range
a
is within at least one range inranges
.- Parameters
a (tuple or list) – single-level range (e.g (4, 6))
ranges (tuple or list) – list of ranges (e.g. [(-1, 1), (2, 7), (5, 12)])
- Returns
Whether range
a
is within any range inranges
- Return type
bool