Ignore:
Timestamp:
09/01/16 16:39:23 (8 years ago)
Author:
Maciej Komosinski
Message:

Updated for new format of dissimilarity matrix (with the optional two extra columns on the left, compatible with Framsticks CLI and GUI)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mds-and-trees/mds_plot.py

    r604 r607  
    7272        if (distances.shape[0]!=distances.shape[1]):
    7373                print("Matrix is not square:",distances.shape)
     74        if (distances.shape[0]>distances.shape[1]):
     75                raise ValueError('More rows than columns?')
     76        if (distances.shape[0]<distances.shape[1]):
    7477                minsize = min(distances.shape[0],distances.shape[1])
    75                 distances = np.array([row[:minsize] for row in distances]) #this can only fix matrices with more columns than rows
     78                firstsquarecolumn=distances.shape[1]-minsize
     79                distances = np.array([row[firstsquarecolumn:] for row in distances]) #this can only fix matrices with more columns than rows
    7680                print("Making it square:",distances.shape)
    7781
    78         try: #maybe the file has more columns than rows, and the extra column has labels?
    79                 labels = np.genfromtxt(fname, delimiter=separator, usecols=distances.shape[0],dtype=[('label','S10')])
     82                #if the file has more columns than rows, assume the first extra column on the left of the square matrix has labels
     83                labels = np.genfromtxt(fname, delimiter=separator, usecols=firstsquarecolumn-1,dtype=[('label','S10')])
    8084                labels = [label[0].decode("utf-8") for label in labels]
    81         except ValueError:
     85        else:
    8286                labels = None #no labels
    8387       
     
    116120        if labels is not None and dimensions==2:
    117121                ax.scatter(*points, alpha=0.1) #barely visible points, because we will show labels anyway
    118                 labelconvert={'vel':'V','vpp':'P','vpa':'A'} #use this if you want to replace long names with short IDs
     122                labelconvert={'velland':'V','velwat':'W','vpp':'P','vpa':'A'} #use this if you want to replace long names with short IDs
    119123                #for point in points:
    120124                #       print(point)
     
    134138
    135139
    136         plt.title('Phenotypes distances')
     140        plt.title('Phenotypes distances') #TODO add % variance information
    137141        plt.tight_layout()
    138142        plt.axis('tight')
     
    140144        if outname == "":
    141145                plt.show()
    142 
    143146        else:
    144147                plt.savefig(outname+".pdf")
     
    159162        parser = argparse.ArgumentParser()
    160163        parser.add_argument('--in', dest='input', required=True, help='input file with dissimilarity matrix')
    161         parser.add_argument('--out', dest='output', required=False, help='output file name without extension')
     164        parser.add_argument('--out', dest='output', required=False, help='output file name (without extension)')
    162165        parser.add_argument('--dim', required=False, help='number of dimensions of the new space')
    163166        parser.add_argument('--sep', required=False, help='separator of the source file')
Note: See TracChangeset for help on using the changeset viewer.