Пример #1
0
  def write_plots (self, plot_file_base, out, show_labels=True, point_style='bo') :
    """
    Write a set of six PNG images representing the plots for each residue type.

    :param plot_file_base: file name prefix
    :param out: log filehandle
    """
    print >> out, ""
    print >> out, "Creating images of plots..."
    for pos in range(6) :
      stats = utils.get_rotarama_data(
        pos_type=res_types[pos],
        convert_to_numpy_array=True)
      file_label = res_type_labels[pos].replace("/", "_")
      plot_file_name = plot_file_base + "_rama_%s.png" % file_label
      points, coords = self.get_plot_data(position_type=pos)
      draw_ramachandran_plot(
        points=points,
        rotarama_data=stats,
        position_type=pos,
        title=format_ramachandran_plot_title(pos, '*'),
        file_name=plot_file_name,
        show_labels=show_labels,
        point_style=point_style)
      print >> out, "  wrote %s" % plot_file_name
Пример #2
0
 def get_plots(self,
               show_labels=True,
               point_style='bo',
               markersize=10,
               markeredgecolor="black",
               dpi=100,
               markerfacecolor="white",
               show_filling=True,
               show_contours=True):
     """
 Create a dictionary of six PNG images representing the plots for each residue type.
 :param out: log filehandle
 """
     result = {}
     for pos in range(6):
         stats = utils.get_rotarama_data(pos_type=res_types[pos],
                                         convert_to_numpy_array=True)
         points, coords = self.get_plot_data(position_type=pos)
         result[pos] = draw_ramachandran_plot(
             points=points,
             rotarama_data=stats,
             position_type=pos,
             title=format_ramachandran_plot_title(pos, '*'),
             show_labels=show_labels,
             markeredgecolor=markeredgecolor,
             markerfacecolor=markerfacecolor,
             show_filling=show_filling,
             show_contours=show_contours,
             point_style=point_style,
             markersize=markersize)
     return result
Пример #3
0
 def draw_plot(self):
     stats = utils.get_rotarama_data(pos_type='general', convert_to_numpy_array=True)
     residue_name = 'GLN'
     points, coords = graphics.get_residue_rotamer_data(rotalyze_data=self.rotalyze_data,
                                                        residue_name=self.residue_name,
                                                        point_type=self.point_type)
     
     self.plot.draw_plot(
                  stats=stats,
                  title="Chi1-Chi2 plot for %s" % self.residue_name,
                  points=points,
                  xyz=coords,
                  colormap="Blues",
                  contours=None)
     
     if self.canvas is not None:
         self.canvas.draw()
Пример #4
0
 def draw_plot(self):
     stats = utils.get_rotarama_data(pos_type='general', convert_to_numpy_array=True)
     points, coords = graphics.get_residue_ramachandran_data(ramalyze_data=self.ramalyze_data,
                                                             position_type=self.pos_type,
                                                             residue_name=self.residue_name,
                                                             point_type=self.point_type)
     
     title = graphics.format_ramachandran_plot_title(self.pos_type, self.residue_name)
     self.plot.draw_plot(
                         stats=stats,
                         title=title,
                         points=points,
                         xyz=coords,
                         colormap="Blues",
                         contours=[0.1495, 0.376])
     
     if self.canvas is not None:
         self.canvas.draw()
Пример #5
0
  def write_plots (self, plot_file_base, out) :
    """
    Write a set of six PNG images representing the plots for each residue type.

    :param plot_file_base: file name prefix
    :param out: log filehandle
    """
    print >> out, ""
    print >> out, "Creating images of plots..."
    for pos in range(6) :
      stats = utils.get_rotarama_data(
        pos_type=res_types[pos],
        convert_to_numpy_array=True)
      file_label = res_type_labels[pos].replace("/", "_")
      plot_file_name = plot_file_base + "_rama_%s.png" % file_label
      points, coords = self.get_plot_data(position_type=pos)
      draw_ramachandran_plot(
        points=points,
        rotarama_data=stats,
        position_type=pos,
        title=format_ramachandran_plot_title(pos, '*'),
        file_name=plot_file_name)
      print >> out, "  wrote %s" % plot_file_name
Пример #6
0
  def get_plots(self):
    '''
    Draw plots from data in pickle file
    '''
    if self.json_data['success_composition'] is False:
      return
    make_sub_header('Making plots', out=self.logger)
    self.save_json()
    success = True

    root = os.path.join(self.dest_dir)

    # B factor histogram
    print('Plotting B-factor histogram.', file=self.logger)
    bfactor_hist_fn = os.path.join(root, self.pdb_code + '_bfactor_hist.svg')
    try:
      rerefine_plots.plot_b_histogram(
        histogram = self.pickle_data.adp_hist,
        r_histogram = self.pickle_data.r_adp_hist,
        filename = bfactor_hist_fn,
        log = self.logger)
    except Exception as e:
      success = False
      msg = traceback.format_exc()
      print(msg, file=self.logger)
    if (os.path.isfile(bfactor_hist_fn)):
      self.json_data['plot_bfactor_hist'] = bfactor_hist_fn
    else:
      print('\tNo B-factor plot generated.', file=self.logger)

    # FSC plots
    d_inv     = self.pickle_data.d_inv
    fsc_model = self.pickle_data.fsc_model
    r_d_inv     = self.pickle_data.r_d_inv
    r_fsc_model = self.pickle_data.r_fsc_model

    min_reso = self.pickle_data.min_reso
    d_inv_half = self.pickle_data.d_inv_half
    fsc_half   = self.pickle_data.fsc_half

    print('Plotting FSC halfmaps', file=self.logger)
    filename = os.path.join(root, self.pdb_code + '_fsc_halfmaps.svg')
    try:
      rerefine_plots.plot_fsc(
          x1 = d_inv_half,
          y1 = fsc_half,
          x2 = None,
          y2 = None,
          figure_title = 'Fourier Shell Correlation (from half maps)',
          filename = filename,
          resolution = min_reso)
    except Exception as e:
      success = False
      msg = traceback.format_exc()
      print(msg, file=self.logger)
    if (os.path.isfile(filename)):
      self.json_data['plot_fsc_halfmaps'] = filename
    else:
      print('\tNo FSC halfmaps plot generated.', file=self.logger)

    print('Plotting FSC model', file=self.logger)
    filename = os.path.join(root, self.pdb_code + '_fsc_model.svg')
    try:
      rerefine_plots.plot_fsc(
          x1 = d_inv,
          y1 = fsc_model,
          x2 = r_d_inv,
          y2 = r_fsc_model,
          figure_title = 'Fourier Shell Correlation (Model vs Map)',
          filename = filename,
          resolution = min_reso,
          label1 = 'initial model',
          label2 = 'refined model')
    except Exception as e:
      success = False
      msg = traceback.format_exc()
      print(msg, file=self.logger)
    if (os.path.isfile(filename)):
      self.json_data['plot_fsc_model'] = filename
    else:
      print('\tNo FSC model plot generated', file=self.logger)

    # CC per chain
    print('Plotting CC per chain', file=self.logger)
    cc_per_chain_fn = os.path.join(root, self.pdb_code + '_cc_per_chain.svg')
    chains, chain_ccs, r_chains, r_chain_ccs = None, None, None, None
    if (self.pickle_data.cc_per_chain):
      chains, chain_ccs = [], []
      for arg1 in self.pickle_data.cc_per_chain:
        chains.append(arg1.chain_id)
        chain_ccs.append(arg1.cc)
      if (self.pickle_data.r_cc_per_chain):
        r_chains, r_chain_ccs = [], []
        for arg2 in self.pickle_data.r_cc_per_chain:
          r_chains.append(arg2.chain_id)
          r_chain_ccs.append(arg2.cc)
    try:
      rerefine_plots.plot_cc_chain(
          x1 = chains,
          y1 = chain_ccs,
          x2 = r_chains,
          y2 = r_chain_ccs,
          filename = cc_per_chain_fn)
    except Exception as e:
      success = False
      msg = traceback.format_exc()
      print(msg, file=self.logger)
    if (os.path.isfile(cc_per_chain_fn)):
      self.json_data['plot_cc_chain'] = cc_per_chain_fn
    else:
      print('\tNo CC per chain plot generated', file=self.logger)

    # CC per residue
    print('Saving ngl color scheme.', file=self.logger)
    if (self.pickle_data.cc_per_residue):
      self.ngl_color_scheme(
        property_list = self.pickle_data.cc_per_residue,
        json_key      = 'cc_color_scheme')
    if (self.pickle_data.r_cc_per_residue):
      self.ngl_color_scheme(
        property_list = self.pickle_data.r_cc_per_residue,
        json_key      = 'r_cc_color_scheme')

    file_list = []
    print('Plotting CC per residue.', file=self.logger)
    for chain in self.pickle_data.chain_dict:
      res, cc, r_res, r_cc = [], [], [], []
      if self.pickle_data.cc_per_residue:
        for item in self.pickle_data.cc_per_residue:
          if item.chain_id != chain: continue
          res.append(int(item.resseq))
          cc.append(item.cc)
      if self.pickle_data.r_cc_per_residue:
        for item in self.pickle_data.r_cc_per_residue:
          if item.chain_id != chain: continue
          r_res.append(int(item.resseq))
          r_cc.append(item.cc)
      filename = os.path.join(root, 'cc_per_residue_chain_' + chain + '.svg')
      #filename = 'cc_per_residue_chain_' + chain + '.png'
      title = 'CC per residue - chain %s' % chain
      print('Chain: ', chain, file=self.logger)
      try:
        rerefine_plots.plot_cc_residue(
          x1       = res,
          y1       = cc,
          x2       = r_res,
          y2       = r_cc,
          chain    = chain,
          filename = filename,
          title    = title)
      except Exception as e:
        success = False
        msg = traceback.format_exc()
        print(msg, file=self.logger)
      if (os.path.isfile(filename)):
        file_list.append(filename)
    self.json_data['plot_cc_residue'] = file_list
    if not file_list:
      print('\tNo CC per residue plots generated', file=self.logger)

    # Ramachandran plots
    print('Making Ramachandran plot', file=self.logger)
    for p, rl in zip(['', 'r_'],
      [self.pickle_data.ramalyze, self.pickle_data.r_ramalyze]):
      if rl is None: continue
      rama_fn = os.path.join(root, self.pdb_code + '_' +p + 'rama.png')
      rama_plot = ramachandran_plot()
      # Just copy from ramalyze etc. but where do these numbers come from?
      contours = [0.1495, 0.376]

#      stats = utils.get_rotarama_data(
#        pos_type='general',
#        convert_to_numpy_array=True)
#      # position type 0 is "general"
#      points, coords = rl.get_plot_data(position_type=0)
#      rama_plot.draw_plot(stats    = stats,
#                  points   = points,
#                  show_labels = False,
#                  title    = "Ramachandran plot for all non-Pro/Gly residues",
#                  colormap = "Blues",
#                  contours = contours)
#      rama_plot.save_image(
#        file_name = rama_fn,
#        dpi       = 72)
#      if (os.path.isfile(rama_fn)):
#        self.json_data['plot_' + p+'rama'] = rama_fn
#      else:
#        print('\tNo Ramachandran plot generated', file=self.logger)


      res_types = ["general", "glycine", "cis-proline", "trans-proline",
        "pre-proline", "isoleucine or valine"]
      positions = range(6)
      titles = ["general", "glycine", "cis_pro", "trans_pro", "pre_pro", "ile_val"]
      for res_type, pos, title in zip(res_types, positions, titles):
        stats = utils.get_rotarama_data(
          pos_type=res_type,
          convert_to_numpy_array=True)
        points, coords = rl.get_plot_data(position_type=pos)
        rama_plot.draw_plot(stats    = stats,
                    points   = points,
                    show_labels = False,
                    title    = "Ramachandran plot for all %s residues" % res_type,
                    colormap = "Blues",
                    contours = contours)
        if pos == 0:
          rama_fn = os.path.join(root, self.pdb_code + '_' +p + 'rama.png')
        else:
          rama_fn = os.path.join(root, self.pdb_code + '_' +p + 'rama_' + title + '.png')
        rama_plot.save_image(file_name = rama_fn, dpi = 150)
        if (os.path.isfile(rama_fn)):
          if pos == 0:
            self.json_data['plot_' + p +'rama'] = rama_fn
          else:
            self.json_data['plot_' + p +'rama_' + title] = rama_fn
        else:
          print('\tNo Ramachandran plot generated', file=self.logger)

    self.json_data['success_plots'] = success