Esempio n. 1
0
    def plot_cm(ecs, output_file=None):
        """
        Simple wrapper for contact map plotting
        """
        with misc.plot_context("Arial"):
            fig = plt.figure(figsize=(8, 8))
            if kwargs["scale_sizes"]:
                ecs = ecs.copy()
                ecs.loc[:, "size"] = ecs.cn.values / ecs.cn.max()

            pairs.plot_contact_map(
                ecs,
                d_intra,
                d_multimer,
                distance_cutoff=kwargs["distance_cutoff"],
                show_secstruct=kwargs["draw_secondary_structure"],
                margin=5,
                boundaries=kwargs["boundaries"])

            plt.suptitle("{} evolutionary couplings".format(len(ecs)),
                         fontsize=14)

            if output_file is not None:
                plt.savefig(output_file, bbox_inches="tight")
                plt.close(fig)
Esempio n. 2
0
    def plot_cm(ecs, output_file=None):
        """
        Simple wrapper for contact map plotting
        """
        with misc.plot_context("Arial"):
            fig = plt.figure(figsize=(10, 10))
            if kwargs["scale_sizes"]:
                ecs = ecs.copy()
                ecs.loc[:, "size"] = ecs.score.values / ecs.score.max()
                # avoid negative sizes
                ecs.loc[ecs["size"] < 0, "size"] = 0

            # draw PDB structure and alignment/EC coverage information on contact map if selected
            # (for now, not a required parameter, default to True)
            if kwargs.get("draw_coverage", True):
                additional_plot_kwargs = {
                    "show_structure_coverage": True,
                    "margin": 0,
                    "ec_coverage": ec_table,
                }
            else:
                additional_plot_kwargs = {
                    "show_structure_coverage": False,
                    "margin": 5,
                    "ec_coverage": None,
                }

            pairs.plot_contact_map(
                ecs,
                d_intra,
                d_multimer,
                distance_cutoff=kwargs["distance_cutoff"],
                show_secstruct=kwargs["draw_secondary_structure"],
                boundaries=kwargs["boundaries"],
                **additional_plot_kwargs)

            # print PDB information if selected as parameter
            # (for now, not a required parameter, default to True)
            if kwargs.get("print_pdb_information",
                          True) and sifts_map is not None and len(
                              sifts_map.hits) > 0:
                print_pdb_structure_info(
                    sifts_map,
                    ax=plt.gca(),
                    header_text="PDB structures:",
                )

            plt.suptitle("{} evolutionary couplings".format(len(ecs)),
                         fontsize=14)

            if output_file is not None:
                plt.savefig(output_file, bbox_inches="tight")
                plt.close(fig)
Esempio n. 3
0
    def plot_complex_cm(ecs_i,
                        ecs_j,
                        ecs_inter,
                        first_segment_name,
                        second_segment_name,
                        output_file=None):
        """
        Simple wrapper for contact map plotting
        """
        with misc.plot_context("Arial"):
            if kwargs["scale_sizes"]:
                # to scale sizes, combine all ecs to rescale together
                ecs = pd.concat([ecs_i, ecs_j, ecs_inter])
                ecs.loc[:, "size"] = ecs.cn.values / ecs.cn.max()

                # split back into three separate DataFrames
                ecs_i = ecs.query(
                    "segment_i == segment_j == @first_segment_name")
                ecs_j = ecs.query(
                    "segment_i == segment_j == @second_segment_name")
                ecs_inter = ecs.query("segment_i != segment_j")

                # if any of these groups are entry, replace with None
                if len(ecs_i) == 0:
                    ecs_i = None
                if len(ecs_j) == 0:
                    ecs_j = None
                if len(ecs_inter) == 0:
                    ecs_inter = None

            # Currently, we require at least one of the monomer
            # to have either ECs or distances in order to make a plot
            if ((ecs_i is None or ecs_i.empty) and d_intra_i is None and d_multimer_i is None) \
                    or ((ecs_j is None or ecs_j.empty) and d_intra_j is None and d_multimer_i is None):
                return False

            fig = plt.figure(figsize=(8, 8))

            # create the contact map
            pairs.complex_contact_map(ecs_i,
                                      ecs_j,
                                      ecs_inter,
                                      d_intra_i,
                                      d_multimer_i,
                                      d_intra_j,
                                      d_multimer_j,
                                      d_inter,
                                      margin=5,
                                      boundaries=kwargs["boundaries"],
                                      scale_sizes=kwargs["scale_sizes"])

            # Add title to the plot
            if ecs_inter is None:
                ec_len = '0'
            else:
                ec_len = len(ecs_inter)
            plt.suptitle(
                "{} inter-molecule evolutionary couplings".format(ec_len),
                fontsize=14)

            # save to output
            if output_file is not None:
                plt.savefig(output_file, bbox_inches="tight")
                plt.close(fig)

            return True