text stringlengths 0 828 |
|---|
warnings.warn(warntext) |
else: |
for identifier in self.container[specfile]: |
si = msrunContainer.sic[specfile][identifier] |
for sii in self.container[specfile][identifier]: |
for attribute in attributes: |
setattr(sii, attribute, |
getattr(si, attribute, None) |
)" |
1957,"def calcMz(self, specfiles=None, guessCharge=True, obsMzKey='obsMz'): |
""""""Calculate the exact mass for ``Sii`` elements from the |
``Sii.peptide`` sequence. |
:param specfiles: the name of an ms-run file or a list of names. If None |
all specfiles are selected. |
:param guessCharge: bool, True if the charge should be guessed if the |
attribute ``charge`` is missing from ``Sii``. Uses the calculated |
peptide mass and the observed m/z value to calculate the charge. |
:param obsMzKey: attribute name of the observed m/z value in ``Sii``. |
"""""" |
#TODO: important to test function, since changes were made |
_calcMass = maspy.peptidemethods.calcPeptideMass |
_calcMzFromMass = maspy.peptidemethods.calcMzFromMass |
_massProton = maspy.constants.atomicMassProton |
_guessCharge = lambda mass, mz: round(mass / (mz - _massProton), 0) |
if specfiles is None: |
specfiles = [_ for _ in viewkeys(self.info)] |
else: |
specfiles = aux.toList(specfiles) |
tempMasses = dict() |
for specfile in specfiles: |
if specfile not in self.info: |
warntext = 'Error while calling ""SiiContainer.calcMz()"": '\ |
'""%s"" is not present in ""SiiContainer.info""!'\ |
% (specfile, ) |
warnings.warn(warntext) |
else: |
for sii in self.getItems(specfiles=specfile): |
peptide = sii.peptide |
if peptide not in tempMasses: |
if hasattr(sii, 'diPeptide'): |
tempMasses[peptide] = (_calcMass(sii.peptide1) + |
_calcMass(sii.peptide2) |
) |
else: |
tempMasses[peptide] = _calcMass(peptide) |
peptideMass = tempMasses[peptide] |
if sii.charge is not None: |
sii.excMz = _calcMzFromMass(peptideMass, sii.charge) |
elif guessCharge: |
guessedCharge = _guessCharge(peptideMass, |
getattr(sii, obsMzKey) |
) |
sii.excMz = _calcMzFromMass(peptideMass, guessedCharge) |
sii.charge = guessedCharge |
else: |
sii.excMz = None |
del(tempMasses)" |
1958,"def getArrays(self, attr=None, specfiles=None, sort=False, reverse=False, |
selector=None, defaultValue=None): |
""""""Return a condensed array of data selected from :class:`Fi` instances |
from ``self.container`` for fast and convenient data processing. |
:param attr: list of :class:`Fi` item attributes that should be added |
to the returned array. The attributes ""id"" and ""specfile"" are always |
included, in combination they serve as a unique id. |
:param defaultValue: if an item is missing an attribute, the |
""defaultValue"" is added to the array instead. |
:param specfiles: filenames of ms-run files - if specified return only |
items from those files |
:type specfiles: str or [str, str, ...] |
:param sort: if ""sort"" is specified the returned list of items is sorted |
according to the :class:`Fi` attribute specified by ""sort"", if the |
attribute is not present the item is skipped. |
:param reverse: bool, set True to reverse sort order |
:param selector: a function which is called with each `Fi` item and has |
to return True (include item) or False (discard item). |
Default function is: ``lambda si: True``. By default only items with |
``Fi.isValid == True`` are returned. |
:returns: {'attribute1': numpy.array(), |
'attribute2': numpy.array(), |
... |
} |
"""""" |
selector = (lambda fi: fi.isValid) if selector is None else selector |
attr = attr if attr is not None else [] |
attr = set(['id', 'specfile'] + aux.toList(attr)) |
items = self.getItems(specfiles, sort, reverse, selector) |
return _getArrays(items, attr, defaultValue)" |
1959,"def getItems(self, specfiles=None, sort=False, reverse=False, |
selector=None): |
""""""Generator that yields filtered and/or sorted :class:`Fi` instances |
from ``self.container``. |
:param specfiles: filenames of ms-run files - if specified return only |
items from those files |
:type specfiles: str or [str, str, ...] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.