Changeset 607
- Timestamp:
- 09/01/16 16:39:23 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mds-and-trees/mds_plot.py
r604 r607 72 72 if (distances.shape[0]!=distances.shape[1]): 73 73 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]): 74 77 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 76 80 print("Making it square:",distances.shape) 77 81 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')]) 80 84 labels = [label[0].decode("utf-8") for label in labels] 81 e xcept ValueError:85 else: 82 86 labels = None #no labels 83 87 … … 116 120 if labels is not None and dimensions==2: 117 121 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 IDs122 labelconvert={'velland':'V','velwat':'W','vpp':'P','vpa':'A'} #use this if you want to replace long names with short IDs 119 123 #for point in points: 120 124 # print(point) … … 134 138 135 139 136 plt.title('Phenotypes distances') 140 plt.title('Phenotypes distances') #TODO add % variance information 137 141 plt.tight_layout() 138 142 plt.axis('tight') … … 140 144 if outname == "": 141 145 plt.show() 142 143 146 else: 144 147 plt.savefig(outname+".pdf") … … 159 162 parser = argparse.ArgumentParser() 160 163 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)') 162 165 parser.add_argument('--dim', required=False, help='number of dimensions of the new space') 163 166 parser.add_argument('--sep', required=False, help='separator of the source file')
Note: See TracChangeset
for help on using the changeset viewer.