OpenSWATH - GUI Models

SWATH MS Run Module

SingleChromatogramFile

class openswathgui.models.SingleChromatogramFile.SingleChromatogramFile(run, filename, load_in_memory=False, precursor_mapping=None, sequences_mapping=None)

Data Model for a single file from one run.

One run may contain multiple mzML files

runid

Current run id

Private Attributes:
  • _run: A pymzml.run.Reader object
  • _filename: Original filename
  • _basename: Original filename basename
  • _precursor_mapping: Dictionary { FullPrecursorName : [transition_id, transition_id] }
  • _sequences_mapping: Dictionary { StrippedSequence : [FullPrecursorName, FullPrecursorName]}
getTransitionCount()

Get total number of transitions

get_all_peptide_sequences()

Get all (stripped) sequences

get_all_precursor_ids()

Get all precursor ids (full sequence + charge)

get_data_for_precursor(precursor)

Retrieve raw data for a specific precursor - data will be as list of pairs (timearray, intensityarray)

get_id()
get_precursors_for_sequence(sequence)

Get all precursors mapping to one stripped sequence

get_transitions_for_precursor(precursor)

Return the transition names for a specific precursor

get_transitions_with_mass_for_precursor(precursor)

Return the transition names prepended with the mass for a specific precursor

SwathRun

class openswathgui.models.SwathRun.SwathRun(files, runid=None, precursor_mapping=None, sequences_mapping=None)

Bases: object

Data model for an individual SWATH injection (may contain multiple mzML files).

This contains the model for all data from a single run (e.g. one panel in the viewer - in reality this could be multiple actual MS runs since in SRM not all peptides can be measured in the same injection or just multiple files generated by SWATH MS.

It abstracts all the interfaces of SingleChromatogramFile, usually all other classes directly communicate with this class.

runid

Current run id

Private Attributes:

_all_swathes: Dictionary of { mz : SingleChromatogramFile }

_files: List of files that are containing data for this run

_in_memory: Whether data should be held in memory

TODO: the following three attributes are set by _read_peakgroup_files violating encapsulation)

_range_mapping: Dictionary of { precursor_id : [leftWidth, rightWidth] }

_score_mapping: Dictionary of { precursor_id : FDR_score }

_intensity_mapping: Dictionary of { precursor_id : Intensity }

getTransitionCount()

Aggregate transition count over all files

get_all_peptide_sequences()
get_all_precursor_ids()
get_data_for_precursor(precursor)

Retrieve raw data for a specific precursor (using the right run).

get_id()
get_intensity_data(precursor)
get_precursors_for_sequence(sequence)
get_range_data(precursor)
get_score_data(precursor)
get_transitions_for_precursor(precursor)
get_transitions_for_precursor_display(precursor)
remove_precursors(toremove)

Remove a set of precursors from the run (this can be done to filter down the list of precursors to display).

SwathRunCollection

class openswathgui.models.SwathRunCollection.SwathRunCollection

Bases: object

A collection of SWATH files

Contains multiple SwathRun objects which each represent one single mass spectrometric injection. It can be initialized in three different ways, either from a set of directories (assuming each directory is one run), a set of files mapped to a run id (multiple files may be mapped to run id) or a simple flat list of chromatogram files.

swath_chromatograms

Dictionary mapping of the form { run_id : SwathRun}

getRunIds()

Returns all available run ids

Returns:runlist – A list of all available runs
Return type:list of str
getSwathFile(key)
Parameters:key (str) – The requested run
Returns:run – The run corresponding to the requested run
Return type:SwathRun
getSwathFiles()
Returns:runs – All runs found in this collection
Return type:list of SwathRun
initialize_from_chromatograms(runid_mapping, precursor_mapping=None, sequences_mapping=None)

Initialize from a set of mapped chromatogram files. There may be multiple chromatogram (chrom.mzML) files mapped to one run id.

Parameters:
  • runid_mapping (dict) – A mapping dictionary of form { run_id : [filename, filename, ...] }
  • precursor_mapping (dict) – An optional mapping of the form { FullPrecursorName : [transition_id, transition_id, ...] }
  • sequences_mapping (dict) – An optional mapping of the form { StrippedSequence : [FullPrecursorName, FullPrecursorName, ...]}
initialize_from_directories(runid_mapping)

Initialize from a directory

This assumes that all .mzML files in the same directory are from the same run. There may be multiple chromatogram (chrom.mzML) files mapped to one run id.

Parameters:runid_mapping ((dict)) – A mapping dictionary of form { run_id : directory }
initialize_from_files(filenames)

Initialize from individual files, setting the runid as increasing integers.

This assumes that each .mzML file is from a separate run.

Parameters:filenames (list of str) – A list of filenames

ChromatogramTransition Module

ChromatogramTransition

class openswathgui.models.ChromatogramTransition.ChromatogramTransition(name, charge, subelements, peptideSequence=None, fullName=None, datatype='Precursor')

Bases: object

Internal tree structure object representing one row in the in the left side tree.

This is the bridge between the view and the data model

Pointers to objects of ChromatogramTransition are passed to callback functions when the selection of the left side tree changes. The object needs to have store information about all the column present in the rows (PeptideSequence, Charge, Name) which are requested by the PeptideTree model.

Also it needs to know how to access the raw data as well as meta-data for a certain transition. This is done through getData, getLabel etc.

getCharge()

Get charge of precursor

Returns:Charge
Return type:int
getData(run)

Get raw data for a certain object

If we have a single precursors or a peptide with only one precursor, we show the same data as for the precursor itself. For a peptide with multiple precursors, we show all precursors as individual curves. For a single transition, we simply plot that transition.

Parameters:run (SwathRun) – SwathRun object which will be used to retrieve data
Returns:Returns the raw data of the chromatograms for a given run. The dataformat is a list of transitions and each transition is a pair of (timearray,intensityarray)
Return type:list of pairs (timearray, intensityarray)
getIntensity(run)

Get the intensity for a specific run and current precursor

Parameters:run (SwathRun) – SwathRun object which will be used to retrieve data
Returns:The intensity for a specific run and current precursor
Return type:float
getLabel(run)

Get the labels for a curve (corresponding to the raw data from getData call) for a certain object.

If we have a single precursors or a peptide with only one precursor, we show the same data as for the precursor itself. For a peptide with multiple precusors, we show all precursors as individual curves. For a single transition, we simply plot that transition.

Parameters:run (SwathRun) – SwathRun object which will be used to retrieve data
Returns:The labels to display for each line in the graph
Return type:list of str
getName()

Get name of precursor

Returns:Name of precursor
Return type:str
getPeptideSequence()
getProbScore(run)

Get the probabilistic score for a specific run and current precursor

Parameters:run (SwathRun) – SwathRun object which will be used to retrieve data
Returns:The probabilistic score for a specific run and current precursor
Return type:float
getRange(run)

Get the data range (leftWidth/rightWidh) for a specific run

Parameters:run (SwathRun) – SwathRun object which will be used to retrieve data
Returns:A pair of floats representing the data range (leftWidth/rightWidh) for a specific run
Return type:list of float
getSubelements()
getType()

MSData Data model Module

MSData

class openswathgui.models.MSData.DataModel

Bases: object

The main data model

It stores the references to individual SwathRun objects and can be initialized from a list of files.

runs

list of SwathRun

The MS runs which are handled by this class

getStatus()

Returns its own status (number of transitions etc.) for the status bar.

get_precursor_tree()

Returns the data models precursor tree structure

Returns a list of ChromatogramTransition root elements (rows) to display in the left side tree view. Each element may contain nested ChromatogramTransition elements (tree elements).

get_runs()

Returns the list of SwathRun objects of this current data model

list of SwathRun
The main content of the class is returned, its list of SwathRun
loadFiles(filenames)

Load a set of chromatogram files (no peakgroup information).

Parameters:filenames (list of str) – List of filepaths containing the chromatograms
loadMixedFiles(rawdata_files, aligned_pg_files)

Load files that contain raw data files and aligned peakgroup files.

Since no mapping is present here, we need to infer it from the data. Basically, we try to map the column align_runid to the filenames of the input .chrom.mzML hoping that the user did not change the filenames.

Parameters:
  • rawdata_files (list of str) – List of paths to chrom.mzML files
  • aligned_pg_files (list of str) – List of paths to output files of the FeatureAligner
load_from_yaml(yamlfile)

Load a yaml file containing a mapping of chromatogram files and aligned peakgroup files.

Parameters:yamlfile (str) – Filepath to the yaml file for loading

PrecursorModel

class openswathgui.models.MSData.PrecursorModel(chrom_id)

A simplistic precursor model

It is initialized with an ID and knows how to parse the sequence and the charge from that string.

getCharge()
getFullSequence()

TreeModels Module

TreeNode

class openswathgui.models.TreeModels.TreeNode(parent, row)

Bases: object

Generic model of a tree node

Adopted from http://www.hardcoded.net/articles/using_qtreeview_with_qabstractitemmodel.htm

See PeptideTreeNode for implementation.

TreeModel

class openswathgui.models.TreeModels.TreeModel

Bases: PyQt4.QtCore.QAbstractItemModel

Generic tree model

Adopted from http://www.hardcoded.net/articles/using_qtreeview_with_qabstractitemmodel.htm

See parent class http://qt-project.org/doc/qt-5/QAbstractItemModel.html

See PeptideTree for implementation.

index(row, column, parent)
initialize()

Initialize tree

parent(index)
reset()
rowCount(parent)

PeptideTreeNode

class openswathgui.models.PeptideTree.PeptideTreeNode(ref, parent, row)

Bases: openswathgui.models.TreeModels.TreeNode

Implementation of a node in the right-hand peptide tree in the GUI

PeptideTree

class openswathgui.models.PeptideTree.PeptideTree(rootElements)

Bases: openswathgui.models.TreeModels.TreeModel

Implementation of a tree in the right-hand peptide tree in the GUI

columnCount(parent)
data(index, role)

Get data for a specific index (and role)

Currently supported role is only Qt.DisplayRole (for displaying the tree). The three columns are:
  • Peptide Sequence
  • Charge
  • Name
headerData(section, orientation, role)

Get header data (column header) for a specific index (and role)

The three columns are:
  • Peptide Sequence
  • Charge
  • Name
set_precursor_tree_structure(data, sortData=True)

Initialize tree structure

The three columns are:
  • Peptide Sequence
  • Charge
  • Name