Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ids : list, optional
A list of IDs in the Dataset for which to find texts. Default is
None, in which case all texts of requested type are returned.
field : str, optional
Metadata field to extract. Corresponds to column name in
Dataset.metadata DataFrame. Default is 'sample_sizes'.
Returns
-------
metadata : list
List of values of requested type for selected IDs.
"""
return_first = False
if not isinstance(ids, list) and ids is not None:
return_first = True
ids = listify(ids)
md_fields = [c for c in self.metadata.columns if c not in self._id_cols]
if field not in md_fields:
raise ValueError('Metadata field "{0}" not found.\nAvailable fields: '
'{1}'.format(field, ', '.join(md_fields)))
if ids is not None:
result = self.metadata[field].loc[self.metadata['id'].isin(ids)].tolist()
else:
result = self.metadata[field].tolist()
if return_first:
return result[0]
else:
return result
ids : list, optional
A list of IDs in the Dataset for which to find texts. Default is
None, in which case all texts of requested type are returned.
imtype : str, optional
Type of image to extract. Corresponds to column name in
Dataset.images DataFrame. Default is 'z'.
Returns
-------
images : list
List of images of requested type for selected IDs.
"""
return_first = False
if not isinstance(ids, list) and ids is not None:
return_first = True
ids = listify(ids)
imtypes = [c for c in self.images.columns if c not in self._id_cols]
if imtype not in imtypes:
raise ValueError('Image type "{0}" not found.\nAvailable types: '
'{1}'.format(imtype, ', '.join(imtypes)))
if ids is not None:
result = self.images[imtype].loc[self.images['id'].isin(ids)].tolist()
else:
result = self.images[imtype].tolist()
if return_first:
return result[0]
else:
return result
def add_images(self, images):
''' Add one or more images to the current list. '''
for image in listify(images):
if not isinstance(image, Image) and image is not None:
raise ValueError('All images inputs must be nimare Images.')
elif image.type in self.images.keys():
self.images[image.type] = image
def add_contrasts(self, contrasts):
self.contrasts.extend(listify(contrasts))
"""
Extract list of labels for which studies in Dataset have annotations.
Parameters
----------
ids : list, optional
A list of IDs in the Dataset for which to find labels. Default is
None, in which case all labels are returned.
Returns
-------
labels : list
List of labels for which there are annotations in the Dataset.
"""
if not isinstance(ids, list) and ids is not None:
ids = listify(ids)
result = [c for c in self.annotations.columns if c not in self._id_cols]
if ids is not None:
temp_annotations = self.annotations.loc[self.annotations['id'].isin(ids)]
res = temp_annotations[result].any(axis=0)
result = res.loc[res].index.tolist()
return result
ids : list, optional
A list of IDs in the Dataset for which to find texts. Default is
None, in which case all texts of requested type are returned.
text_type : str, optional
Type of text to extract. Corresponds to column name in
Dataset.texts DataFrame. Default is 'abstract'.
Returns
-------
texts : list
List of texts of requested type for selected IDs.
"""
return_first = False
if not isinstance(ids, list) and ids is not None:
return_first = True
ids = listify(ids)
text_types = [c for c in self.texts.columns if c not in self._id_cols]
if text_type not in text_types:
raise ValueError('Text type "{0}" not found.\nAvailable types: '
'{1}'.format(text_type, ', '.join(text_types)))
if ids is not None:
result = self.texts[text_type].loc[self.texts['id'].isin(ids)]
else:
result = self.texts[text_type]
if return_first:
return result[0]
else:
return result