nomspectra.spectra module

class nomspectra.spectra.SpectrumList(spectra: Optional[List[nomspectra.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[nomspectra.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(how_average: str = 'weight', how: Optional[str] = None) pandas.core.frame.DataFrame[source]

Calculate molecular class density table

Parameters
  • how_average ({'weight', 'count'}) – how average density. Default “weight” - weight by intensity. Also can be “count”.

  • how ({'kellerman', 'perminova', 'laszakovits'}) – How devide to calsses. Optional. Default ‘laszakovits’

Return type

pandas Dataframe

References

Laszakovits, J. R., & MacKay, A. A. Journal of the American Society for Mass Spectrometry, 2021, 33(1), 198-202. A. M. Kellerman, T. Dittmar, D. N. Kothawala, L. J. Tranvik. Nat. Commun. 5, 3804 (2014) Perminova I. V. Pure and Applied Chemistry. 2019. Vol. 91, № 5. P. 851-864

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

Perminova I. V. From green chemistry and nature-like technologies towards ecoadaptive chemistry and technology // Pure and Applied Chemistry. 2019. Vol. 91, № 5. P. 851-864.

static read_csv(folder: Union[pathlib.Path, str]) nomspectra.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]) nomspectra.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