text
stringlengths
0
828
: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, ``True`` reverses the sort order
:param selector: a function which is called with each ``Fi`` item and
has to return True (include item) or False (discard item). By
default only items with ``Fi.isValid == True`` are returned.
:returns: items from container that passed the selector function
""""""
selector = (lambda fi: fi.isValid) if selector is None else selector
if specfiles is None:
specfiles = [_ for _ in viewkeys(self.info)]
else:
specfiles = aux.toList(specfiles)
return _getItems(self.container, specfiles, sort, reverse, selector)"
1960,"def _writeContainer(self, filelike, specfile, compress):
""""""Writes the ``self.container`` entry of the specified specfile to the
``fic`` format.
:param filelike: path to a file (str) or a file-like object
:param specfile: name of an ms-run file present in ``self.info``
:param compress: bool, True to use zip file compression
.. note::
In addition it could also dump the ``self.info`` entry to the
zipfile with the filename ``info``, but this is not used at the
moment. For details see :func:`maspy.auxiliary.writeJsonZipfile()`
""""""
aux.writeJsonZipfile(filelike, self.container[specfile],
compress=compress
)"
1961,"def load(self, specfiles=None):
""""""Imports the specified ``fic`` files from the hard disk.
:param specfiles: the name of an ms-run file or a list of names. If None
all specfiles are selected.
:type specfiles: None, str, [str, str]
""""""
if specfiles is None:
specfiles = [_ for _ in viewkeys(self.info)]
else:
specfiles = aux.toList(specfiles)
for specfile in specfiles:
if specfile not in self.info:
warntext = 'Error while calling ""FiContainer.load()"": ""%s"" is'\
' not present in ""FiContainer.info""!'\
% (specfile, )
warnings.warn(warntext)
continue
else:
fiPath = aux.joinpath(self.info[specfile]['path'],
specfile+'.fic'
)
with zipfile.ZipFile(fiPath, 'r') as containerZip:
#Convert the zipfile data into a str object, necessary since
#containerZip.read() returns a bytes object.
jsonString = io.TextIOWrapper(containerZip.open('data'),
encoding='utf-8'
).read()
#infoString = io.TextIOWrapper(containerZip.open('info'),
# encoding='utf-8'
# ).read()
self.container[specfile] = json.loads(jsonString,
object_hook=Fi.jsonHook
)"
1962,"def removeAnnotation(self, specfiles=None):
""""""Remove all annotation information from :class:`Fi` elements.
:param specfiles: the name of an ms-run file or a list of names. If None
all specfiles are selected.
:type specfiles: None, str, [str, str]
""""""
if specfiles is None:
specfiles = [_ for _ in viewkeys(self.info)]
else:
specfiles = aux.toList(specfiles)
for specfile in aux.toList(specfiles):
for item in viewvalues(self.container[specfile]):
item.isMatched = False
item.isAnnotated = False
item.siIds = list()
item.siiIds = list()
item.peptide = None
item.sequence = None
item.bestScore = None"
1963,"def as_dict(self):
""""""Returns a JSON-serializeable object representing this tree.""""""
def conv(v):
if isinstance(v, SerializableAttributesHolder):
return v.as_dict()
elif isinstance(v, list):
return [conv(x) for x in v]
elif isinstance(v, dict):
return {x:conv(y) for (x,y) in v.items()}
else:
return v
return {k.replace('_', '-'): conv(v) for (k, v) in self._attributes.items()}"