def renderTransCPData(self, fileName="", show=True, elev=45, azim=45, all=False, showAxis=False, primaryWidth=12, primarySpace=3, dpi=300, format='png', fig=None, highlight=None, restrictedBids=[], alpha=1, ignoreContigLengths=False): """Plot transformed data in 3D""" del_fig = False if(fig is None): fig = plt.figure() del_fig = True else: plt.clf() if(all): myAXINFO = { 'x': {'i': 0, 'tickdir': 1, 'juggled': (1, 0, 2), 'color': (0, 0, 0, 0, 0)}, 'y': {'i': 1, 'tickdir': 0, 'juggled': (0, 1, 2), 'color': (0, 0, 0, 0, 0)}, 'z': {'i': 2, 'tickdir': 0, 'juggled': (0, 2, 1), 'color': (0, 0, 0, 0, 0)}, } ax = fig.add_subplot(131, projection='3d') sc = ax.scatter(self.transformedCP[:,0], self.transformedCP[:,1], self.transformedCP[:,2], edgecolors='k', c=self.contigGCs, cmap=self.colorMapGC, vmin=0.0, vmax=1.0, marker='.') sc.set_edgecolors = sc.set_facecolors = lambda *args:None # disable depth transparency effect ax.azim = 0 ax.elev = 0 ax.set_xlim3d(0,self.scaleFactor) ax.set_ylim3d(0,self.scaleFactor) ax.set_zlim3d(0,self.scaleFactor) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_zticklabels([]) ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) for axis in ax.w_xaxis, ax.w_yaxis, ax.w_zaxis: for elt in axis.get_ticklines() + axis.get_ticklabels(): elt.set_visible(False) ax.w_xaxis._AXINFO = myAXINFO ax.w_yaxis._AXINFO = myAXINFO ax.w_zaxis._AXINFO = myAXINFO ax = fig.add_subplot(132, projection='3d') sc = ax.scatter(self.transformedCP[:,0], self.transformedCP[:,1], self.transformedCP[:,2], edgecolors='k', c=self.contigGCs, cmap=self.colorMapGC, vmin=0.0, vmax=1.0, marker='.') sc.set_edgecolors = sc.set_facecolors = lambda *args:None # disable depth transparency effect ax.azim = 90 ax.elev = 0 ax.set_xlim3d(0,self.scaleFactor) ax.set_ylim3d(0,self.scaleFactor) ax.set_zlim3d(0,self.scaleFactor) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_zticklabels([]) ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) for axis in ax.w_xaxis, ax.w_yaxis, ax.w_zaxis: for elt in axis.get_ticklines() + axis.get_ticklabels(): elt.set_visible(False) ax.w_xaxis._AXINFO = myAXINFO ax.w_yaxis._AXINFO = myAXINFO ax.w_zaxis._AXINFO = myAXINFO ax = fig.add_subplot(133, projection='3d') sc = ax.scatter(self.transformedCP[:,0], self.transformedCP[:,1], self.transformedCP[:,2], edgecolors='k', c=self.contigGCs, cmap=self.colorMapGC, vmin=0.0, vmax=1.0, marker='.') sc.set_edgecolors = sc.set_facecolors = lambda *args:None # disable depth transparency effect ax.azim = 0 ax.elev = 90 ax.set_xlim3d(0,self.scaleFactor) ax.set_ylim3d(0,self.scaleFactor) ax.set_zlim3d(0,self.scaleFactor) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_zticklabels([]) ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) for axis in ax.w_xaxis, ax.w_yaxis, ax.w_zaxis: for elt in axis.get_ticklines() + axis.get_ticklabels(): elt.set_visible(False) ax.w_xaxis._AXINFO = myAXINFO ax.w_yaxis._AXINFO = myAXINFO ax.w_zaxis._AXINFO = myAXINFO else: ax = fig.add_subplot(111, projection='3d') if len(restrictedBids) == 0: if highlight is None: print "BF:", np_shape(self.transformedCP) if ignoreContigLengths: sc = ax.scatter(self.transformedCP[:,0], self.transformedCP[:,1], self.transformedCP[:,2], edgecolors='none', c=self.contigGCs, cmap=self.colorMapGC, s=10., vmin=0.0, vmax=1.0, marker='.') else: sc = ax.scatter(self.transformedCP[:,0], self.transformedCP[:,1], self.transformedCP[:,2], edgecolors='none', c=self.contigGCs, cmap=self.colorMapGC, vmin=0.0, vmax=1.0, s=np_sqrt(self.contigLengths), marker='.') sc.set_edgecolors = sc.set_facecolors = lambda *args:None # disable depth transparency effect else: #draw the opaque guys first """ sc = ax.scatter(self.transformedCP[:,0], self.transformedCP[:,1], self.transformedCP[:,2], edgecolors='none', c=self.contigGCs, cmap=self.colorMapGC, vmin=0.0, vmax=1.0, s=100., marker='s', alpha=alpha) sc.set_edgecolors = sc.set_facecolors = lambda *args:None # disable depth transparency effect """ # now replot the highlighted guys disp_vals = np_array([]) disp_GCs = np_array([]) thrower = {} hide_vals = np_array([]) hide_GCs = np_array([]) num_points = 0 for bin in highlight: for row_index in bin.rowIndices: num_points += 1 disp_vals = np_append(disp_vals, self.transformedCP[row_index]) disp_GCs = np_append(disp_GCs, self.contigGCs[row_index]) thrower[row_index] = False # reshape disp_vals = np_reshape(disp_vals, (num_points, 3)) num_points = 0 for i in range(len(self.indices)): try: thrower[i] except KeyError: num_points += 1 hide_vals = np_append(hide_vals, self.transformedCP[i]) hide_GCs = np_append(hide_GCs, self.contigGCs[i]) # reshape hide_vals = np_reshape(hide_vals, (num_points, 3)) sc = ax.scatter(hide_vals[:,0], hide_vals[:,1], hide_vals[:,2], edgecolors='none', c=hide_GCs, cmap=self.colorMapGC, vmin=0.0, vmax=1.0, s=100., marker='s', alpha=alpha) sc.set_edgecolors = sc.set_facecolors = lambda *args:None # disable depth transparency effect sc = ax.scatter(disp_vals[:,0], disp_vals[:,1], disp_vals[:,2], edgecolors='none', c=disp_GCs, cmap=self.colorMapGC, vmin=0.0, vmax=1.0, s=10., marker='.') sc.set_edgecolors = sc.set_facecolors = lambda *args:None # disable depth transparency effect print np_shape(disp_vals), np_shape(hide_vals), np_shape(self.transformedCP) # render color bar cbar = plt.colorbar(sc, shrink=0.5) cbar.ax.tick_params() cbar.ax.set_title("% GC", size=10) cbar.set_ticks([0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]) cbar.ax.set_ylim([0.15, 0.85]) mungeCbar(cbar) else: r_trans = np_array([]) r_cols=np_array([]) num_added = 0 for i in range(len(self.indices)): if self.binIds[i] not in restrictedBids: r_trans = np_append(r_trans, self.transformedCP[i]) r_cols = np_append(r_cols, self.contigGCs[i]) num_added += 1 r_trans = np_reshape(r_trans, (num_added,3)) print np_shape(r_trans) #r_cols = np_reshape(r_cols, (num_added,3)) sc = ax.scatter(r_trans[:,0], r_trans[:,1], r_trans[:,2], edgecolors='none', c=r_cols, cmap=self.colorMapGC, s=10., vmin=0.0, vmax=1.0, marker='.') sc.set_edgecolors = sc.set_facecolors = lambda *args:None # disable depth transparency effect # render color bar cbar = plt.colorbar(sc, shrink=0.5) cbar.ax.tick_params() cbar.ax.set_title("% GC", size=10) cbar.set_ticks([0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]) cbar.ax.set_ylim([0.15, 0.85]) mungeCbar(cbar) ax.azim = azim ax.elev = elev ax.set_xlim3d(0,self.scaleFactor) ax.set_ylim3d(0,self.scaleFactor) ax.set_zlim3d(0,self.scaleFactor) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_zticklabels([]) ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) if(not showAxis): ax.set_axis_off() if(fileName != ""): try: if(all): fig.set_size_inches(3*primaryWidth+2*primarySpace,primaryWidth) else: fig.set_size_inches(primaryWidth,primaryWidth) plt.savefig(fileName,dpi=dpi,format=format) except: print "Error saving image",fileName, exc_info()[0] raise elif(show): try: plt.show() except: print "Error showing image", exc_info()[0] raise if del_fig: plt.close(fig) del fig
def renderTransCPData(self, fileName="", show=True, elev=45, azim=45, all=False, showAxis=False, primaryWidth=12, primarySpace=3, dpi=300, format='png', fig=None): """Plot transformed data in 3D""" del_fig = False if(fig is None): fig = plt.figure() del_fig = True else: plt.clf() if(all): myAXINFO = { 'x': {'i': 0, 'tickdir': 1, 'juggled': (1, 0, 2), 'color': (0, 0, 0, 0, 0)}, 'y': {'i': 1, 'tickdir': 0, 'juggled': (0, 1, 2), 'color': (0, 0, 0, 0, 0)}, 'z': {'i': 2, 'tickdir': 0, 'juggled': (0, 2, 1), 'color': (0, 0, 0, 0, 0)}, } ax = fig.add_subplot(131, projection='3d') ax.scatter(self.transformedCP[:,0], self.transformedCP[:,1], self.transformedCP[:,2], edgecolors=self.contigColours, c=self.contigColours, marker='.') ax.azim = 0 ax.elev = 0 ax.set_xlim3d(0,self.scaleFactor) ax.set_ylim3d(0,self.scaleFactor) ax.set_zlim3d(0,self.scaleFactor) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_zticklabels([]) ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) for axis in ax.w_xaxis, ax.w_yaxis, ax.w_zaxis: for elt in axis.get_ticklines() + axis.get_ticklabels(): elt.set_visible(False) ax.w_xaxis._AXINFO = myAXINFO ax.w_yaxis._AXINFO = myAXINFO ax.w_zaxis._AXINFO = myAXINFO ax = fig.add_subplot(132, projection='3d') ax.scatter(self.transformedCP[:,0], self.transformedCP[:,1], self.transformedCP[:,2], edgecolors=self.contigColours, c=self.contigColours, marker='.') ax.azim = 90 ax.elev = 0 ax.set_xlim3d(0,self.scaleFactor) ax.set_ylim3d(0,self.scaleFactor) ax.set_zlim3d(0,self.scaleFactor) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_zticklabels([]) ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) for axis in ax.w_xaxis, ax.w_yaxis, ax.w_zaxis: for elt in axis.get_ticklines() + axis.get_ticklabels(): elt.set_visible(False) ax.w_xaxis._AXINFO = myAXINFO ax.w_yaxis._AXINFO = myAXINFO ax.w_zaxis._AXINFO = myAXINFO ax = fig.add_subplot(133, projection='3d') ax.scatter(self.transformedCP[:,0], self.transformedCP[:,1], self.transformedCP[:,2], edgecolors=self.contigColours, c=self.contigColours, marker='.') ax.azim = 0 ax.elev = 90 ax.set_xlim3d(0,self.scaleFactor) ax.set_ylim3d(0,self.scaleFactor) ax.set_zlim3d(0,self.scaleFactor) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_zticklabels([]) ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) for axis in ax.w_xaxis, ax.w_yaxis, ax.w_zaxis: for elt in axis.get_ticklines() + axis.get_ticklabels(): elt.set_visible(False) ax.w_xaxis._AXINFO = myAXINFO ax.w_yaxis._AXINFO = myAXINFO ax.w_zaxis._AXINFO = myAXINFO else: ax = fig.add_subplot(111, projection='3d') ax.scatter(self.transformedCP[:,0], self.transformedCP[:,1], self.transformedCP[:,2], edgecolors='none', c=self.contigColours, s=2, marker='.') ax.azim = azim ax.elev = elev ax.set_xlim3d(0,self.scaleFactor) ax.set_ylim3d(0,self.scaleFactor) ax.set_zlim3d(0,self.scaleFactor) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_zticklabels([]) ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) if(not showAxis): ax.set_axis_off() if(fileName != ""): try: if(all): fig.set_size_inches(3*primaryWidth+2*primarySpace,primaryWidth) else: fig.set_size_inches(primaryWidth,primaryWidth) plt.savefig(fileName,dpi=dpi,format=format) except: print "Error saving image",fileName, exc_info()[0] raise elif(show): try: plt.show() except: print "Error showing image", exc_info()[0] raise if del_fig: plt.close(fig) del fig