Exemple #1
0
def save(dataset, destination=None, values=None):
    """
    Saves the dataset with the same name simultaneously in 3 different formats:
    
     - mat: matlab file
     - pickled dataset
     - TSV: tab-separated values
     
    """
    if destination is None:
        msg = ("Pick a name to save the dataset (without extension; '.mat', "
               "'.pickled' and '.tsv' will be appended")
        destination = ui.ask_saveas("Save Dataset", msg, [])
    
    if not destination:
        return
    
    destination = str(destination)
    if ui.test_targetpath(destination):
        msg_temp = "Writing: %r"
        dest = os.path.extsep.join((destination, 'pickled'))
        print msg_temp % dest
        pickle_data = {'design': dataset, 'values': values}
        with open(dest, 'w') as f:
            _pickle.dump(pickle_data, f)
        
        dest = os.path.extsep.join((destination, 'mat'))
        print msg_temp % dest
        export_mat(dataset, values, dest)
        
        dest = os.path.extsep.join((destination, 'tsv'))
        print msg_temp % dest
        dataset.export(dest)
Exemple #2
0
 def save_tsv(self, path=None, delimiter='\t', linesep='\r\n', fmt='%.15e'):
     """
     Saves the table as tab-separated values file. 
     
     :arg str delimiter: string that is placed between cells (default: tab).
     :arg str linesep: string that is placed in between lines.
     :arg str fmt: format string for representing numerical cells. 
         (see 'Python String Formatting Documentation <http://docs.python.org/library/stdtypes.html#string-formatting-operations>'_ )
         http://docs.python.org/library/stdtypes.html#string-formatting-operations
         
     """
     if not path:
         path = ui.ask_saveas(title = "Save Tab Separated Table",
                              message = "Please Pick a File Name",
                              ext = [("txt", "txt (tsv) file")])
     if ui.test_targetpath(path):
         ext = os.path.splitext(path)[1]
         if ext not in ['.tsv', '.txt']:
             path += '.txt'
         with open(path, 'w') as f:
             f.write(self.get_tsv(delimiter=delimiter, linesep=linesep, 
                                  fmt=fmt))