def main(): fig, ax = plt.subplots(2, 2, figsize=(10, 10)) fig.tight_layout() data = -25 * make_test_data('hills', noise_factor=0.025) # secretly swapped :-) #data = -25 * make_test_data('circles', noise_factor=0.025) # secretly swapped :-) terrain = data assert terrain.shape == data.shape, "{} != {}".format( terrain.shape, data.shape) if '--bw' in sys.argv: # Only intensities blend_function = no_blending cmap = INTENSITY_CMAP # Don't auto scale the intensities, it gives the wrong impression norm = mpl.colors.Normalize(vmin=0.0, vmax=1.0) else: blend_function = rgb_blending cmap = plt.cm.get_cmap('gist_earth') norm = mpl.colors.Normalize() azimuths = [45, 135, 270] # North-East, North-West and South. elevations = [60] * len(azimuths) # Draw shading by separate light sources for idx, (azim, elev) in enumerate(zip(azimuths, elevations)): row = idx // 2 col = idx % 2 draw(ax[row, col], cmap=cmap, norm=norm, title='azim = {}, elev = {}'.format(azim, elev), image_data=hill_shade(data, terrain, blend_function=blend_function, ambient_weight=1, lamp_weight=5, cmap=cmap, norm=norm, azimuth=azim, elevation=elev)) # Draw shading by all light sources combined draw(ax[1, 1], cmap=cmap, norm=norm, title='combined'.format(azim, elev), image_data=hill_shade(data, terrain, blend_function=blend_function, ambient_weight=1, lamp_weight=[5, 5, 5], cmap=cmap, norm=norm, azimuth=azimuths, elevation=elevations)) plt.show()
def plot(self, plotdir, subset_by_gene=False, cyst_positions=None, tryp_positions=None): print ' plotting parameters' start = time.time() utils.prep_dir(plotdir + '/plots') #, multilings=('*.csv', '*.svg')) for column in self.counts: if column == 'all': continue values, gene_values = {}, {} if len(self.counts[column]) == 0: print 'ERROR no counts in %s' % column assert False for index, count in self.counts[column].iteritems(): gene = None if subset_by_gene and ('_del' in column or column == 'vd_insertion' or column == 'dj_insertion'): # option to subset deletion and (real) insertion plots by gene if '_del' in column: region = column[0] else: region = column[1] assert region in utils.regions assert 'IGH' + region.upper() in index[1] # NOTE this is hackey, but it works find now and will fail obviously gene = index[1] # if I ever change the correlations to be incompatible. so screw it if gene not in gene_values: gene_values[gene] = {} column_val = index[0] if gene is not None: if column_val not in gene_values[gene]: gene_values[gene][column_val] = 0.0 gene_values[gene][column_val] += count if column_val not in values: values[column_val] = 0.0 values[column_val] += count try: # figure out whether this is an integer or string (only used outside this loop when we make the plots) int(column_val) var_type = 'int' except: var_type = 'string' if subset_by_gene and ('_del' in column or column == 'vd_insertion' or column == 'dj_insertion'): # option to subset deletion and (real) insertion plots by gene thisplotdir = plotdir + '/' + column utils.prep_dir(thisplotdir + '/plots', multilings=['*.csv', '*.svg']) for gene in gene_values: plotname = utils.sanitize_name(gene) + '-' + column hist = plotting.make_hist_from_dict_of_counts(gene_values[gene], var_type, plotname, sort=True) plotting.draw(hist, var_type, plotname=plotname, plotdir=thisplotdir, errors=True, write_csv=True) check_call(['./bin/makeHtml', thisplotdir, '3', 'null', 'svg']) check_call(['./bin/permissify-www', thisplotdir]) # NOTE this should really permissify starting a few directories higher up plotname = column hist = plotting.make_hist_from_dict_of_counts(values, var_type, plotname, sort=True) plotting.draw(hist, var_type, plotname=plotname, plotdir=plotdir, errors=True, write_csv=True) self.mutefreqer.plot(plotdir, cyst_positions, tryp_positions) #, mean_freq_outfname=base_outdir + '/REGION-mean-mute-freqs.csv') # REGION is replace by each region in the three output files if has_root: check_call(['./bin/makeHtml', plotdir, '3', 'null', 'svg']) check_call(['./bin/permissify-www', plotdir]) # NOTE this should really permissify starting a few directories higher up print ' parameter plot time: %.3f' % (time.time()-start)
def plot(self, plotdir, subset_by_gene=False, cyst_positions=None, tryp_positions=None): print ' plotting parameters' # start = time.time() utils.prep_dir(plotdir + '/plots') #, multilings=('*.csv', '*.svg')) for column in self.counts: if column == 'all': continue values, gene_values = {}, {} if len(self.counts[column]) == 0: print 'ERROR no counts in %s' % column assert False for index, count in self.counts[column].iteritems(): gene = None if subset_by_gene and ('_del' in column or column == 'vd_insertion' or column == 'dj_insertion'): # option to subset deletion and (real) insertion plots by gene if '_del' in column: region = column[0] else: region = column[1] assert region in utils.regions assert 'IGH' + region.upper() in index[1] # NOTE this is hackey, but it works find now and will fail obviously gene = index[1] # if I ever change the correlations to be incompatible. so screw it if gene not in gene_values: gene_values[gene] = {} column_val = index[0] if gene is not None: if column_val not in gene_values[gene]: gene_values[gene][column_val] = 0.0 gene_values[gene][column_val] += count if column_val not in values: values[column_val] = 0.0 values[column_val] += count try: # figure out whether this is an integer or string (only used outside this loop when we make the plots) int(column_val) var_type = 'int' except: var_type = 'string' if subset_by_gene and ('_del' in column or column == 'vd_insertion' or column == 'dj_insertion'): # option to subset deletion and (real) insertion plots by gene thisplotdir = plotdir + '/' + column utils.prep_dir(thisplotdir + '/plots', multilings=['*.csv', '*.svg']) for gene in gene_values: plotname = utils.sanitize_name(gene) + '-' + column hist = plotting.make_hist_from_dict_of_counts(gene_values[gene], var_type, plotname, sort=True) plotting.draw(hist, var_type, plotname=plotname, plotdir=thisplotdir, errors=True, write_csv=True) check_call(['./bin/makeHtml', thisplotdir, '3', 'null', 'svg']) check_call(['./bin/permissify-www', thisplotdir]) # NOTE this should really permissify starting a few directories higher up plotname = column hist = plotting.make_hist_from_dict_of_counts(values, var_type, plotname, sort=True) plotting.draw(hist, var_type, plotname=plotname, plotdir=plotdir, errors=True, write_csv=True) self.mutefreqer.plot(plotdir, cyst_positions, tryp_positions) #, mean_freq_outfname=base_outdir + '/REGION-mean-mute-freqs.csv') # REGION is replace by each region in the three output files if has_root: check_call(['./bin/makeHtml', plotdir, '3', 'null', 'svg']) check_call(['./bin/permissify-www', plotdir]) # NOTE this should really permissify starting a few directories higher up
def main(): fig, ax = plt.subplots(2, 2, figsize=(10, 10)) fig.tight_layout() data = -25 * make_test_data('hills', noise_factor=0.025) # secretly swapped :-) #data = -25 * make_test_data('circles', noise_factor=0.025) # secretly swapped :-) terrain = data assert terrain.shape == data.shape, "{} != {}".format(terrain.shape, data.shape) if '--bw' in sys.argv: # Only intensities blend_function = no_blending cmap=INTENSITY_CMAP # Don't auto scale the intensities, it gives the wrong impression norm = mpl.colors.Normalize(vmin=0.0, vmax=1.0) else: blend_function = rgb_blending cmap = plt.cm.get_cmap('gist_earth') norm = mpl.colors.Normalize() azimuths = [45, 135, 270] # North-East, North-West and South. elevations = [60] * len(azimuths) # Draw shading by separate light sources for idx, (azim, elev) in enumerate(zip(azimuths, elevations)): row = idx // 2 col = idx % 2 draw(ax[row, col], cmap=cmap, norm=norm, title='azim = {}, elev = {}'.format(azim, elev), image_data = hill_shade(data, terrain, blend_function=blend_function, ambient_weight = 1, lamp_weight = 5, cmap=cmap, norm=norm, azimuth=azim, elevation=elev)) # Draw shading by all light sources combined draw(ax[1, 1], cmap=cmap, norm=norm, title='combined'.format(azim, elev), image_data = hill_shade(data, terrain, blend_function=blend_function, ambient_weight = 1, lamp_weight = [5, 5, 5], cmap=cmap, norm=norm, azimuth=azimuths, elevation=elevations)) plt.show()
def main(): fig, ax = plt.subplots(2, 2, figsize=(10, 10)) fig.tight_layout() data = make_test_data('circles') terrain = 10 * make_test_data('hills', noise_factor=0.05) assert terrain.shape == data.shape, "{} != {}".format(terrain.shape, data.shape) print("min data: {}".format(np.min(data))) print("max data: {}".format(np.max(data))) # Some color maps to try. #cmap = plt.cm.get_cmap('bwr') #cmap = plt.cm.get_cmap('CMRmap') #cmap = plt.cm.get_cmap('rainbow') #cmap = plt.cm.get_cmap('cool_r') cmap = plt.cm.get_cmap('Set1') # Optionally set the over and under flow colors. #cmap.set_bad('yellow') #cmap.set_over('cyan') #cmap.set_under('magenta') if ['--autoscale'] in sys.argv: print ("Auto scale legend") dnorm = mpl.colors.Normalize() else: dmin = 0 dmax = 10 print ("clip legend at ({}, {})".format(dmin, dmax)) dnorm = mpl.colors.Normalize(vmin=dmin, vmax=dmax) # Don't auto scale the intensities, it gives the wrong impression inorm = mpl.colors.Normalize(vmin=0.0, vmax=1.0) azimuth = DEF_AZIMUTH elevation = DEF_ELEVATION draw(ax[0, 0], cmap=plt.cm.gist_earth, title='Terrain height', image_data = terrain) draw(ax[0, 1], cmap=INTENSITY_CMAP, norm=inorm, title='Shaded terrain (azim = {}, elev = {})'.format(azimuth, elevation), image_data = hill_shade(terrain, blend_function=no_blending, azimuth=azimuth, elevation=elevation)) draw(ax[1, 0], cmap=cmap, norm=dnorm, title='Surface properties', image_data = data) draw(ax[1, 1], cmap=cmap, norm=dnorm, title='Shaded terrain with surface properties', image_data = hill_shade(data, terrain=terrain, azimuth=azimuth, elevation=elevation, cmap=cmap, norm=dnorm)) plt.show()
def plot(self, plotdir): utils.prep_dir(plotdir + '/plots', wildling=None, multilings=['*.csv', '*.svg', '*.root']) for column in self.values: if self.only_correct_gene_fractions and column not in bool_columns: continue if column in bool_columns: right = self.values[column]['right'] wrong = self.values[column]['wrong'] errs = fraction_uncertainty.err(right, right+wrong) print ' %s\n correct up to allele: %4d / %-4d = %4.4f (-%.3f, +%.3f)' % (column, right, right+wrong, float(right) / (right + wrong), errs[0], errs[1]) hist = plotting.make_bool_hist(right, wrong, self.name + '-' + column) plotting.draw(hist, 'bool', plotname=column, plotdir=plotdir, write_csv=True) else: # TODO this is dumb... I should make the integer-valued ones histograms as well hist = plotting.make_hist_from_dict_of_counts(self.values[column], 'int', self.name + '-' + column, normalize=True) log = '' if column.find('hamming_to_true_naive') >= 0: hist.GetXaxis().SetTitle('hamming distance') else: hist.GetXaxis().SetTitle('inferred - true') plotting.draw(hist, 'int', plotname=column, plotdir=plotdir, write_csv=True, log=log) for column in self.hists: hist = plotting.make_hist_from_my_hist_class(self.hists[column], column) plotting.draw(hist, 'float', plotname=column, plotdir=plotdir, write_csv=True, log=log) check_call(['./bin/makeHtml', plotdir, '3', 'null', 'svg']) check_call(['./bin/permissify-www', plotdir]) # NOTE this should really permissify starting a few directories higher up
def main(): fig, ax = plt.subplots(3, 4, figsize=(15, 10)) fig.tight_layout() #terrain = make_test_data('circles', noise_factor=0.0) terrain = make_test_data('hills', noise_factor=0.1) # Scale terrain. terrain *= 5 # Don't auto scale the intensities, it gives the wrong impression inorm = mpl.colors.Normalize(vmin=0.0, vmax=1.0) # Draw the terrain as color map draw(ax[0, 0], cmap=plt.cm.gist_earth, title='No shading', ticks=True, image_data = terrain) # Draw empty space ax[1, 0].set_axis_off() ax[2, 0].set_axis_off() cmap = INTENSITY_CMAP azim0_is_east = True # If true, azimuth 0 will correspond to east just as in our implementation azimuths = [45, 90, 135] #elev = 50 # At low elevation you will see still noise bumps in places that are completely in the shadows. # This may seem nice but it is incorrect. elev = 15 for idx, azim in enumerate(azimuths): col = idx + 1 draw(ax[0, col], cmap=cmap, norm=inorm, title="MPL normalized (azim = {}, elev = {})".format(azim, elev), image_data = mpl_surface_intensity(terrain, azimuth=azim, elevation=elev, azim0_is_east=azim0_is_east, normalize=True)) draw(ax[1, col], cmap=cmap, norm=inorm, title="MPL (azim = {}, elev = {})".format(azim, elev), image_data = mpl_surface_intensity(terrain, azimuth=azim, elevation=elev, azim0_is_east=azim0_is_east, normalize=False)) draw(ax[2, col], cmap=cmap, norm=inorm, title="Diffuse (azim = {}, elev = {})".format(azim, elev), image_data = relative_surface_intensity(terrain, azimuth=azim, elevation=elev)) plt.show()
def plot(self, base_plotdir, cyst_positions=None, tryp_positions=None): if not self.finalized: self.finalize() plotdir = base_plotdir + '/mute-freqs' utils.prep_dir(plotdir + '/plots', multilings=('*.csv', '*.svg')) for region in utils.regions: utils.prep_dir(plotdir + '/' + region + '/plots', multilings=('*.csv', '*.svg')) utils.prep_dir(plotdir + '/' + region + '-per-base/plots', multilings=('*.csv', '*.png')) for gene in self.counts: counts, plotting_info = self.counts[gene], self.plotting_info[gene] sorted_positions = sorted(counts) hist = TH1D('hist_' + utils.sanitize_name(gene), '', sorted_positions[-1] - sorted_positions[0] + 1, sorted_positions[0] - 0.5, sorted_positions[-1] + 0.5) for position in sorted_positions: hist.SetBinContent(hist.FindBin(position), counts[position]['freq']) hi_diff = abs(counts[position]['freq'] - counts[position]['freq_hi_err']) lo_diff = abs(counts[position]['freq'] - counts[position]['freq_lo_err']) err = 0.5*(hi_diff + lo_diff) hist.SetBinError(hist.FindBin(position), err) plotfname = plotdir + '/' + utils.get_region(gene) + '/plots/' + utils.sanitize_name(gene) + '.svg' xline = None if utils.get_region(gene) == 'v' and cyst_positions is not None: xline = cyst_positions[gene]['cysteine-position'] elif utils.get_region(gene) == 'j' and tryp_positions is not None: xline = int(tryp_positions[gene]) plotting.draw(hist, 'int', plotdir=plotdir + '/' + utils.get_region(gene), plotname=utils.sanitize_name(gene), errors=True, write_csv=True, xline=xline, draw_str='e') #, cwidth=4000, cheight=1000) paramutils.make_mutefreq_plot(plotdir + '/' + utils.get_region(gene) + '-per-base', utils.sanitize_name(gene), plotting_info) # for region in utils.regions: # utils.prep_dir(plotdir + '/' + region + '/tmp/plots', multilings=('*.csv', '*.svg')) # for gene in self.tmpcounts: # for position in self.tmpcounts[gene]: # roothist = plotting.make_hist_from_my_hist_class(self.tmpcounts[gene][position]['muted'], gene + '_' + str(position)) # plotting.draw(roothist, 'int', plotdir=plotdir + '/' + utils.get_region(gene) + '/tmp', plotname=utils.sanitize_name(gene) + '_' + str(position), errors=True, write_csv=True) #, cwidth=4000, cheight=1000) # make mean mute freq hists hist = plotting.make_hist_from_my_hist_class(self.mean_rates['all'], 'all-mean-freq') plotting.draw(hist, 'float', plotname='all-mean-freq', plotdir=plotdir, stats='mean', bounds=(0.0, 0.4), write_csv=True) for region in utils.regions: hist = plotting.make_hist_from_my_hist_class(self.mean_rates[region], region+'-mean-freq') plotting.draw(hist, 'float', plotname=region+'-mean-freq', plotdir=plotdir, stats='mean', bounds=(0.0, 0.4), write_csv=True) check_call(['./bin/makeHtml', plotdir, '3', 'null', 'svg']) # then write html file and fix permissiions for region in utils.regions: check_call(['./bin/makeHtml', plotdir + '/' + region, '1', 'null', 'svg']) check_call(['./bin/makeHtml', plotdir + '/' + region + '-per-base', '1', 'null', 'png']) check_call(['./bin/permissify-www', plotdir]) # NOTE this should really permissify starting a few directories higher up
def plot(self): for column in self.values: if column in bool_columns: right = self.values[column]['right'] wrong = self.values[column]['wrong'] print ' %s\n correct up to allele: %4d / %-4d = %4.2f' % (column, right, right+wrong, float(right) / (right + wrong)) hist = plotting.make_bool_hist(right, wrong, self.name + '-' + column) plotting.draw(hist, 'bool', plotname=column, plotdir=self.plotdir, write_csv=True) else: hist = plotting.make_hist_from_dict_of_counts(self.values[column], 'int', self.name + '-' + column, normalize=True) log = '' if column.find('hamming_to_true_naive') >= 0: hist.GetXaxis().SetTitle('hamming distance') else: hist.GetXaxis().SetTitle('inferred - true') plotting.draw(hist, 'int', plotname=column, plotdir=self.plotdir, write_csv=True, log=log) for column in self.hists: hist = plotting.make_hist_from_my_hist_class(self.hists[column], 'mute_freqs') plotting.draw(hist, 'float', plotname=column, plotdir=self.plotdir, write_csv=True, log=log) check_call(['./bin/makeHtml', self.plotdir, '3', 'null', 'svg']) check_call(['./bin/permissify-www', self.plotdir]) # NOTE this should really permissify starting a few directories higher up
def main(): fig, ax = plt.subplots(3, 2, figsize=(7, 10)) fig.tight_layout() if 1: # Same terrain and data. data = make_test_data('circles', noise_factor=0.05) * 2 - 7 terrain = data else: # Different terrain and data. Matplotlib hill shading can only show the data. data = make_test_data('hills') * -1 terrain = make_test_data('circles', noise_factor=0.05) * 2 assert terrain.shape == data.shape, "{} != {}".format(terrain.shape, data.shape) print("data range: {} {}".format(np.min(data), np.max(data))) if len(sys.argv) > 1: cmap_name = sys.argv[1] else: #cmap_name = 'copper' # from http://matplotlib.org/examples/pylab_examples/shading_example.html?highlight=codex%20shade #cmap_name = 'gist_earth' # works reasonably fine with all of them cmap_name = 'bwr' # shows that mpl & pegtop don't work when there is no increasing intensity #cmap_name = 'cubehelix' # shows that HSV blending does not work were color is black #cmap_name = 'rainbow' # shows that mpl & pegtop don't work when there is no increasing intensity #cmap_name = 'Paired_r' # is nice to inspect when the data is different from the terrain print ("Using colormap: {!r}".format(cmap_name)) cmap = plt.cm.get_cmap(cmap_name) cmap.set_bad('cyan') cmap.set_over('cyan') cmap.set_under('cyan') abs_max = np.max(np.abs(data)) # force color bar to be symmetrical. norm = mpl.colors.Normalize(vmin=-abs_max, vmax=abs_max) #norm = mpl.colors.Normalize(vmin=-2, vmax=3) draw(ax[0, 0], cmap=cmap, norm=norm, title='No shading', image_data = data) draw(ax[0, 1], cmap=plt.cm.gray, title='Matplotlib intensity', image_data = mpl_surface_intensity(terrain)) ls = LightSource(azdeg=DEF_AZIMUTH, altdeg=DEF_ELEVATION) draw(ax[1, 0], cmap=cmap, norm=norm, title='Matplotlib hill shading', image_data = ls.shade(data, cmap=cmap, norm=norm)) draw(ax[1, 1], cmap=cmap, norm=norm, title='Pegtop blending', image_data = mpl_hill_shade(data, terrain=terrain, cmap=cmap, norm=norm, blend_function=pegtop_blending)) draw(ax[2, 0], cmap=cmap, norm=norm, title='RGB blending', image_data = mpl_hill_shade(data, terrain=terrain, cmap=cmap, norm=norm, blend_function=rgb_blending)) draw(ax[2, 1], cmap=cmap, norm=norm, title='HSV blending', image_data = mpl_hill_shade(data, terrain=terrain, cmap=cmap, norm=norm, blend_function=hsv_blending)) plt.show()
def main(): fig, ax = plt.subplots(3, 2, figsize=(7, 10)) fig.tight_layout() if 1: # Same terrain and data. data = make_test_data('circles', noise_factor=0.05) * 2 - 7 terrain = data else: # Different terrain and data. Matplotlib hill shading can only show the data. data = make_test_data('hills') * -1 terrain = make_test_data('circles', noise_factor=0.05) * 2 assert terrain.shape == data.shape, "{} != {}".format( terrain.shape, data.shape) print("data range: {} {}".format(np.min(data), np.max(data))) if len(sys.argv) > 1: cmap_name = sys.argv[1] else: #cmap_name = 'copper' # from http://matplotlib.org/examples/pylab_examples/shading_example.html?highlight=codex%20shade #cmap_name = 'gist_earth' # works reasonably fine with all of them cmap_name = 'bwr' # shows that mpl & pegtop don't work when there is no increasing intensity #cmap_name = 'cubehelix' # shows that HSV blending does not work were color is black #cmap_name = 'rainbow' # shows that mpl & pegtop don't work when there is no increasing intensity #cmap_name = 'Paired_r' # is nice to inspect when the data is different from the terrain print("Using colormap: {!r}".format(cmap_name)) cmap = plt.cm.get_cmap(cmap_name) cmap.set_bad('cyan') cmap.set_over('cyan') cmap.set_under('cyan') abs_max = np.max(np.abs(data)) # force color bar to be symmetrical. norm = mpl.colors.Normalize(vmin=-abs_max, vmax=abs_max) #norm = mpl.colors.Normalize(vmin=-2, vmax=3) draw(ax[0, 0], cmap=cmap, norm=norm, title='No shading', image_data=data) draw(ax[0, 1], cmap=plt.cm.gray, title='Matplotlib intensity', image_data=mpl_surface_intensity(terrain)) ls = LightSource(azdeg=DEF_AZIMUTH, altdeg=DEF_ELEVATION) draw(ax[1, 0], cmap=cmap, norm=norm, title='Matplotlib hill shading', image_data=ls.shade(data, cmap=cmap, norm=norm)) draw(ax[1, 1], cmap=cmap, norm=norm, title='Pegtop blending', image_data=mpl_hill_shade(data, terrain=terrain, cmap=cmap, norm=norm, blend_function=pegtop_blending)) draw(ax[2, 0], cmap=cmap, norm=norm, title='RGB blending', image_data=mpl_hill_shade(data, terrain=terrain, cmap=cmap, norm=norm, blend_function=rgb_blending)) draw(ax[2, 1], cmap=cmap, norm=norm, title='HSV blending', image_data=mpl_hill_shade(data, terrain=terrain, cmap=cmap, norm=norm, blend_function=hsv_blending)) plt.show()
def cluster(self, input_scores=None, infname=None, debug=False, reco_info=None, outfile=None, plotdir=''): if infname is None: assert input_scores is not None else: assert input_scores is None # should only specify <input_scores> *or* <infname> input_scores = [] with opener('r')(infname) as infile: reader = csv.DictReader(infile) for line in reader: input_scores.append(line) sorted_lines = sorted(input_scores, key=lambda k: float(k['score'])) for line in sorted_lines: a_name = line['id_a'] b_name = line['id_b'] score = float(line['score']) from_same_event = -1 if (reco_info == None or a_name not in reco_info or b_name not in reco_info) else reco_info[a_name]['reco_id'] == reco_info[b_name]['reco_id'] dbg_str_list = ['%22s %22s %8.3f %d' % (a_name, b_name, score, from_same_event), ] self.incorporate_into_clusters(a_name, b_name, score, dbg_str_list) self.pairscores[(utils.get_key((a_name, b_name)))] = score self.plotscores['all'].append(score) if reco_info != None: if from_same_event: self.plotscores['same'].append(score) else: self.plotscores['diff'].append(score) # if reco_info != None and reco_info[a_name]['reco_id'] == reco_info[b_name]['reco_id']: # for query,score in {a_name:score, b_name:score}.iteritems(): # if query not in self.nearest_true_mate: # self.nearest_true_mate[query] = score # elif self.greater_than and score > self.nearest_true_mate[query]: # self.nearest_true_mate[query] = score # elif not self.greater_than and score < self.nearest_true_mate[query]: # self.nearest_true_mate[query] = score if debug: outstr = ''.join(dbg_str_list) if outfile == None: print outstr else: outfile.write(outstr + '\n') if plotdir != '': utils.prep_dir(plotdir + '/plots', '*.svg') hists = {} for htype in ['all', 'same', 'diff']: hists[htype] = plotting.make_hist_from_list(self.plotscores[htype], htype + '_pairscores') hists[htype].SetTitle(htype) plotting.draw(hists['all'], 'float', plotdir=plotdir, plotname='pairscores', more_hists=[hists['same'], hists['diff']]) check_call(['./bin/makeHtml', plotdir, '3', 'null', 'svg']) check_call(['./bin/permissify-www', plotdir]) for query, cluster_id in self.query_clusters.iteritems(): if cluster_id not in self.id_clusters: self.id_clusters[cluster_id] = [] self.id_clusters[cluster_id].append(query) for cluster_id, queries in self.id_clusters.items(): if len(queries) == 1: self.singletons.append(queries[0]) # print 'nearest',self.nearest_true_mate out_str_list = [' %d clusters:\n'%len(self.id_clusters), ] for cluster_id in self.id_clusters: out_str_list.append(' ' + ' '.join([str(x) for x in self.id_clusters[cluster_id]]) + '\n') if outfile == None: print ''.join(out_str_list) else: outfile.write(''.join(out_str_list))
def main(): fig, ax = plt.subplots(3, 4, figsize=(15, 10)) fig.tight_layout() #terrain = make_test_data('circles', noise_factor=0.0) terrain = make_test_data('hills', noise_factor=0.1) # Scale terrain. terrain *= 5 # Don't auto scale the intensities, it gives the wrong impression inorm = mpl.colors.Normalize(vmin=0.0, vmax=1.0) # Draw the terrain as color map draw(ax[0, 0], cmap=plt.cm.gist_earth, title='No shading', ticks=True, image_data=terrain) # Draw empty space ax[1, 0].set_axis_off() ax[2, 0].set_axis_off() cmap = INTENSITY_CMAP azim0_is_east = True # If true, azimuth 0 will correspond to east just as in our implementation azimuths = [45, 90, 135] #elev = 50 # At low elevation you will see still noise bumps in places that are completely in the shadows. # This may seem nice but it is incorrect. elev = 15 for idx, azim in enumerate(azimuths): col = idx + 1 draw(ax[0, col], cmap=cmap, norm=inorm, title="MPL normalized (azim = {}, elev = {})".format(azim, elev), image_data=mpl_surface_intensity(terrain, azimuth=azim, elevation=elev, azim0_is_east=azim0_is_east, normalize=True)) draw(ax[1, col], cmap=cmap, norm=inorm, title="MPL (azim = {}, elev = {})".format(azim, elev), image_data=mpl_surface_intensity(terrain, azimuth=azim, elevation=elev, azim0_is_east=azim0_is_east, normalize=False)) draw(ax[2, col], cmap=cmap, norm=inorm, title="Diffuse (azim = {}, elev = {})".format(azim, elev), image_data=relative_surface_intensity(terrain, azimuth=azim, elevation=elev)) plt.show()
def main(): fig, ax = plt.subplots(2, 2, figsize=(10, 10)) fig.tight_layout() data = make_test_data('circles') terrain = 10 * make_test_data('hills', noise_factor=0.05) assert terrain.shape == data.shape, "{} != {}".format( terrain.shape, data.shape) print("min data: {}".format(np.min(data))) print("max data: {}".format(np.max(data))) # Some color maps to try. #cmap = plt.cm.get_cmap('bwr') #cmap = plt.cm.get_cmap('CMRmap') #cmap = plt.cm.get_cmap('rainbow') #cmap = plt.cm.get_cmap('cool_r') cmap = plt.cm.get_cmap('Set1') # Optionally set the over and under flow colors. #cmap.set_bad('yellow') #cmap.set_over('cyan') #cmap.set_under('magenta') if ['--autoscale'] in sys.argv: print("Auto scale legend") dnorm = mpl.colors.Normalize() else: dmin = 0 dmax = 10 print("clip legend at ({}, {})".format(dmin, dmax)) dnorm = mpl.colors.Normalize(vmin=dmin, vmax=dmax) # Don't auto scale the intensities, it gives the wrong impression inorm = mpl.colors.Normalize(vmin=0.0, vmax=1.0) azimuth = DEF_AZIMUTH elevation = DEF_ELEVATION draw(ax[0, 0], cmap=plt.cm.gist_earth, title='Terrain height', image_data=terrain) draw(ax[0, 1], cmap=INTENSITY_CMAP, norm=inorm, title='Shaded terrain (azim = {}, elev = {})'.format( azimuth, elevation), image_data=hill_shade(terrain, blend_function=no_blending, azimuth=azimuth, elevation=elevation)) draw(ax[1, 0], cmap=cmap, norm=dnorm, title='Surface properties', image_data=data) draw(ax[1, 1], cmap=cmap, norm=dnorm, title='Shaded terrain with surface properties', image_data=hill_shade(data, terrain=terrain, azimuth=azimuth, elevation=elevation, cmap=cmap, norm=dnorm)) plt.show()
def plot(self, base_plotdir, cyst_positions=None, tryp_positions=None): if not self.finalized: self.finalize() plotdir = base_plotdir + '/mute-freqs' utils.prep_dir(plotdir + '/plots', multilings=('*.csv', '*.svg')) for region in utils.regions: utils.prep_dir(plotdir + '/' + region + '/plots', multilings=('*.csv', '*.svg')) utils.prep_dir(plotdir + '/' + region + '-per-base/plots', multilings=('*.csv', '*.png')) for gene in self.counts: counts, plotting_info = self.counts[gene], self.plotting_info[gene] sorted_positions = sorted(counts) hist = TH1D('hist_' + utils.sanitize_name(gene), '', sorted_positions[-1] - sorted_positions[0] + 1, sorted_positions[0] - 0.5, sorted_positions[-1] + 0.5) for position in sorted_positions: hist.SetBinContent(hist.FindBin(position), counts[position]['freq']) hi_diff = abs(counts[position]['freq'] - counts[position]['freq_hi_err']) lo_diff = abs(counts[position]['freq'] - counts[position]['freq_lo_err']) err = 0.5 * (hi_diff + lo_diff) hist.SetBinError(hist.FindBin(position), err) plotfname = plotdir + '/' + utils.get_region( gene) + '/plots/' + utils.sanitize_name(gene) + '.svg' xline = None if utils.get_region(gene) == 'v' and cyst_positions is not None: xline = cyst_positions[gene]['cysteine-position'] elif utils.get_region(gene) == 'j' and tryp_positions is not None: xline = int(tryp_positions[gene]) plotting.draw(hist, 'int', plotdir=plotdir + '/' + utils.get_region(gene), plotname=utils.sanitize_name(gene), errors=True, write_csv=True, xline=xline, draw_str='e') #, cwidth=4000, cheight=1000) paramutils.make_mutefreq_plot( plotdir + '/' + utils.get_region(gene) + '-per-base', utils.sanitize_name(gene), plotting_info) # make mean mute freq hists hist = plotting.make_hist_from_my_hist_class(self.mean_rates['all'], 'all-mean-freq') plotting.draw(hist, 'float', plotname='all-mean-freq', plotdir=plotdir, stats='mean', bounds=(0.0, 0.4), write_csv=True) for region in utils.regions: hist = plotting.make_hist_from_my_hist_class( self.mean_rates[region], region + '-mean-freq') plotting.draw(hist, 'float', plotname=region + '-mean-freq', plotdir=plotdir, stats='mean', bounds=(0.0, 0.4), write_csv=True) check_call(['./bin/makeHtml', plotdir, '3', 'null', 'svg']) # then write html file and fix permissiions for region in utils.regions: check_call( ['./bin/makeHtml', plotdir + '/' + region, '1', 'null', 'svg']) check_call([ './bin/makeHtml', plotdir + '/' + region + '-per-base', '1', 'null', 'png' ]) check_call( ['./bin/permissify-www', plotdir] ) # NOTE this should really permissify starting a few directories higher up