natorgms.spectra module

class natorgms.spectra.SpectrumList(spectra: Optional[List[natorgms.spectrum.Spectrum]] = [])[source]

Bases: collections.UserList

Class for work list of Spectrums objects inheritan from list class with some extra features. Store list of Spectrum objects

__init__(spectra: Optional[List[natorgms.spectrum.Spectrum]] = [])[source]

init SpectrumList Class

Parameters

spectra (Sequence[Spectrum]) – list of Spectrum objects

draw_mol_density(mol_density: Optional[pandas.core.frame.DataFrame] = None, ax: Optional[matplotlib.pyplot.axes] = None, **kwargs) None[source]

Draw mol density of spectra in bar diagram

Parameters
  • mol_density (pd.DataFrame) – Optional. Table with molecular class density. Default None and cacl by self.

  • ax (matplotlib axes) – Entarnal axes for plot

  • **kwargs (dict) – Additional parameters to seaborn heatmap method

draw_simmilarity(mode: str = 'cosine', values: Optional[numpy.ndarray] = None, ax: Optional[matplotlib.pyplot.axes] = None, annot: bool = True, **kwargs) None[source]

Draw simmilarity matrix by using seaborn

Parameters
  • values (np.ndarray) – Optionaly. simmilarity matix. Default None - It is call calculate_simmilarity() method.

  • mode (str) – Optionaly. If values is none for calculate matrix. Default cosine. one of the simmilarity functions Mode can be: “tanimoto”, “jaccard”, “cosine”

  • ax (matplotlib axes) – Entarnal axes for plot

  • annotate (bool) – Draw value of simmilarity onto titles

  • **kwargs (dict) – Additional parameters to seaborn heatmap method

get_mol_density() pandas.core.frame.DataFrame[source]

Calculate molecular class density table

Return type

pandas Dataframe

References

Zherebker, Alexander, et al. “Interlaboratory comparison of humic substances compositional space as measured by Fourier transform ion cyclotron resonance mass spectrometry (IUPAC Technical Report).” Pure and Applied Chemistry 92.9 (2020): 1447-1467.

get_mol_metrics(metrics: Optional[Sequence[str]] = None, func: Optional[str] = None) pandas.core.frame.DataFrame[source]

Get average molecular metrics

Parameters
  • metrics (Sequence[str]) – Optional. Default None. Chose metrics fot watch.

  • func ({"weight", "mean", "median", "max", "min", "std"}) – How calculate average. My be “weight” (default - weight average on intensity), “mean”, “median”, “max”, “min”, “std” (standard deviation)

Return type

Pandas Dataframe

get_names() Sequence[source]

Get names of spectra

Returns

list with names of spectra in SpectrumList

Return type

List

get_simmilarity(mode: str = 'cosine', symmetric=True) numpy.ndarray[source]

Calculate simmilarity matrix for all spectra in SpectrumList

Parameters
  • mode ({"tanimoto", "jaccard", "cosine"}) – Optionaly. Default cosine. one of the simmilarity functions Mode can be: “tanimoto”, “jaccard”, “cosine”

  • symmetric (bool) – Optionaly. Default True. If metric is symmetrical ( a(b)==b(a) ) it is enough to calc just half of table

Returns

table with simmilirities of spectrum corresponig their index in SpectrumList

Return type

numpy array

get_square_vk(how_average: str = 'weight') pandas.core.frame.DataFrame[source]

Calculate Van-Krevelen square density for spectra

Parameters

how_average ({"count", "weight"}) – How calculate average. My be “count” or “weight” ((default))

Return type

Pandas Dataframe

References

Zherebker, Alexander, et al. “Interlaboratory comparison of humic substances compositional space as measured by Fourier transform ion cyclotron resonance mass spectrometry (IUPAC Technical Report).” Pure and Applied Chemistry 92.9 (2020): 1447-1467.

static read_csv(folder: Union[pathlib.Path, str]) natorgms.spectra.SpectrumList[source]

Read csv files from folder to SpectrumList object. Read only ‘csv’ ot ‘txt’ fromat

Parameters

folder (str) – folder for save spectra in separate files

Return type

SpectrumList

static read_json(filename: Union[pathlib.Path, str]) natorgms.spectra.SpectrumList[source]

Read SpectrumList from json

Parameters

filename (str) – path to SpectrumList json file, absoulute or relative

Return type

SpectrumList

to_csv(folder: Union[pathlib.Path, str]) None[source]

Save all spectrum into separate csv files

Parameters

folder (str) – folder for save spectra in separate files

to_json(filename: Union[pathlib.Path, str]) None[source]

Saves Spectrum mass-list to JSON

Parameters

filename (str) – Path for saving mass spectrum table with calculation to json file