def export_ascii(self, root_name, format='dat'): """ @summary: Exports the intensity matrix, retention time vector, and m/z vector to the ascii format By default, export_ascii("NAME") will create NAME.im.dat, NAME.rt.dat, and NAME.mz.dat where these are the intensity matrix, retention time vector, and m/z vector in tab delimited format. If format='csv', the files will be in the CSV format, named NAME.im.csv, NAME.rt.csv, and NAME.mz.csv. @param root_name: Root name for the output files @type root_name: StringType @return: none @rtype: NoneType @author: Milica Ng @author: Andrew Isaac @author: Vladimir Likic """ if not is_str(root_name): error("'root_name' is not a string") if format == 'dat': separator = " " extension = ".dat" elif format == 'csv': separator = "," extension = ".csv" else: error("unkown format '%s'. Only 'dat' or 'csv' supported" % format) # export 2D matrix of intensities vals = self.__intensity_matrix save_data(root_name+'.im'+extension, vals, sep=separator) # export 1D vector of m/z's, corresponding to rows of # the intensity matrix mass_list = self.__mass_list save_data(root_name+'.mz'+extension, mass_list, sep=separator) # export 1D vector of retention times, corresponding to # columns of the intensity matrix time_list = self.__time_list save_data(root_name+'.rt'+extension, time_list, sep=separator)
def export_ascii( self, root_name: PathLike, fmt: AsciiFiletypes = AsciiFiletypes.ASCII_DAT, ): """ Exports the intensity matrix, retention time vector, and m/z vector to the ascii format. By default, export_ascii("NAME") will create NAME.im.dat, NAME.rt.dat, and NAME.mz.dat where these are the intensity matrix, retention time vector, and m/z vector in tab delimited format. If ``format`` == ``<AsciiFiletypes.ASCII_CSV>``, the files will be in the CSV format, named NAME.im.csv, NAME.rt.csv, and NAME.mz.csv. :param root_name: Root name for the output files :param fmt: Format of the output file, either ``<AsciiFiletypes.ASCII_DAT>`` or ``<AsciiFiletypes.ASCII_CSV>`` :authors: Milica Ng, Andrew Isaac, Vladimir Likic, Dominic Davis-Foster (pathlib support) """ if not is_path(root_name): raise TypeError("'root_name' must be a string or a pathlib.Path object") root_name = prepare_filepath(root_name, mkdirs=True) fmt = AsciiFiletypes(fmt) if fmt is AsciiFiletypes.ASCII_DAT: separator = ' ' extension = "dat" elif fmt is AsciiFiletypes.ASCII_CSV: separator = ',' extension = "csv" # export 2D matrix of intensities vals = self._intensity_array save_data(f"{root_name}.im.{extension}", vals, sep=separator) # export 1D vector of m/z's, corresponding to rows of # the intensity matrix mass_list = self._mass_list save_data(f"{root_name}.mz.{extension}", mass_list, sep=separator) # export 1D vector of retention times, corresponding to # columns of the intensity matrix time_list = self._time_list save_data(f"{root_name}.rt.{extension}", time_list, sep=separator)
# IntensityMatrix # must build intensity matrix before accessing any intensity matrix methods. # default, float masses with interval (bin interval) of one from min mass print "default intensity matrix, bin interval = 1, boundary +/- 0.5" im = build_intensity_matrix(data) # # Saving data # # save the intensity matrix values to a file mat = im.get_matrix_list() print "saving intensity matrix intensity values..." save_data("output/im.dat", mat) # Export the entire IntensityMatrix as CSV. This will create # data.im.csv, data.mz.csv, and data.rt.csv where # these are the intensity matrix, retention time # vector, and m/z vector in the CSV format print "exporting intensity matrix data..." im.export_ascii("output/data") # Export the entire IntensityMatrix as LECO CSV. This is # useful for import into AnalyzerPro print "exporting intensity matrix data to LECO CSV format..." im.export_leco_csv("output/data_leco.csv") # # Import saved data