mh_utils.csv_parser.classes
Classes to model parts of MassHunter CSV files.
New in version 0.2.0.
Classes:
OrderedDict to store a single property of a set of samples. |
|
|
Represents a Result in a MassHunter CSV file. |
|
Represents a sample in a MassHunter CSV file. |
|
A list of |
|
|
|
Data:
Invariant |
|
Invariant |
|
Invariant |
-
class
BaseSamplePropertyDict[source] Bases:
OrderedDictOrderedDict to store a single property of a set of samples.
Keys are the sample names and the values are dictionaries mapping compound names to property values.
Attributes:
Returns the number of compounds in the
BaseSamplePropertyDict.Returns the number of samples in the
BaseSamplePropertyDict.Returns a list of sample names in the
BaseSamplePropertyDict.-
property
n_compounds Returns the number of compounds in the
BaseSamplePropertyDict.- Return type
-
property
n_samples Returns the number of samples in the
BaseSamplePropertyDict.- Return type
-
property
sample_names Returns a list of sample names in the
BaseSamplePropertyDict.
-
property
-
class
Result(cas, name, hits, index=-1, formula='', score=0.0, abundance=0, height=0, area=0, diff_mDa=0.0, diff_ppm=0.0, rt=0.0, start=0.0, end=0.0, width=0.0, tgt_rt=0.0, rt_diff=0.0, mz=0.0, product_mz=0.0, base_peak=0.0, mass=0.0, average_mass=0.0, tgt_mass=0.0, mining_algorithm='', z_count=0, max_z=0, min_z=0, n_ions=0, polarity='', label='', flags='', flag_severity='', flag_severity_code=0)[source] Bases:
DictableRepresents a Result in a MassHunter CSV file.
- Parameters
cas
name (
str)hits
index (
int) – Default-1.formula (
str) – Default''.score (
float) – Default0.0.abundance (
float) – Default0.height (
float) – Default0.area (
float) – Default0.diff_mDa (
float) – Default0.0.diff_ppm (
float) – Default0.0.rt (
float) – Default0.0.start (
float) – Default0.0.end (
float) – Default0.0.width (
float) – Default0.0.tgt_rt (
float) – Default0.0.rt_diff (
float) – Default0.0.mz (
float) – Default0.0.product_mz (
float) – Default0.0.base_peak (
float) – Default0.0.mass (
float) – Default0.0.average_mass (
float) – Default0.0.tgt_mass (
float) – Default0.0.mining_algorithm (
str) – Default''.z_count (
int) – Default0.max_z (
int) – Default0.min_z (
int) – Default0.n_ions (
int) – Default0.polarity (
str) – Default''.label (
str) – Default''.flags (
str) – Default''.flag_severity (
str) – Default''.flag_severity_code (
int) – Default0.
Methods:
from_series(series)Consruct a
Resultfrom apandas.Series.to_dict()Return a dictionary representation of the class.
-
classmethod
from_series(series)[source] Consruct a
Resultfrom apandas.Series.
-
class
Sample(sample_name, sample_type, instrument_name, position, user, acq_method, da_method, irm_cal_status, filename, results=None)[source] Bases:
DictableRepresents a sample in a MassHunter CSV file.
- Parameters
sample_name
sample_type
instrument_name
position
user
acq_method
da_method
irm_cal_status
filename
results – Default
None.
Methods:
add_result(result)Add a result to the sample.
from_series(series)Constuct a
Samplefrom apandas.Series.to_dict()Return a dictionary representation of the class.
Attributes:
Returns a list of results in the order in which they were identified.
-
classmethod
from_series(series)[source] Constuct a
Samplefrom apandas.Series.
-
property
results_list Returns a list of results in the order in which they were identified.
I.e. sorted by the
Cpdvalue from the csv export.
-
class
SampleList(iterable=(), /)[source] -
A list of
mh_utils.csv_parser.classes.Sampleobjects.Methods:
add_new_sample(*args, **kwargs)Add a new sample to the list and return the
Sampleobject representing it.add_sample(sample)Add a
Sampleobject to the list.add_sample_from_series(series)Create a new sample object from a
pandas.seriesand add it to the list.filter(sample_names[, key, exclude])Filter the list to only contain sample_names whose name is in
sample_names.from_json_file(filename, **kwargs)Construct a
SampleListfrom JSON file.get_areas_and_scores(compound_name[, ...])Returns two dictionaries: one containing sample names and peak areas for the compound with the given name, the other containing sample names and scores.
get_areas_and_scores_for_compounds(...[, ...])Returns two dictionaries: one containing sample names and peak areas for the compounds with the given names, the other containing sample names and scores.
get_areas_for_compounds(compound_names[, ...])Returns a dictionary containing sample names and peak areas for the compounds with the given names.
Returns a list containing the names of the compounds present in the samples in alphabetical order.
get_peak_areas(compound_name[, include_none])Returns a dictionary containing sample names and peak areas for the compound with the given name.
get_retention_times(compound_name[, ...])Returns a dictionary containing sample names and retention times for the compound with the given name.
get_scores(compound_name[, include_none])Returns a dictionary containing sample names and scores for the compound with the given name.
rename_samples(rename_mapping[, key])Rename the samples in the list.
reorder_samples(order_mapping[, key])Reorder the list of
Samplesin place.sort_samples(key[, reverse])Sort the list of
Samplesin place.Attributes:
Returns a list of sample names in the
SampleList.-
add_new_sample(*args, **kwargs)[source] Add a new sample to the list and return the
Sampleobject representing it.- Return type
-
add_sample_from_series(series)[source] Create a new sample object from a
pandas.seriesand add it to the list.
-
filter(sample_names, key='sample_name', exclude=False)[source] Filter the list to only contain sample_names whose name is in
sample_names.- Parameters
- Return type
-
classmethod
from_json_file(filename, **kwargs)[source] Construct a
SampleListfrom JSON file.
-
get_areas_and_scores(compound_name, include_none=False)[source] Returns two dictionaries: one containing sample names and peak areas for the compound with the given name, the other containing sample names and scores.
- Parameters
- Return type
-
get_areas_and_scores_for_compounds(compound_names, include_none=False)[source] Returns two dictionaries: one containing sample names and peak areas for the compounds with the given names, the other containing sample names and scores.
- Parameters
- Return type
-
get_areas_for_compounds(compound_names, include_none=False)[source] Returns a dictionary containing sample names and peak areas for the compounds with the given names.
- Parameters
- Return type
-
get_compounds()[source] Returns a list containing the names of the compounds present in the samples in alphabetical order.
-
get_peak_areas(compound_name, include_none=False)[source] Returns a dictionary containing sample names and peak areas for the compound with the given name.
- Parameters
- Return type
-
get_retention_times(compound_name, include_none=False)[source] Returns a dictionary containing sample names and retention times for the compound with the given name.
- Parameters
- Return type
-
get_scores(compound_name, include_none=False)[source] Returns a dictionary containing sample names and scores for the compound with the given name.
- Parameters
- Return type
-
rename_samples(rename_mapping, key='sample_name')[source] Rename the samples in the list.
- Parameters
Use
rename_mapping=:py:obj:None or omit the sample from therename_mappingentirely to leave the name unchanged.For example:
rename_mapping = { "Propellant 1ug +ve": "Alliant Unique 1µg/L +ESI", "Propellant 1mg +ve": "Alliant Unique 1mg/L +ESI", "Propellant 1mg -ve": None, }
-
reorder_samples(order_mapping, key='sample_name')[source] Reorder the list of
Samplesin place.- Parameters
order_mapping (
Dict) –A mapping between sample names and their new position in the list. For example:
order_mapping = { "Propellant 1ug +ve": 0, "Propellant 1mg +ve": 1, "Propellant 1ug -ve": 2, "Propellant 1mg -ve": 3, }
key (
str) – The name of the property in the sample to sort by. Default'sample_name'.
-
property
sample_names Returns a list of sample names in the
SampleList.
-
-
class
SamplesAreaDict[source] Bases:
BaseSamplePropertyDictcollections.OrderedDictto store area information parsed from MassHunter results CSV files.Methods:
get_compound_areas(compound_name)Get the peak areas for the given compound in every sample.
-
class
SamplesScoresDict[source] Bases:
BaseSamplePropertyDictcollections.OrderedDictto store score information parsed from MassHunter results CSV files.Methods:
get_compound_scores(compound_name)Get the peak scores for the given compound in every sample.
-
_R= TypeVar(_R, bound=Result) Type:
TypeVarInvariant
TypeVarbound tomh_utils.csv_parser.classes.Result.
-
_S= TypeVar(_S, bound=Sample) Type:
TypeVarInvariant
TypeVarbound tomh_utils.csv_parser.classes.Sample.
-
_SL= TypeVar(_SL, bound=SampleList) Type:
TypeVarInvariant
TypeVarbound tomh_utils.csv_parser.classes.SampleList.