Added function to save fluents tab separated values (ftsv) files.
This commit is contained in:
		@@ -383,6 +383,36 @@ class Selection(dict):
 | 
			
		||||
        self[axis] = labels
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
def write_ftsv(fd, ds):
 | 
			
		||||
    # Write header information
 | 
			
		||||
    if isinstance(ds, CategoryDataset):
 | 
			
		||||
        type = 'category'
 | 
			
		||||
    elif isinstance(ds, GraphDataset):
 | 
			
		||||
        type = 'network'
 | 
			
		||||
    elif isinstance(ds, Dataset):
 | 
			
		||||
        type = 'dataset'
 | 
			
		||||
    else:
 | 
			
		||||
        raise Exception("Unknown object")
 | 
			
		||||
    print >> fd, "# type: %s" % type
 | 
			
		||||
 | 
			
		||||
    for dim in ds.get_dim_name():
 | 
			
		||||
        print >> fd, "# dimension: %s" % dim,
 | 
			
		||||
        for id in ds.get_identifiers(dim, None, True):
 | 
			
		||||
            print >> fd, id,
 | 
			
		||||
        print >> fd
 | 
			
		||||
 | 
			
		||||
    print >> fd, "# name: %s" % ds.get_name()
 | 
			
		||||
    print >> fd
 | 
			
		||||
 | 
			
		||||
    # Write data
 | 
			
		||||
    m = ds.asarray()
 | 
			
		||||
    y, x = m.shape
 | 
			
		||||
    for j in range(y):
 | 
			
		||||
        for i in range(x):
 | 
			
		||||
            print >> fd, "%s\t" % m[j, i], 
 | 
			
		||||
        print >> fd
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def read_ftsv(fd):
 | 
			
		||||
    split_re = re.compile('^#\s*(\w+)\s*:\s*(.+)')
 | 
			
		||||
    dimensions = []
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user