pyms.DPA
¶
Alignment of peak lists by dynamic programming.
pyms.DPA.Alignment
¶
Classes for peak alignment by dynamic programming.
Classes:
|
Models an alignment of peak lists. |
Functions:
|
Converts a list of experiments into a list of alignments. |
-
class
Alignment
(expr)[source]¶ Bases:
object
Models an alignment of peak lists.
- Parameters:
expr (
Optional
[Experiment
]) – The experiment to be converted into an alignment object.- Authors:
Woon Wai Keen, Qiao Wang, Vladimir Likic, Dominic Davis-Foster.
Methods:
__len__
()Returns the length of the alignment, defined as the number of peak positions in the alignment.
aligned_peaks
([minutes])Returns a list of Peak objects where each peak has the combined spectra and average retention time of all peaks that aligned.
Calculates a common ion among the peaks of an aligned peak.
filter_min_peaks
(min_peaks)Filters alignment positions that have less peaks than
min_peaks
.get_area_alignment
([require_all_expr])Returns a Pandas dataframe containing the peak areas of the aligned peaks.
get_highest_mz_ion
(ion_dict)Returns the preferred ion for quantitiation.
get_ms_alignment
([require_all_expr])Returns a Pandas dataframe of mass spectra for the aligned peaks.
get_peak_alignment
([minutes, require_all_expr])Returns a Pandas dataframe of aligned retention times.
get_peaks_alignment
([require_all_expr])Returns a Pandas dataframe of Peak objects for the aligned peaks.
write_common_ion_csv
(area_file_name, ...[, ...])Writes the alignment to CSV files.
write_csv
(rt_file_name, area_file_name[, ...])Writes the alignment to CSV files.
write_ion_areas_csv
(ms_file_name[, minutes])Write Ion Areas to CSV File.
Attributes:
List of experiment codes.
-
__len__
()[source]¶ Returns the length of the alignment, defined as the number of peak positions in the alignment.
- Return type:
- Authors:
Qiao Wang, Vladimir Likic
-
aligned_peaks
(minutes=False)[source]¶ Returns a list of Peak objects where each peak has the combined spectra and average retention time of all peaks that aligned.
-
filter_min_peaks
(min_peaks)[source]¶ Filters alignment positions that have less peaks than
min_peaks
.This function is useful only for within state alignment.
- Parameters:
min_peaks (
int
) – Minimum number of peaks required for the alignment position to survive filtering.- Author:
Qiao Wang
-
get_area_alignment
(require_all_expr=True)[source]¶ Returns a Pandas dataframe containing the peak areas of the aligned peaks.
-
static
get_highest_mz_ion
(ion_dict)[source]¶ Returns the preferred ion for quantitiation.
Looks at the list of candidate ions, selects those which have highest occurrence, and selects the heaviest of those.
-
get_ms_alignment
(require_all_expr=True)[source]¶ Returns a Pandas dataframe of mass spectra for the aligned peaks.
-
get_peak_alignment
(minutes=True, require_all_expr=True)[source]¶ Returns a Pandas dataframe of aligned retention times.
- Parameters:
- Authors:
Woon Wai Keen, Andrew Isaac, Vladimir Likic, Dominic Davis-Foster
- Return type:
-
get_peaks_alignment
(require_all_expr=True)[source]¶ Returns a Pandas dataframe of Peak objects for the aligned peaks.
-
write_common_ion_csv
(area_file_name, top_ion_list, minutes=True)[source]¶ Writes the alignment to CSV files.
This function writes two files: one containing the alignment of peak retention times and the other containing the alignment of peak areas.
- Parameters:
area_file_name (
Union
[str
,Path
,PathLike
]) – The name for the areas alignment file.top_ion_list (
Sequence
[float
]) – A list of the highest intensity common ion along the aligned peaks.minutes (
bool
) – Whether to save retention times in minutes. IfFalse
, retention time will be saved in seconds. DefaultTrue
.
- Authors:
Woon Wai Keen, Andrew Isaac, Sean O’Callaghan, Vladimir Likic, Dominic Davis-Foster (pathlib support)
-
write_csv
(rt_file_name, area_file_name, minutes=True)[source]¶ Writes the alignment to CSV files.
This function writes two files: one containing the alignment of peak retention times and the other containing the alignment of peak areas.
- Parameters:
rt_file_name (
Union
[str
,Path
,PathLike
]) – The name for the retention time alignment file.area_file_name (
Union
[str
,Path
,PathLike
]) – The name for the areas alignment file.minutes (
bool
) – Whether to save retention times in minutes. IfFalse
, retention time will be saved in seconds. DefaultTrue
.
- Authors:
Woon Wai Keen, Andrew Isaac, Vladimir Likic, David Kainer, Dominic Davis-Foster (pathlib support)
-
exprl2alignment
(expr_list)[source]¶ Converts a list of experiments into a list of alignments.
- Parameters:
expr_list (
List
[Experiment
]) – The list of experiments to be converted into an alignment objects.- Return type:
- Returns:
A list of alignment objects for the experiments.
- Author:
Vladimir Likic
pyms.DPA.PairwiseAlignment
¶
Classes for peak alignment by dynamic programming.
Classes:
|
Models pairwise alignment of alignments. |
Functions:
|
Aligns two alignments. |
|
Aligns a list of alignments using the supplied guide tree. |
|
A helper function for sorting peak positions in a alignment. |
|
Calculates similarity score between two alignments (new method). |
|
Solves optimal path in score matrix based on global sequence alignment. |
|
Merges two alignments with gaps added in from DP traceback. |
|
Calculates the similarity between the two alignment positions. |
|
Calculates the score matrix between two alignments. |
|
Calculates the score matrix between two alignments. |
-
class
PairwiseAlignment
(alignments, D, gap)[source]¶ Bases:
object
Models pairwise alignment of alignments.
-
align_with_tree
(T, min_peaks=1)[source]¶ Aligns a list of alignments using the supplied guide tree.
- Parameters:
T (
PairwiseAlignment
) – The pairwise alignment object.min_peaks (
int
) – Default1
.
- Return type:
- Returns:
The final alignment consisting of aligned input alignments.
- Authors:
Woon Wai Keen, Vladimir Likic
-
alignment_compare
(x, y)[source]¶ A helper function for sorting peak positions in a alignment.
- Parameters:
x
y
- Return type:
-
alignment_similarity
(traces, score_matrix, gap)[source]¶ Calculates similarity score between two alignments (new method).
-
merge_alignments
(A1, A2, traces)[source]¶ Merges two alignments with gaps added in from DP traceback.
-
position_similarity
(pos1, pos2, D)[source]¶ Calculates the similarity between the two alignment positions.
A score of 0 is best and 1 is worst.
pyms.DPA.IO
¶
Functions for writing peak alignment to various file formats.
Functions:
|
Writes the alignment to an excel file, with colouring showing possible mis-alignments. |
|
Creates a csv file with UID, common and qualifying ions and their ratios for mass hunter interpretation. |
|
Write an alignment to an Excel workbook. |
-
write_excel
(alignment, file_name, minutes=True)[source]¶ Writes the alignment to an excel file, with colouring showing possible mis-alignments.
- Parameters:
- Author:
David Kainer
pyms.DPA.clustering
¶
Provides Pycluster.treecluster regardless of which library provides it.
Functions:
|
Perform hierarchical clustering, and return a Tree object. |
-
treecluster
(data, mask=None, weight=None, transpose=False, method='m', dist='e', distancematrix=None)[source]¶ Perform hierarchical clustering, and return a Tree object.
This function implements the pairwise single, complete, centroid, and average linkage hierarchical clustering methods.
- Keyword arguments:
Either data or distancematrix should be None. If distancematrix is None, the hierarchical clustering solution is calculated from the values stored in the argument data. If data is None, the hierarchical clustering solution is instead calculated from the distance matrix. Pairwise centroid-linkage clustering can be performed only from the data values and not from the distance matrix. Pairwise single-, maximum-, and average-linkage clustering can be calculated from the data values or from the distance matrix.
Return value: treecluster returns a Tree object describing the hierarchical clustering result. See the description of the Tree class for more information.