def test_read_group_info_file(self): wrongfiles = ["empty.txt", "wrongmatchedline.txt", "zerogroupline.txt", "matchedwrong.txt"] for file in wrongfiles: filepath = os.path.join(self.indir, file) self.assertRaises(inputcommon.FormatError, inputcommon.read_group_info, filepath) nomatched = os.path.join(self.indir, "nomatched.txt") grs, group2samples, is_matched = inputcommon.read_group_info(nomatched) g2s = {'group1': ['s1.1', 's1.2', 's1.3'], 'group2': ['s2.1'], 'group3': ['s3.1', 's3.2', 's3.3', 's3.4']} self.assertTrue(group2samples, g2s) self.assertTrue(not is_matched) matched = os.path.join(self.indir, "matchedcorrect.txt") grs, group2samples, is_matched = inputcommon.read_group_info(matched) g2s = {'group1': ['s1.1', 's1.2', 's1.3'], 'group2': ['s2.1', 's2.2', 's2.3'], 'group3': ['s3.1', 's3.2', 's3.3']} self.assertTrue(group2samples, g2s) self.assertTrue(is_matched) rep = os.path.join(self.indir, "repetitivenames.txt") grs, group2samples, is_matched = inputcommon.read_group_info(matched) self.assertTrue(group2samples, g2s) self.assertTrue(is_matched)
def main(): matrixfile = sys.argv[1] g2sfile = sys.argv[2] outdir = sys.argv[3] # read in matrix: r2c2count = read_matrix(matrixfile) # group info: groups, g2s, matched = read_group_info(g2sfile) pair2count = get_pair2count(r2c2count) # get distribution (draw dist and get outliers) lowpoint, uppoint = get_dist(pair2count, g2s, outdir) # re draw group comparison boxplot with lims: group_cmp(pair2count, g2s, lowpoint, uppoint, outdir) # draw heatmap: s2g = lcommon.get_val2key_1to1(g2s) s2color = dcommon.get_name2color_wtgroup(s2g.keys(), s2g, g2s) heatmap_file = os.path.join(outdir, "heatmap.pdf") names = [] for g, gnames in g2s.iteritems(): for n in gnames: if n in r2c2count: names.append(n) draw_heatmap(r2c2count, s2color, lowpoint, uppoint, heatmap_file, names)