Range

Range

class apav.Range(ion, minmax, vol=1, color=(0, 0, 0))[source]

A single mass spectrum range

Define a singular mass spectrum range composed of a composition, interval, volume, and color. i.e. Created as:

>>> cu = Range("Cu", (62, 66), color=(0.5, 1, 0.25))
Parameters
  • ion (Union[Ion, str]) – the range composition

  • minmax (Tuple[Real, Real]) – (min, max) tuple of the mass spectrum range

  • vol (Real) – the “volume” of the atom used during reconstruction

  • color (Tuple[Real, Real, Real]) – the color as RGB fractions

property color: Tuple[numbers.Real, numbers.Real, numbers.Real]

Get the color of the range as (R, G, B) tuple. Values range from 0-1

Return type

Tuple[Real, Real, Real]

contains_mass(mass)[source]

Test if the given mass/charge ratio is contained within range’s bounds :type mass: Real :param mass: mass/charge ratio

Return type

bool

property formula: str

Get the range composition as a string

Return type

str

property hill_formula: str

Get the range composition as a string

Return type

str

intersects(rng)[source]

Determine if the range intersects a given Range

property interval: Tuple[numbers.Real, numbers.Real]

Get the (min, max) interval defined the mass spectrum range

Return type

Tuple[Real, Real]

property ion: apav.core.isotopic.Ion

Get a tuple of the elements that compose this range

Return type

Ion

property lower: numbers.Real

Get the lower (closed) boundary of the range

Return type

Real

num_elems()[source]

Get the number of unique elements of the range composition

Return type

int

property upper: numbers.Real

Get the upper (open) boundary of the range

Return type

Real

property vol: numbers.Real

Get the volume of the range

Return type

Real

RangeCollection

class apav.RangeCollection(ranges=())[source]

Operations on multiple ranges

Maintain and operate on a collection of ranges the describe the peaks in a mass spectrum. This is the principle class used for mass spectrum range definitions. A collection may be created by manually supplying the Range objects through the constructor, or 1 by 1 through RangeCollection.add(). A RangeCollection may also be created using the alternate constructors RangeCollection.from_rng() and RangeCollection.from_rrng() to import the ranges from the two common range file types.

A RangeCollection can be created as:

>>> rng_lst = [Range("Cu", (62.5, 63.5)), Range("Cu", (63.5, 66))]
>>> rngs = RangeCollection(rng_list)

Or 1 by 1 as:

>>> rngs = RangeCollection()
>>> rngs.add(Range("Cu", (62.5, 63.5)))
>>> rngs.add(Range("Cu", (63.5, 66)))
Parameters

ranges (Sequence[Range]) – sequence of Range objects

add(new)[source]

Add a new Range to the RangeCollection :type new: Range :param new: the new Range :return:

check_overlap()[source]

Check if any ranges in the RangeCollection overlap. This returns the first overlap found, not all overlaps. This is provided if Ranges are being directly accessed and modified

Return type

Union[Tuple, Tuple[float, float]]

clear()[source]

Remove all Ranges from the RangeCollection

elements()[source]

Get a tuple of all elements

Return type

Tuple[Element]

property filepath: str

Get the file path the RangeCollection was create from, if it was imported from a file

Return type

str

find_by_mass(mass)[source]

Get the range that contains the given m/q

Return type

Range

classmethod from_rng(filepath)[source]

Build RangeCollection from a .rng file :type filepath: str :param filepath: filepath

classmethod from_rrng(fpath)[source]

Build RangeCollection from *.rrng files :type fpath: str :param fpath: filepath

ions()[source]

Get a tuple of all ions

Return type

Tuple[Ion, …]

property ranges

Get a copy of the ranges in the RangeCollection. This returns a copy so as to prevent accidental modification of the underlying ranges possibly resulting in overlapping ranges.

Instead, remove the old range with RangeCollection.remove_by_mass() and add the new one, or use RangeCollection.replace()

remove_by_mass(mass)[source]

Remove a range overlapping the given mass ratio

replace(old_rng, new_rng)[source]

Replace an existing Range with a new one. Throws an error if the range is not found.

Parameters
  • old_rng (Range) – Range to be replaced

  • new_rng (Range) – New range

sorted_ranges()[source]

Get the list of range objects sorted in ascending mass range

Return type

list