Esempio n. 1
0
    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,
                            )
Esempio n. 2
0
	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)