def _output(section, subsection, valuef, dtype): # fold change matrix matrix, row_headers = buildMatrix(results, valuef=valuef, dtype=dtype) outfile = getFileName(options, go=test_ontology, section=section, set='%s_all' % subsection) IOTools.write_matrix(outfile, matrix, row_headers, col_headers, row_header="category") outfile = getFileName(options, go=test_ontology, section=section, set='%s_alldesc' % subsection) IOTools.write_matrix( outfile, matrix, ["%s:%s" % (x, go2info[x].mDescription) for x in row_headers], col_headers, row_header="category")
def writeMatricesForSortOrder(features_per_interval, bins, foreground_track, control_tracks, shifted, sort_order): '''output one or more matrices for each sort sorder. For each sort order output the forerground. If there are additional controls and shifted section, output these as well The files will named: matrix_<track>_<sortorder> ''' if "name" in features_per_interval[0].interval: names = [x.interval.name for x in features_per_interval] else: names = list(map(str, list(range(1, len(features_per_interval) + 1)))) bins = ["%i" % x for x in bins] sort_order = re.sub("-", "_", sort_order) # write foreground IOTools.write_matrix( E.open_output_file("matrix_%s_%s.gz" % (foreground_track, sort_order)), [x.foreground.counts for x in features_per_interval], row_headers=names, col_headers=bins, row_header="name") # write controls for idx, track in enumerate(control_tracks): IOTools.write_matrix( E.open_output_file("matrix_%s_%s.gz" % (track, sort_order)), [x.controls[idx].counts for x in features_per_interval], row_headers=names, col_headers=bins, row_header="name") # write shifted matrix if shifted: IOTools.write_matrix( E.open_output_file("matrix_shift_%s.gz" % (sort_order)), [x.shifted.counts for x in features_per_interval], row_headers=names, col_headers=bins, row_header="name") # output a combined matrix if len(control_tracks) > 0 or shifted: rows = [] for row in features_per_interval: l = [row.foreground.counts] l.extend([row.controls[x].counts for x in range(len(control_tracks))]) if shifted: l.append(row.shifted.counts) rows.append(numpy.concatenate(l)) n = 1 + len(control_tracks) if shifted: n += 1 # make column names unique and make sure they can be sorted # lexicographically all_bins = [] for x in range(n): all_bins.extend(["%i:%s" % (x, b) for b in bins]) IOTools.write_matrix( E.open_output_file("matrix_sidebyside_%s.gz" % (sort_order)), rows, row_headers=names, col_headers=all_bins, row_header="name")