Documentation for Chemicals.py
¶
Chemicals
¶
Provides implementation of Chemicals objects that are used as input to the simulation.
Adducts
¶
Adducts(formula, adduct_proportion_cutoff=0.05, adduct_prior_dict=None)
A class to represent an adduct of a chemical
Create an Adduct class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
formula
|
the formula of this adduct |
required | |
adduct_proportion_cutoff
|
proportion cut-off of the adduct |
0.05
|
|
adduct_prior_dict
|
custom adduct dictionary, if any |
None
|
Source code in vimms/Chemicals.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
get_adducts
¶
get_adducts()
Get the adducts Returns: adducts in the correct proportion
Source code in vimms/Chemicals.py
186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
BaseChemical
¶
BaseChemical(ms_level, children)
The base class for Chemical objects across all MS levels. Chemicals at MS level = 1 is special and should be instantiated as either Known or Unknown chemicals. For other MS levels, please use the MSN class.
Defines a base chemical object Args: ms_level: the MS level of this chemical children: any children of this chemical
Source code in vimms/Chemicals.py
238 239 240 241 242 243 244 245 246 |
|
Chemical
¶
Chemical(rt, max_intensity, chromatogram, children, base_chemical)
Bases: BaseChemical
The class that represents a Chemical object of MS-level 1. Should be realised as either Known or Unknown chemicals.
Create a Chemical object Args: rt: the starting RT value of this chemical max_intensity: the maximum intensity of this chemical chromatogram: the chromatogram of this chemical children: any children of this chemical base_chemical: the base chemical from which this chemical is derived
Source code in vimms/Chemicals.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
get_apex_rt
¶
get_apex_rt()
Get the apex (highest point) RT of the chromatogram of this chemical Returns: the apex RT of the chromatogram
Source code in vimms/Chemicals.py
282 283 284 285 286 287 288 289 |
|
get_original_parent
¶
get_original_parent()
Get the original base chemical in a recursive manner. This is necessary if the parent chemical also has another parent. Returns: the original base chemical
Source code in vimms/Chemicals.py
297 298 299 300 301 302 303 304 |
|
ChemicalMixtureCreator
¶
ChemicalMixtureCreator(
formula_sampler,
rt_and_intensity_sampler=UniformRTAndIntensitySampler(),
chromatogram_sampler=GaussianChromatogramSampler(),
ms2_sampler=UniformMS2Sampler(),
adduct_proportion_cutoff=0.05,
adduct_prior_dict=None,
)
A class to create a list of known chemical objects using simplified, cleaned methods.
Create a mixture of vimms.Chemicals.KnownChemical objects. Args: formula_sampler: an instance of vimms.ChemicalSamplers.FormulaSampler to sample chemical formulae. rt_and_intensity_sampler: an instance of vimms.ChemicalSamplers.RTAndIntensitySampler to sample RT and intensity values. chromatogram_sampler: an instance of vimms.ChemicalSamplers.ChromatogramSampler to sample chromatograms. ms2_sampler: an instance of vimms.ChemicalSamplers.MS2Sampler to sample MS2 fragmentation spectra. adduct_proportion_cutoff: proportion of adduct cut-off adduct_prior_dict: custom adduct dictionary
Source code in vimms/Chemicals.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
|
sample
¶
sample(n_chemicals, ms_levels, include_adducts_isotopes=True)
Samples chemicals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_chemicals
|
the number of chemicals |
required | |
ms_levels
|
the highest MS level to generate. Typically this is 2. |
required | |
include_adducts_isotopes
|
whether to include adduct and isotopes or not. |
True
|
Returns: a list of vimms.Chemicals.KnownChemical objects.
Source code in vimms/Chemicals.py
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
|
ChemicalMixtureFromMZML
¶
ChemicalMixtureFromMZML(
mzml_file_name, ms2_sampler=UniformMS2Sampler(), roi_params=None
)
A class to create a list of known chemical objects from an mzML file using simplified, cleaned methods.
Create a ChemicalMixtureFromMZML class. Args: mzml_file_name: the mzML filename to extract vimms.Chemicals.UnknownChemical objects from. ms2_sampler: the MS2 sampler to use. Should be an instance of vimms.ChemicalSamplers.MS2Sampler. roi_params: parameters for ROI building, as defined in vimms.Roi.RoiBuilderParams.
Source code in vimms/Chemicals.py
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 |
|
sample
¶
sample(n_chemicals, ms_levels, source_polarity=POSITIVE)
Generate a dataset of Chemicals from the mzml file Args: n_chemicals: the number of Chemical objects. Set to None to get all the ROIs. ms_levels: the maximum MS level source_polarity: either POSITIVE or NEGATIVE
Returns: the list of Chemicals from the mzML file.
Source code in vimms/Chemicals.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 |
|
DatabaseCompound
¶
DatabaseCompound(
name,
chemical_formula,
monisotopic_molecular_weight,
smiles,
inchi,
inchikey,
)
A class to represent a compound stored in a database, e.g. HMDB
Creates a DatabaseCompound object Args: name: the compound name chemical_formula: the formula of that compound monisotopic_molecular_weight: the monoisotopic weight of the compound smiles: SMILES of the compound inchi: InCHI of the compound inchikey: InCHI key of the compound
Source code in vimms/Chemicals.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
Isotopes
¶
Isotopes(formula)
A class to represent an isotope of a chemical
Create an Isotope object Args: formula: the formula for the given isotope
Source code in vimms/Chemicals.py
73 74 75 76 77 78 79 |
|
get_isotopes
¶
get_isotopes(total_proportion)
Gets the isotope total proportion
Parameters:
Name | Type | Description | Default |
---|---|---|---|
total_proportion
|
the total proportion to compute |
required |
Returns: the computed isotope total proportion
TODO: Add functionality for elements other than Carbon
Source code in vimms/Chemicals.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
KnownChemical
¶
KnownChemical(
formula,
isotopes,
adducts,
rt,
max_intensity,
chromatogram,
children=None,
include_adducts_isotopes=True,
total_proportion=0.99,
database_accession=None,
base_chemical=None,
)
Bases: Chemical
A Chemical representation from a known chemical formula. Known chemicals have formula which are defined during creation.
Initialises a Known chemical object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
formula
|
the formula of this chemical object. |
required | |
isotopes
|
the isotope of this chemical object |
required | |
adducts
|
the adduct of this chemical object |
required | |
rt
|
the starting retention time value of this chemical object |
required | |
max_intensity
|
the maximum intensity value in the chromatogram |
required | |
chromatogram
|
the chromatogram of the chemical |
required | |
children
|
any children of the chemical |
None
|
|
include_adducts_isotopes
|
whether to include adducts and isotopes of this chemical |
True
|
|
total_proportion
|
total proportion of this chemical |
0.99
|
|
database_accession
|
database accession number, if any |
None
|
|
base_chemical
|
parent chemica, if any |
None
|
Source code in vimms/Chemicals.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
MSN
¶
MSN(mz, ms_level, prop_ms2_mass, parent_mass_prop, children=None, parent=None)
Bases: BaseChemical
A chemical that represents an MS2+ fragment.
Initialises an MSN object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mz
|
the m/z value of this fragment peak |
required | |
ms_level
|
the MS level of this fragment peak |
required | |
prop_ms2_mass
|
proportion of MS2 mass |
required | |
parent_mass_prop
|
proportion from the parent MS1 mass |
required | |
children
|
any children |
None
|
|
parent
|
parent MS1 peak |
None
|
Source code in vimms/Chemicals.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
|
MultipleMixtureCreator
¶
MultipleMixtureCreator(
master_chemical_list,
group_list,
group_dict,
intensity_noise=GaussianPeakNoise(sigma=0.001, log_space=True),
overall_missing_probability=0.0,
)
A class to create a list of known chemical objects in multiple samples (mixtures)
Create a chemical mixture creator. example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
master_chemical_list
|
the master list of Chemicals to create each sample (mixture) |
required | |
group_list
|
a list of different groups, e.g. group_list = ['control', 'control', 'case', 'case'] |
required | |
group_dict
|
a dictionary of parameters for each group, e.g. group_dict = { 'control': { 'missing_probability': 0.0, 'changing_probability': 0.0 }, 'case': { 'missing_probability': 0.0, 'changing_probability': 0.0 } } |
required | |
intensity_noise
|
intensity noise. Should be an instance of vimms.Noise.NoPeakNoise. |
GaussianPeakNoise(sigma=0.001, log_space=True)
|
|
overall_missing_probability
|
overall missing probability across all mixtures. |
0.0
|
Source code in vimms/Chemicals.py
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
|
generate_chemical_lists
¶
generate_chemical_lists()
Generates list of chemicals across mixtures (samples)
Returns: the list of chemicals across mixtures (samples)
Source code in vimms/Chemicals.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 |
|
UnknownChemical
¶
UnknownChemical(
mz, rt, max_intensity, chromatogram, children=None, base_chemical=None
)
Bases: Chemical
A Chemical representation from an unknown chemical formula. Unknown chemicals are typically created by extracting Regions-of-Interest from an existing mzML file.
Initialises an UnknownChemical object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mz
|
the m/z value of this chemical. Unlike vimms.Chemicals.KnownChemical here we know the m/z value but do not known the formula that generates this chemical. |
required | |
rt
|
the starting RT value of this chemical |
required | |
max_intensity
|
the maximum intensity of this chemical |
required | |
chromatogram
|
the chromatogram of this chemical |
required | |
children
|
any children of this chemical |
None
|
|
base_chemical
|
the base chemical from which this chemical is derived |
None
|
Source code in vimms/Chemicals.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
get_pooled_sample
¶
get_pooled_sample(dataset_list)
Takes a list of datasets and creates a pooled dataset from them
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_list
|
a list of datasets, each containing Chemical objects |
required |
Returns: combined list where the datasets have been pooled
Source code in vimms/Chemicals.py
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 |
|