text stringlengths 0 828 |
|---|
return cls |
except: |
if added: |
del cls.TutelaryMeta |
raise" |
1919,"def _getArrays(items, attr, defaultValue): |
""""""Return arrays with equal size of item attributes from a list of sorted |
""items"" for fast and convenient data processing. |
:param attr: list of item attributes that should be added to the returned |
array. |
:param defaultValue: if an item is missing an attribute, the ""defaultValue"" |
is added to the array instead. |
:returns: {'attribute1': numpy.array([attributeValue1, ...]), ...} |
"""""" |
arrays = dict([(key, []) for key in attr]) |
for item in items: |
for key in attr: |
arrays[key].append(getattr(item, key, defaultValue)) |
for key in [_ for _ in viewkeys(arrays)]: |
arrays[key] = numpy.array(arrays[key]) |
return arrays" |
1920,"def _getItems(container, containerKeys=None, sort=False, reverse=False, |
selector=lambda item: True): |
""""""Generator that yields filtered and/or sorted items from the specified |
""container"". |
:param container: The container has to be a dictionary of dictionaries that |
contain some kind of items. Depending on the specified parameters all or |
a subset of these items are yielded. |
``{containerKey1: {key1: item1, key2: item2, ...}, ...}`` |
:param containerKeys: valid keys of the ""container"", if None all keys are |
considered. |
:type containerKeys: a single dictionary key or a list of keys |
:param sort: if ""sort"" is specified the returned list of items is sorted |
according to the item 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 item and returns |
True (include item) or False (discard item). If not specified all items |
are returned |
:returns: items from container that passed the selector function |
"""""" |
if containerKeys is None: |
containerKeys = [_ for _ in viewkeys(container)] |
else: |
containerKeys = aux.toList(containerKeys) |
if sort: |
sortIdentifier = list() |
for containerKey in containerKeys: |
for identifier in [_ for _ in viewkeys(container[containerKey])]: |
item = container[containerKey][identifier] |
if selector(item): |
try: |
sortIdentifier.append((getattr(item, sort), |
containerKey, identifier |
) |
) |
except AttributeError: |
pass |
sortIdentifier.sort(key=ITEMGETTER(0), reverse=reverse) |
for _, containerKey, identifier in sortIdentifier: |
yield container[containerKey][identifier] |
else: |
for containerKey in containerKeys: |
for identifier in [_ for _ in viewkeys(container[containerKey])]: |
item = container[containerKey][identifier] |
if selector(item): |
yield item" |
1921,"def _containerSetPath(container, folderpath, specfiles): |
""""""Helper function for :class:`MsrunContainer`, :class:`SiiContainer` and |
:class:`FiContainer`. Changes the folderpath of the specified specfiles in |
container.info: ``container.info[specfile]['path'] = folderpath``. |
:param container: a container like class that has an attribute ``.info`` |
:param folderpath: a filedirectory |
:param specfiles: a list of ms-run names |
"""""" |
if not os.path.exists(folderpath): |
warntext = 'Error while calling ""_containerSetPath()"": The specified '\ |
'directory ""%s"" does not exist!' %(folderpath, ) |
warnings.warn(warntext) |
for specfile in specfiles: |
if specfile in container.info: |
container.info[specfile]['path'] = folderpath |
else: |
warntext = 'Error while calling ""_containerSetPath()"": The '\ |
'specfile ""%s"" is not present in the container!'\ |
%(specfile, ) |
warnings.warn(warntext)" |
1922,"def _mzmlListAttribToTuple(oldList): |
""""""Turns the param entries of elements in a list elements into tuples, used |
in :func:`MzmlScan._fromJSON()` and :func:`MzmlPrecursor._fromJSON()`. |
.. note:: only intended for a list of elements that contain params. For |
example the mzML element ``selectedIonList`` or ``scanWindowList``. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.