def readInDataToPlot(self, input_fname): """ 2009-5-20 add the column index into the column header for easy picking 2009-3-13 wrap the float conversion part into try...except to report what goes wrong 2009-3-13 """ reader = csv.reader(open(input_fname), delimiter=figureOutDelimiter(input_fname)) self.column_header=reader.next() for i in range(len(self.column_header)): self.column_header[i] = '%s %s'%(i, self.column_header[i]) no_of_cols = len(self.column_header) self.column_types = [str]*2 + [float]*(no_of_cols-2) self.column_editable_flag_ls = [True, True] + [False]*(no_of_cols-2) self.list_2d = [] for row in reader: float_part = row[2:] try: float_part = map(float, float_part) except: sys.stderr.write('Except type: %s\n'%repr(sys.exc_info())) traceback.print_exc() new_row = row[:2]+float_part self.list_2d.append(new_row) self.setupColumns(self.treeview_matrix) self.plotXY(self.ax, self.canvas, self.liststore, self.plot_title)
def run(self): """ 2008-09-10 in case chop the whole figure into blocks, swap col_block_index and row_block_index to make row first, column 2nd """ from SNP import read_data from utils import figureOutDelimiter, PassingData delimiter = figureOutDelimiter(self.input_fname) print delimiter header, row_label_ls1, row_label_ls2, data_matrix = read_data( self.input_fname, matrix_data_type=float, delimiter="\t" ) import numpy data_matrix = numpy.array(data_matrix) min_value = numpy.min(data_matrix) if self.min_value_non_negative and min_value < 0: min_value = 0 max_value = numpy.max(data_matrix) font = get_font(self.font_path, font_size=self.font_size) Value2Color.special_value2color[-2] = self.super_value_color value2color_func = lambda x: Value2Color.value2HSLcolor(x, min_value, max_value) im_legend = drawContinousLegend(min_value, max_value, self.no_of_ticks, value2color_func, font) fig_fname_prefix = os.path.splitext(self.fig_fname)[0] if self.split_legend_and_matrix: im_legend.save("%s_legend.png" % fig_fname_prefix) no_of_rows, no_of_cols = data_matrix.shape passParam = PassingData( value2color_func=value2color_func, im_legend=im_legend, font=font, split_legend_and_matrix=self.split_legend_and_matrix, no_grid=self.no_grid, ) if no_of_cols <= self.col_step_size: self._drawMatrix(data_matrix, row_label_ls1, header[2:], self.fig_fname, passParam) else: # split into blocks no_of_col_blocks = no_of_cols / self.col_step_size + 1 no_of_row_blocks = no_of_rows / self.row_step_size + 1 for i in range(no_of_col_blocks): col_start_index = i * self.col_step_size col_end_index = (i + 1) * self.col_step_size if col_start_index < no_of_cols: for j in range(no_of_row_blocks): row_start_index = j * self.row_step_size row_end_index = (j + 1) * self.row_step_size if row_start_index < no_of_rows: fig_fname = "%s_%s_%s.png" % (fig_fname_prefix, j, i) # row first, column 2nd self._drawMatrix( data_matrix[row_start_index:row_end_index, col_start_index:col_end_index], row_label_ls1[row_start_index:row_end_index], header[2 + col_start_index : 2 + col_end_index], fig_fname, passParam, )
def getProbeIntensityData(input_fname, data_type=numpy.float32): """ 2010-3-18 copied from CNVNormalize.get_input() 2009-10-28 switch the default data_type to numpy.float32 to save memory on 64bit machines 2009-9-28 add argument data_type to specify data type of data_matrix. default is numpy.float (numpy.float could be float32, float64, float128 depending on the architecture). numpy.double is also fine. 2009-5-18 become classmethod """ sys.stderr.write("Getting tiling probe intensity data from %s ..."%input_fname) import csv, subprocess reader = csv.reader(open(input_fname), delimiter=figureOutDelimiter(input_fname)) commandline = 'wc -l %s'%input_fname command_handler = subprocess.Popen(commandline, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE) stdout_content, stderr_content = command_handler.communicate() if stderr_content: sys.stderr.write('stderr of %s: %s \n'%(commandline, stderr_content)) no_of_rows = int(stdout_content.split()[0])-1 header = reader.next() no_of_cols = len(header)-3 data_matrix = numpy.zeros([no_of_rows, no_of_cols], data_type) probe_id_ls = [] chr_pos_ls = [] i=0 for row in reader: probe_id = row[0] probe_id_ls.append(probe_id) chr_pos_ls.append(tuple(row[-2:])) for j in range(1, 1+no_of_cols): data_matrix[i][j-1] = float(row[j]) i += 1 sys.stderr.write("Done.\n") return data_matrix, probe_id_ls, chr_pos_ls, header
def readInRawMatrixData(self, input_fname): """ 2009-3-13 """ delimiter = figureOutDelimiter(input_fname) self.header, self.strain_acc_list, self.category_list, self.data_matrix = read_data(input_fname, delimiter=delimiter)