def v_qspectrum(cls, analysis_object, x, y, viewer_option=0): """Implement support for qspectrum URL requests for the viewer""" #Get the h5py dataset with the peak_cube data data = None customMZ = None if viewer_option == 0: from omsi.shared.data_selection import selection_string_to_object pl = analysis_object['npg_peaks_labels'] ll = analysis_object['npg_labels_list'] pai = analysis_object['npg_peaks_ArrayIndex'] pints = analysis_object['npg_peaks_Intensities'] x_select = selection_string_to_object(selection_string=x) y_select = selection_string_to_object(selection_string=y) dataset = cls.getnpgspec(pl, ll, pai, pints, x_select, y_select) try: return dataset[:] except: print "NPG spectrum selection failed" return None #Return the spectra and indicate that no customMZ data values (i.e. None) are needed return data, None elif viewer_option > 0: return super(omsi_npg, cls).v_qspectrum(analysis_object, x, y, viewer_option - 1) return data, customMZ
def v_qspectrum(cls, analysis_object, x, y, viewer_option=0): """Implement support for qspectrum URL requests for the viewer""" # Get the h5py dataset with the peak_cube data data = None customMZ = None if viewer_option == 0: from omsi.shared.data_selection import check_selection_string, selection_type, \ selection_string_to_object dataset = analysis_object['npg_peak_cube_mz'] x_select = selection_string_to_object(selection_string=x) y_select = selection_string_to_object(selection_string=y) if (check_selection_string(x) == selection_type['indexlist']) and ( check_selection_string(y) == selection_type['indexlist']): #The peak-cube data is usually small enough. To handle the multiple list selection case #we here just load the full data cube and use numpy to do the subselection. Note, this #version would work for all selection types but we would like to avoid loading the #full data if we don't have to. data = dataset[:][x_select, y_select, :] else: data = dataset[x_select, y_select, :] #Return the spectra and indicate that no customMZ data values (i.e. None) are needed return data, None elif viewer_option > 0: return super(omsi_peakcube, cls).v_qspectrum(analysis_object, x, y, viewer_option - 1) return data, customMZ
def v_qspectrum(cls, analysis_object, x, y, viewer_option=0): """ Get from which 3D analysis spectra in x/y should be extracted for presentation in the OMSI viewer Developer Note: h5py currently supports only a single index list. If the user provides an index-list for both x and y, then we need to construct the proper merged list and load the data manually, or if the data is small enough, one can load the full data into a numpy array which supports mulitple lists in the selection. :param analysis_object: The omsi_file_analysis object for which slicing should be performed :param x: x selection string :param y: y selection string :param viewer_option: If multiple default viewer behaviors are available for a given analysis then this option is used to switch between them. :returns: The following two elemnts are expected to be returned by this function : 1) 1D, 2D or 3D numpy array of the requested spectra. NOTE: The mass (m/z) axis must be the last \ axis. For index selection x=1,y=1 a 1D array is usually expected. For indexList selections x=[0]&y=[1] \ usually a 2D array is expected. For ragne selections x=0:1&y=1:2 we one usually expects a 3D array. 2) None in case that the spectra axis returned by v_qmz are valid for the returned spectrum. Otherwise, \ return a 1D numpy array with the m/z values for the spectrum (i.e., if custom m/z values are needed \ for interpretation of the returned spectrum).This may be needed, e.g., in cases where a per-spectrum \ peak analysis is performed and the peaks for each spectrum appear at different m/z values. """ # Convert the x,y selection to a python selection from omsi.shared.data_selection import selection_string_to_object x_select = selection_string_to_object(x) # Convert the selection string to a python selection y_select = selection_string_to_object(y) # Convert the selection string to a python selection """EDIT_ME Specify the number of custom viewer_options you are going to provide for qslice""" num_custom_viewer_options = 0 # Expose the qslice viewer functionality of any data dependencies if viewer_option >= num_custom_viewer_options: return super(omsi_cx, cls).v_qspectrum(analysis_object, x, y, viewer_option=num_custom_viewer_options) """EDIT_ME Define your custom qspectrum viewer options. Here you need to handle all the different behaviors that are custom to your analysis. Note, this function is expected to return two object: i) The data for the spectrum and ii) the m/z axis information for the spectrum or None, in case that the m/z data is identical to what the v_qmz function returns. Below a simple example. if viewer_option == 0 : dataset = anaObj[ 'my_output_data' ] #This is e.g, an output dataset of your analysis data = dataset[ x_select , y_select, : ] return data, None elif viewer_option == 1 : ... """ return None, None
def v_qspectrum(cls, analysis_object, x, y, viewer_option=0): """Get from which 3D analysis spectra in x/y should be extracted for presentation in the OMSI viewer Developer Note: h5py currently supports only a single index list. If the user provides an index-list for both x and y, then we need to construct the proper merged list and load the data manually, or if the data is small enough, one can load the full data into a numpy array which supports multiple lists in the selection. :param analysis_object: The omsi_file_analysis object for which slicing should be performed :param x: x selection string :param y: y selection string :param viewer_option: If multiple default viewer behaviors are available for a given analysis then this option is used to switch between them. :returns: The following two elements are expected to be returned by this function : 1) 1D, 2D or 3D numpy array of the requested spectra. NOTE: The mass (m/z) axis must be the last \ axis. For index selection x=1,y=1 a 1D array is usually expected. For indexList selections \ x=[0]&y=[1] usually a 2D array is expected. For ragne selections x=0:1&y=1:2 we one usually \ expects a 3D array/ 2) None in case that the spectra axis returned by v_qmz are valid for the returned spectrum. \ Otherwise, return a 1D numpy array with the m/z values for the spectrum (i.e., if custom m/z \ values are needed for interpretation of the returned spectrum).This may be needed, e.g., in \ cases where a per-spectrum peak analysis is performed and the peaks for each spectrum appear \ at different m/z values. """ # Convert the x,y selection to a python selection from omsi.shared.data_selection import selection_string_to_object x_select = selection_string_to_object(x) # Convert the selection string to a python selection y_select = selection_string_to_object(y) # Convert the selection string to a python selection num_custom_viewer_options = 1 # Expose the qslice viewer functionality of any data dependencies if viewer_option >= num_custom_viewer_options: return super(omsi_tic_norm, cls).v_qspectrum(analysis_object, x, y, viewer_option=viewer_option-num_custom_viewer_options) elif viewer_option == 0: dataset = analysis_object['norm_msidata'] # h5py supports only one indexlist as part of a selection. We have to work-around this # by retrieving the spectra we want one-at-a-time if the user provides two index lists if isinstance(x_select, list) and isinstance(y_select, list): xsize = len(x_select) ysize = len(y_select) if xsize != ysize: raise ValueError("x and y selection size do not match") data = np.zeros(shape=(xsize, dataset.shape[2]), dtype=dataset.dtype) for i in xrange(0, xsize): data[i, :] = dataset[x_select[i], y_select[i], :] else: data = dataset[x_select, y_select, :] return data, None return None, None
def v_qspectrum(cls, analysis_object, x, y, viewer_option=0): """ Get from which 3D analysis spectra in x/y should be extracted for presentation in the OMSI viewer Developer Note: h5py currently supports only a single index list. If the user provides an index-list for both x and y, then we need to construct the proper merged list and load the data manually, or if the data is small enough, one can load the full data into a numpy array which supports mulitple lists in the selection. :param analysis_object: The omsi_file_analysis object for which slicing should be performed :param x: x selection string :param y: y selection string :param viewer_option: If multiple default viewer behaviors are available for a given analysis then this option is used to switch between them. :returns: The following two elemnts are expected to be returned by this function : 1) 1D, 2D or 3D numpy array of the requested spectra. NOTE: The mass (m/z) axis must be the last \ axis. For index selection x=1,y=1 a 1D array is usually expected. For indexList selections x=[0]&y=[1] \ usually a 2D array is expected. For ragne selections x=0:1&y=1:2 we one usually expects a 3D array. 2) None in case that the spectra axis returned by v_qmz are valid for the returned spectrum. Otherwise, \ return a 1D numpy array with the m/z values for the spectrum (i.e., if custom m/z values are needed \ for interpretation of the returned spectrum).This may be needed, e.g., in cases where a per-spectrum \ peak analysis is performed and the peaks for each spectrum appear at different m/z values. """ # Convert the x,y selection to a python selection from omsi.shared.data_selection import selection_string_to_object x_select = selection_string_to_object( x) # Convert the selection string to a python selection y_select = selection_string_to_object( y) # Convert the selection string to a python selection """EDIT_ME Specify the number of custom viewer_options you are going to provide for qslice""" num_custom_viewer_options = 0 # Expose the qslice viewer functionality of any data dependencies if viewer_option >= num_custom_viewer_options: return super(omsi_cx, cls).v_qspectrum( analysis_object, x, y, viewer_option=num_custom_viewer_options) """EDIT_ME Define your custom qspectrum viewer options. Here you need to handle all the different behaviors that are custom to your analysis. Note, this function is expected to return two object: i) The data for the spectrum and ii) the m/z axis information for the spectrum or None, in case that the m/z data is identical to what the v_qmz function returns. Below a simple example. if viewer_option == 0 : dataset = anaObj[ 'my_output_data' ] #This is e.g, an output dataset of your analysis data = dataset[ x_select , y_select, : ] return data, None elif viewer_option == 1 : ... """ return None, None
def v_qslice(cls, analysis_object, z, viewer_option=0): """ Get 3D analysis dataset for which z-slices should be extracted for presentation in the OMSI viewer :param analysis_object: The omsi_file_analysis object for which slicing should be performed :param z: Selection string indicting which z values should be selected. :param viewer_option: If multiple default viewer behaviors are available for a given analysis then this option is used to switch between them. :returns: numpy array with the data to be displayed in the image slice viewer. Slicing will be performed typically like [:,:,zmin:zmax]. """ # Convert the z selection to a python selection from omsi.shared.data_selection import selection_string_to_object zselect = selection_string_to_object( z) # Convert the selection string to a python selection num_custom_viewer_options = 1 # Expose the qslice viewer functionality of any data dependencies if viewer_option >= num_custom_viewer_options: return super(omsi_mz_rebin, cls).v_qslice( analysis_object, z, viewer_option=viewer_option - num_custom_viewer_options) #Define your custom qslice viewer options. Here you need to handle all the different #behaviors that are custom to your analysis. Below a simple example. if viewer_option == 0: dataset = analysis_object['new_msidata'] return dataset[:, :, zselect] return None
def v_qslice(cls, analysis_object, z, viewer_option=0): """ Get 3D analysis dataset for which z-slices should be extracted for presentation in the OMSI viewer :param analysis_object: The omsi_file_analysis object for which slicing should be performed :param z: Selection string indicting which z values should be selected. :param viewer_option: If multiple default viewer behaviors are available for a given analysis then this option is used to switch between them. :returns: numpy array with the data to be displayed in the image slice viewer. Slicing will be performed typically like [:,:,zmin:zmax]. """ # Convert the z selection to a python selection from omsi.shared.data_selection import selection_string_to_object z_select = selection_string_to_object( z) # Convert the selection string to a python selection """EDIT_ME Specify the number of custom viewer_options you are going to provide for qslice""" current_objective_dimension = analysis_object['objectiveDim'][0] if current_objective_dimension == cls.dimension_index['imageDim']: num_custom_viewer_options = 1 else: num_custom_viewer_options = 2 # Expose the qslice viewer functionality of any data dependencies if viewer_option >= num_custom_viewer_options: return super(omsi_cx, cls).v_qslice(analysis_object, z, viewer_option=viewer_option - num_custom_viewer_options) elif viewer_option == 0 and current_objective_dimension == cls.dimension_index[ 'imageDim']: informative_indices = analysis_object['infIndices'][z_select] cx_analysis_object = omsi_cx() cx_analysis_object.read_from_omsi_file( analysis_object=analysis_object, load_data=False, load_parameters=False, load_runtime_data=False) return cx_analysis_object['msidata'][:, :, informative_indices] elif viewer_option == 0 and current_objective_dimension == cls.dimension_index[ 'pixelDim']: return analysis_object['levScores'][:] elif viewer_option == 1 and current_objective_dimension == cls.dimension_index[ 'pixelDim']: return analysis_object['infIndices'][:] """EDIT_ME Define your custom qslice viewer options. Here you need to handle all the different behaviors that are custom to your analysis. Below a simple example. if viewer_option == 0 : dataset = anaObj[ 'my_output_data' ] #This is e.g, an output dataset of your analysis return dataset[ : , :, z_select ] elif viewer_option == 1 : ... """ return None
def v_qslice(cls, analysis_object, z, viewer_option=0): """ Get 3D analysis dataset for which z-slices should be extracted for presentation in the OMSI viewer :param analysis_object: The omsi_file_analysis object for which slicing should be performed :param z: Selection string indicting which z values should be selected. :param viewer_option: If multiple default viewer behaviors are available for a given analysis then this option is used to switch between them. :returns: numpy array with the data to be displayed in the image slice viewer. Slicing will be performed typically like [:,:,zmin:zmax]. """ # Convert the z selection to a python selection from omsi.shared.data_selection import selection_string_to_object z_select = selection_string_to_object(z) # Convert the selection string to a python selection """EDIT_ME Specify the number of custom viewer_options you are going to provide for qslice""" current_objective_dimension = analysis_object['objectiveDim'][0] if current_objective_dimension == cls.dimension_index['imageDim']: num_custom_viewer_options = 1 else: num_custom_viewer_options = 2 # Expose the qslice viewer functionality of any data dependencies if viewer_option >= num_custom_viewer_options: return super(omsi_cx, cls).v_qslice(analysis_object, z, viewer_option=viewer_option-num_custom_viewer_options) elif viewer_option == 0 and current_objective_dimension == cls.dimension_index['imageDim']: informative_indices = analysis_object['infIndices'][z_select] cx_analysis_object = omsi_cx() cx_analysis_object.read_from_omsi_file(analysis_object=analysis_object, load_data=False, load_parameters=False, load_runtime_data=False) return cx_analysis_object['msidata'][:, :, informative_indices] elif viewer_option == 0 and current_objective_dimension == cls.dimension_index['pixelDim']: return analysis_object['levScores'][:] elif viewer_option == 1 and current_objective_dimension == cls.dimension_index['pixelDim']: return analysis_object['infIndices'][:] """EDIT_ME Define your custom qslice viewer options. Here you need to handle all the different behaviors that are custom to your analysis. Below a simple example. if viewer_option == 0 : dataset = anaObj[ 'my_output_data' ] #This is e.g, an output dataset of your analysis return dataset[ : , :, z_select ] elif viewer_option == 1 : ... """ return None
def v_qslice(cls, analysis_object, z, viewer_option=0): """Implement support for qslice URL requests for the viewer""" from omsi.shared.data_selection import selection_string_to_object if viewer_option == 0: dataset = analysis_object['ho'] z_select = selection_string_to_object(selection_string=z) data = dataset[:, :, z_select] return data elif viewer_option > 0: return super(omsi_nmf, cls).v_qslice(analysis_object, z, viewer_option-1)
def v_qslice(cls, analysis_object, z, viewer_option=0): """Implement support for qslice URL requests for the viewer""" from omsi.shared.data_selection import selection_string_to_object if viewer_option == 0: dataset = analysis_object['ho'] z_select = selection_string_to_object(selection_string=z) data = dataset[:, :, z_select] return data elif viewer_option > 0: return super(omsi_nmf, cls).v_qslice(analysis_object, z, viewer_option - 1)
def v_qspectrum(cls, analysis_object, x, y, viewer_option=0): """Implement support for qspectrum URL requests for the viewer""" from omsi.shared.data_selection import selection_string_to_object data = None custom_mz = None if viewer_option == 0: # Loadings dataset = analysis_object['ho'] x_select = selection_string_to_object(selection_string=x) y_select = selection_string_to_object(selection_string=y) if isinstance(x_select, list) and isinstance(y_select, list): # Load the full data if multiple lists are given for # the selection and let numpy handle the sub-selection data = dataset[:][x_select, y_select, :] else: data = dataset[x_select, y_select, :] custom_mz = None elif viewer_option > 0: return super(omsi_nmf, cls).v_qspectrum(analysis_object, x, y, viewer_option-1) return data, custom_mz
def v_qspectrum(cls, analysis_object, x, y, viewer_option=0): """Implement support for qspectrum URL requests for the viewer""" from omsi.shared.data_selection import selection_string_to_object data = None custom_mz = None if viewer_option == 0: # Loadings dataset = analysis_object['ho'] x_select = selection_string_to_object(selection_string=x) y_select = selection_string_to_object(selection_string=y) if isinstance(x_select, list) and isinstance(y_select, list): # Load the full data if multiple lists are given for # the selection and let numpy handle the sub-selection data = dataset[:][x_select, y_select, :] else: data = dataset[x_select, y_select, :] custom_mz = None elif viewer_option > 0: return super(omsi_nmf, cls).v_qspectrum(analysis_object, x, y, viewer_option - 1) return data, custom_mz
def v_qslice(cls, analysis_object, z, viewer_option=0): """Implement support for qslice URL requests for the viewer""" from omsi.shared.data_selection import selection_string_to_object if viewer_option == 0: dataset = analysis_object['npg_peak_cube_mz'] try: z_select = selection_string_to_object(selection_string=z) data = dataset[:, :, z_select] return data except: print "Global peak selection failed" return None elif viewer_option >= 0: return super(omsi_peakcube, cls).v_qslice(analysis_object, z, viewer_option - 1) else: return None
def get_data(self): """Get the data associated with the dependency. :returns: If a selection is applied and the dependency object supports array data load (e.g., h5py.Dataset, omsi_file_msidata), then the selected data will be loaded and returned as numpy array. Otherwise the ['omsi_object'] is returned. """ # Return preloaded data if available if self['_data'] is not None: return self['_data'] # Check if we can access the data object else: # Retrieve the data object if self['dataname']: data_object = self['omsi_object'][self['dataname']] # Ensure that the dependency can actually be resolved. E.g, if the data the dependency points to # is not ready yet then we may get a dependency back that points to the same object as we do, # which in turn could result in an endless recursion if isinstance(data_object, dependency_dict): if data_object['omsi_object'] is self['omsi_object']: return self else: data_object = self['omsi_object'] # Resolve any data seletions try: if self['selection'] is None: # data = data_object[:] # self['_data'] = data_object return data_object else: from omsi.shared.data_selection import selection_string_to_object current_selection = selection_string_to_object(self['selection']) if current_selection is not None: dict.__setitem__(self, '_data', data_object[current_selection]) else: raise ValueError('Invalid selection string') return self['_data'] except: raise import sys log_helper.error(__name__, "Application of data selection failed. " + str(sys.exc_info())) return data_object
def v_qslice(cls, analysis_object, z, viewer_option=0): """Implement support for qslice URL requests for the viewer""" from omsi.shared.data_selection import selection_string_to_object if viewer_option == 0: dataset = analysis_object['peak_cube'] try: z_select = selection_string_to_object(selection_string=z) data = dataset[:, :, z_select] return data except: log_helper.error(__name__, "Global peak selection failed. ") return None elif viewer_option >= 0: return super(omsi_findpeaks_global, cls).v_qslice(analysis_object, z, viewer_option-1) else: return None
def v_qslice(cls, analysis_object, z, viewer_option=0): """ Get 3D analysis dataset for which z-slices should be extracted for presentation in the OMSI viewer :param analysis_object: The omsi_file_analysis object for which slicing should be performed :param z: Selection string indicting which z values should be selected. :param viewer_option: If multiple default viewer behaviors are available for a given analysis then this option is used to switch between them. :returns: numpy array with the data to be displayed in the image slice viewer. Slicing will be performed typically like [:,:,zmin:zmax]. """ # Convert the z selection to a python selection from omsi.shared.data_selection import selection_string_to_object zselect = selection_string_to_object(z) # Convert the selection string to a python selection """EDIT_ME Specify the number of custom viewer_options you are going to provide for qslice""" num_custom_viewer_options = 0 # Expose the qslice viewer functionality of any data dependencies if viewer_option >= num_custom_viewer_options: return super(omsi_filter_by_mask, cls).v_qslice(analysis_object, z, viewer_option=viewer_option-num_custom_viewer_options) """ EDIT_ME Define your custom qslice viewer options. Here you need to handle all the different behaviors that are custom to your analysis. Below a simple example. if viewer_option == 0 : dataset = anaObj[ 'my_output_data' ] #This is e.g, an output dataset of your analysis return dataset[ : , :, zselect ] elif viewer_option == 1 : ... """ return None
def v_qslice(cls, analysis_object, z, viewer_option=0): """Implement support for qslice URL requests for the viewer""" from omsi.shared.data_selection import selection_string_to_object if viewer_option == 0: pl = analysis_object['npg_peaks_labels'] ll = analysis_object['npg_labels_list'] pai = analysis_object['npg_peaks_ArrayIndex'] pints = analysis_object['npg_peaks_Intensities'] z_select = selection_string_to_object(selection_string=z) dataset = cls.getnpgimage(pl, ll, pai, pints, z_select) try: return dataset[:, :] except: print "NPG peak selection failed" return None elif viewer_option >= 0: return super(omsi_npg, cls).v_qslice(analysis_object, z, viewer_option - 1) else: return None
def v_qslice(cls, analysis_object, z, viewer_option=0): """ Get 3D analysis dataset for which z-slices should be extracted for presentation in the OMSI viewer :param analysis_object: The omsi_file_analysis object for which slicing should be performed :param z: Selection string indicting which z values should be selected. :param viewer_option: If multiple default viewer behaviors are available for a given analysis then this option is used to switch between them. :returns: numpy array with the data to be displayed in the image slice viewer. Slicing will be performed typically like [:,:,zmin:zmax]. """ # Convert the z selection to a python selection from omsi.shared.data_selection import selection_string_to_object zselect = selection_string_to_object( z) # Convert the selection string to a python selection """EDIT_ME Specify the number of custom viewer_options you are going to provide for qslice""" num_custom_viewer_options = 0 # Expose the qslice viewer functionality of any data dependencies if viewer_option >= num_custom_viewer_options: return super(omsi_filter_by_mask, cls).v_qslice( analysis_object, z, viewer_option=viewer_option - num_custom_viewer_options) """ EDIT_ME Define your custom qslice viewer options. Here you need to handle all the different behaviors that are custom to your analysis. Below a simple example. if viewer_option == 0 : dataset = anaObj[ 'my_output_data' ] #This is e.g, an output dataset of your analysis return dataset[ : , :, zselect ] elif viewer_option == 1 : ... """ return None
def v_qslice(cls, analysis_object, z, viewer_option=0): """ Get 3D analysis dataset for which z-slices should be extracted for presentation in the OMSI viewer :param analysis_object: The omsi_file_analysis object for which slicing should be performed :param z: Selection string indicting which z values should be selected. :param viewer_option: If multiple default viewer behaviors are available for a given analysis then this option is used to switch between them. :returns: numpy array with the data to be displayed in the image slice viewer. Slicing will be performed typically like [:,:,zmin:zmax]. """ # Convert the z selection to a python selection from omsi.shared.data_selection import selection_string_to_object zselect = selection_string_to_object(z) # Convert the selection string to a python selection num_custom_viewer_options = 1 # Expose the qslice viewer functionality of any data dependencies if viewer_option >= num_custom_viewer_options: return super(omsi_mz_rebin, cls).v_qslice(analysis_object, z, viewer_option=viewer_option-num_custom_viewer_options) #Define your custom qslice viewer options. Here you need to handle all the different #behaviors that are custom to your analysis. Below a simple example. if viewer_option == 0: dataset = analysis_object['new_msidata'] return dataset[:, :, zselect] return None