def main(): # first read the data file pathname_in = sys.argv[1] X = util.file_to_comma_separated_matrix(pathname_in, has_headers=True) logging.debug('matrix size: ' + str(X.shape)) # now read the newick file pathname_in = sys.argv[2] fin = open(pathname_in) newick_string = fin.read() fin.close() ordered_indices = heatmap.get_newick_order(newick_string) logging.debug('newick order size: ' + str(len(ordered_indices))) # reorder the rows of the data file X = heatmap.get_permuted_rows(X, ordered_indices) # create the standardized data for drawing the small heatmap Z = khorr.get_standardized_matrix(X) # initialize the progress bar reduction = 100 npixels, remainder = divmod(len(X), reduction) if remainder: npixels += 1 pbar = progress.Bar((npixels*(npixels+1))/2) # show the small heatmap pathname_out = 'small.png' im = heatmap.get_reduced_heatmap_image(Z, reduction=reduction, pixel_callback=pbar.update) fout = open(pathname_out, 'wb') im.save(fout) fout.close() # finish the progress bar pbar.finish()
def do_slow_stuff(): # construct some random data p, n = 2600, 50 reduction = 13 # construct the downsampled heatmap of the correlation of the data X = np.random.random((p, n)) Z = khorr.get_standardized_matrix(X) color_function = gradient.correlation_to_rgb im = heatmap.get_reduced_heatmap_image(Z, color_function, reduction=reduction) fout = open('profile-test.png', 'wb') im.save(fout) fout.close()
def main(): start_time = time.time() filename = sys.argv[1] logging.debug('reading input lines') fin = open(filename) lines = fin.readlines() fin.close() logging.debug('converting input lines to data matrix') X = util.lines_to_comma_separated_matrix(lines, has_headers=True) logging.debug('standardizing the data matrix') Z = khorr.get_standardized_matrix(X) logging.debug('augmenting the data matrix') W = khorr.standardized_to_augmented_C(Z) end_time = time.time() print 'nseconds:', end_time - start_time print 'W.size:', W.size print 'W.itemsize:', W.itemsize print 'W.size * W.itemsize:', W.size * W.itemsize raw_input('kbye\n')
def main(): pathname_in = 'mmc-data-files/Starvation_Residual.TXT' X = util.file_to_comma_separated_matrix(pathname_in, has_headers=True) print X.shape # create the tree from the data root = treebuilder.build_tree(X) ordered_indices = root.ordered_labels() X = heatmap.get_permuted_rows(X, ordered_indices) # create the standardized data for drawing the small heatmap Z = khorr.get_standardized_matrix(X) # show the big heatmap pathname_out = 'big.png' color_function = gradient.correlation_to_rgb im = heatmap.get_heatmap_image(np.dot(Z, Z.T), color_function) fout = open(pathname_out, 'wb') im.save(fout) fout.close() # show the small heatmap pathname_out = 'small.png' im = heatmap.get_reduced_heatmap_image(Z, reduction=5) fout = open(pathname_out, 'wb') im.save(fout) fout.close()
def __init__(self, parent, npixels, data_filename, tree_filename, low_zoom_image_filename): """ @param parent: the parent frame @param npixels: larger for larger windows @param data_filename: the path to a csv file @param tree_filename: the path to a newick tree @param low_zoom_image_filename: the path to a low resolution image """ # save some args self.parent = parent # define some options self.npixels = npixels # create the tkinter image print 'creating the low resolution image...' raw_pil_image = Image.open(low_zoom_image_filename) low_zoom_pil_image = raw_pil_image.resize((self.npixels, self.npixels), Image.ANTIALIAS) low_zoom_image = ImageTk.PhotoImage(low_zoom_pil_image) # create the list of ordered gene names print 'creating the list of ordered gene names...' self.mtree_root = mtree.newick_file_to_mtree(tree_filename) names = get_gene_names(data_filename) ordered_gene_names = [names[row_index] for row_index in self.mtree_root.ordered_labels()] # create the standardized and sorted data matrix print 'creating the ordered correlation square root...' X = util.file_to_comma_separated_matrix(data_filename, has_headers=True) Z = khorr.get_standardized_matrix(X) Z = np.vstack(Z[row_index] for row_index in self.mtree_root.ordered_labels()) #Z = None # create the label to leaf map print 'creating the map from labels to leaves...' self.label_to_leaf = dict((tip.label, tip) for tip in self.mtree_root.ordered_tips()) # initialize the windows individually self._init_windows(low_zoom_image, Z, ordered_gene_names) # redo the layout of the windows self.repack() # initialize the connections among the windows self._connect_windows()