bioutils.coordinates module

Provides utilities for interconverting between coordinate systems especially as used by the hgvs code. The three systems are:

                : A : C : G : T : A : C :
human/hgvs  h   :-3 :-2 :-1 : 1 : 2 : 3 :
continuous  c   :-2 :-1 : 0 : 1 : 2 : 3 :
interbase   i  -3  -2  -1   0   1   2   3

Human/hgvs coordinates are the native coordinates used by the HGVS recommendations. The coordinates are 1-based, inclusive, and refer to the nucleotides; there is no 0.

Continuous coordinates are similar to hgvs coordinates, but adds 1 to all negative values so that there is no discontinuity between -1 and 1 (as there is with HGVS).

Interbase coordinates refer to the zero-width junctions between nucleotides. The main advantage of interbase coordinates is that there are no corner cases in the specification of intervals used for insertions and deletions as there is with numbering systems that refer to nucleotides themselves. Numerically, interbase intervals are 0-based, left-closed, and right-open. Beacuse referring to a single interbase coordinate is not particularly meaningful, interbase coordinates are always passed as start,end pairs.

Because it’s easy to confuse these coordinates in code, _h, _c, and _i suffixes are often used to clarify variables.

For code clarity, this module provides functions that interconvert intervals specified in each of the coordinate systems.

bioutils.coordinates.strand_int_to_pm(i)[source]

Converts 1 and -1 to ‘+’ and ‘-’ respectively.

Parameters:

i (int) –

Returns:

‘+’ if i == 1, ‘-’ if i == -1, otherwise None.

Return type:

str

Examples

>>> strand_int_to_pm(1)
'+'
>>> strand_int_to_pm(-1)
'-'
>>> strand_int_to_pm(42)
bioutils.coordinates.strand_pm(i)

Converts 1 and -1 to ‘+’ and ‘-’ respectively.

Parameters:

i (int) –

Returns:

‘+’ if i == 1, ‘-’ if i == -1, otherwise None.

Return type:

str

Examples

>>> strand_int_to_pm(1)
'+'
>>> strand_int_to_pm(-1)
'-'
>>> strand_int_to_pm(42)
bioutils.coordinates.strand_pm_to_int(s)[source]

Converts ‘+’ and ‘-’ to 1 and -1, respectively.

Parameters:

s (string) –

Returns:

1 if s == ‘+’, -1 if s == ‘-’, otherwise None.

Return type:

int

Examples

>>> strand_pm_to_int('+')
1
>>> strand_pm_to_int('-')
-1
>>> strand_pm_to_int('arglefargle')