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[Number, Number]) – (min, max) tuple of the mass spectrum range

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

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

property color: Tuple[Number, Number, Number]

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

Return type

Tuple[Number, Number, Number]

contains_mass(mass)[source]

Test if the given mass/charge ratio is contained within range’s bounds :type mass: Number :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[Number, Number]

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

Return type

Tuple[Number, Number]

property ion: Ion

Get a tuple of the elements that compose this range

Return type

Ion

property lower: Number

Get the lower (closed) boundary of the range

Return type

Number

num_elems()[source]

Get the number of unique elements of the range composition

Return type

int

property upper: Number

Get the upper (open) boundary of the range

Return type

Number

property vol: Number

Get the volume of the range

Return type

Number

RangeCollection

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

Operations on multiple ranges

Maintain and operate on a collection of ranges that 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 created 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: List[Range]

Get a copy of the ranges in the RangeCollection. This returns a copy 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()

Return type

List[Range]

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