Changeset 608 for mds-and-trees
- Timestamp:
- 09/01/16 17:01:37 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mds-and-trees/mds_plot.py
r607 r608 78 78 firstsquarecolumn=distances.shape[1]-minsize 79 79 distances = np.array([row[firstsquarecolumn:] for row in distances]) #this can only fix matrices with more columns than rows 80 print("Ma king itsquare:",distances.shape)80 print("Made the matrix square:",distances.shape) 81 81 82 82 #if the file has more columns than rows, assume the first extra column on the left of the square matrix has labels … … 93 93 94 94 variances = [np.var(embed[:,i]) for i in range(len(embed[0]))] 95 percent_variances= [sum(variances[:i+1])/sum(variances) for i in range(len(variances))]96 for i,pv in enumerate( percent_variances):95 variances_fraction = [sum(variances[:i+1])/sum(variances) for i in range(len(variances))] 96 for i,pv in enumerate(variances_fraction): 97 97 print("In",i+1,"dimensions:",pv) 98 98 … … 100 100 embed = np.asarray([embed[:,i] for i in range(dim)]).T 101 101 102 return embed 102 return embed, variances_fraction[dim-1] 103 103 104 104 105 def plot(coordinates, labels, dimensions, jitter=0, outname=""):105 def plot(coordinates, labels, dimensions, variance_fraction, jitter=0, outname=""): 106 106 fig = plt.figure() 107 107 … … 138 138 139 139 140 plt.title('P henotypes distances') #TODO add % variance information140 plt.title('Projection of phenotype distances, variance preserved = %.1f%%' % (variance_fraction*100)) 141 141 plt.tight_layout() 142 142 plt.axis('tight') … … 151 151 def main(filename, dimensions=3, outname="", jitter=0, separator='\t'): 152 152 distances,labels = read_file(filename, separator) 153 embed = compute_mds(distances, dimensions)153 embed,variance_fraction = compute_mds(distances, dimensions) 154 154 155 155 if dimensions == 1: 156 156 embed = np.array([np.insert(e, 0, 0, axis=0) for e in embed]) 157 157 158 plot(embed, labels, dimensions, jitter, outname)158 plot(embed, labels, dimensions, variance_fraction, jitter, outname) 159 159 160 160
Note: See TracChangeset
for help on using the changeset viewer.