Example #1
0
    def _write_domain_sequence_file(self, protein_ids, protein_domain_defs,
                                    protein_sequences):
        """Write a fasta file containing target domain sequences."""
        sequence_seqrecords = []
        for protein_id, protein_domain_def, protein_sequence in zip(
                protein_ids, protein_domain_defs, protein_sequences):
            #
            sequence_id = "{}.{}".format(protein_id, protein_domain_def)
            domain_def = structure_tools.decode_domain_def(protein_domain_def,
                                                           merge=True,
                                                           return_string=False)
            seqrecord = SeqRecord(
                id=sequence_id,
                name=protein_id,
                seq=Seq(protein_sequence[domain_def[0] - 1:domain_def[1]]),
            )
            sequence_seqrecords.append(seqrecord)

        sequence_filename = "_".join(seqrec.id
                                     for seqrec in sequence_seqrecords)
        sequence_file = op.join(conf.CONFIGS["unique_temp_dir"],
                                sequence_filename + ".fasta")
        with open(sequence_file, "w") as ofh:
            SeqIO.write(sequence_seqrecords, ofh, "fasta")

        return sequence_file, sequence_seqrecords
Example #2
0
    def _write_domain_sequence_file(self, protein_ids, protein_domain_defs, protein_sequences):
        """Write a fasta file containing target domain sequences."""
        sequence_seqrecords = []
        for protein_id, protein_domain_def, protein_sequence in zip(
            protein_ids, protein_domain_defs, protein_sequences
        ):
            #
            sequence_id = "{}.{}".format(protein_id, protein_domain_def)
            domain_def = structure_tools.decode_domain_def(protein_domain_def, merge=True, return_string=False)
            seqrecord = SeqRecord(
                id=sequence_id, name=protein_id, seq=Seq(protein_sequence[domain_def[0] - 1 : domain_def[1]])
            )
            sequence_seqrecords.append(seqrecord)

        sequence_filename = "_".join(seqrec.id for seqrec in sequence_seqrecords)
        sequence_file = op.join(conf.CONFIGS["unique_temp_dir"], sequence_filename + ".fasta")
        with open(sequence_file, "w") as ofh:
            SeqIO.write(sequence_seqrecords, ofh, "fasta")

        return sequence_file, sequence_seqrecords
Example #3
0
    def get_mutation_data(self):
        """"""
        d = self.d
        uniprot_id_1 = self.uniprot_id
        mutation = self.mutation

        if isinstance(d, elaspic_database.UniprotDomain):
            logger.debug("Analyzing core mutation for uniprot: %s" %
                         uniprot_id_1)
            logger.debug("model_domain_def: {}".format(
                d.template.model.model_domain_def))
            domain_start, domain_end = structure_tools.decode_domain_def(
                d.template.model.model_domain_def)
            mutation_idx = 0
            core_or_interface = "core"
            domain_start = domain_start or 1
            domain_end = domain_end or len(self.sequence.sequence)

            if int(mutation[1:-1]) < domain_start or int(
                    mutation[1:-1]) > domain_end:
                raise errors.MutationOutsideDomainError(
                    "Mutation {} falls outside the domain with definitions {}."
                    .format(mutation, d.template.model.model_domain_def))

        elif isinstance(d, elaspic_database.UniprotDomainPair):
            mutation_pos = int(mutation[1:-1])
            interacting_aa_1 = self._get_interacting_aa(d, 1)
            interacting_aa_2 = self._get_interacting_aa(d, 2)
            assert uniprot_id_1 in [
                d.uniprot_domain_1.uniprot_id,
                d.uniprot_domain_2.uniprot_id,
            ]
            logger.debug("sequence: {}".format(self.sequence.sequence))

            if uniprot_id_1 == d.uniprot_domain_1.uniprot_id and mutation_pos in interacting_aa_1:
                logger.debug("Mutation is inside the first domain.")
                logger.debug("model_domain_def: {}".format(
                    d.template.model.model_domain_def_1))
                domain_start, domain_end = structure_tools.decode_domain_def(
                    d.template.model.model_domain_def_1)
                if domain_start is None:
                    domain_start = 1
                mutation_idx = 0
                core_or_interface = "interface"
                domain_start = domain_start or 1  # if None
                domain_end = domain_end or len(self.sequence.sequence)

            elif uniprot_id_1 == d.uniprot_domain_2.uniprot_id and mutation_pos in interacting_aa_2:
                logger.debug("Mutation is inside the second domain.")
                logger.debug("model_domain_def: {}".format(
                    d.template.model.model_domain_def_2))
                domain_start, domain_end = structure_tools.decode_domain_def(
                    d.template.model.model_domain_def_2)
                mutation_idx = 1
                core_or_interface = "interface"
                domain_start = domain_start or 1
                domain_end = domain_end or len(self.sequence.sequence)

            else:
                # Mutation is outside the interface
                error_message = "Mutated residue {} not involved in the interaction!".format(
                    mutation[:-1])
                logger.error(error_message)
                logger.error("Uniprot ID: {}\tMutation: {}".format(
                    uniprot_id_1, mutation))
                logger.error("Uniprot ID 1: {}\tInteracting AA 1: {}".format(
                    d.uniprot_domain_1.uniprot_id, interacting_aa_1))
                logger.error("Uniprot ID 2: {}\tInteracting AA 2: {}".format(
                    d.uniprot_domain_2.uniprot_id, interacting_aa_2))
                raise errors.MutationOutsideInterfaceError(error_message)

        position_domain = int(mutation[1:-1]) - domain_start + 1
        mutation_domain = mutation[0] + str(position_domain) + mutation[-1]

        class MutationData:
            def __init__(self, **kwargs):
                self.__dict__ = kwargs

        mut_data = MutationData(
            mutation_idx=mutation_idx,
            mutation_domain=mutation_domain,
            core_or_interface=core_or_interface,
        )
        return mut_data
Example #4
0
    def get_mutation_data(self):
        """
        """
        d = self.d
        uniprot_id_1 = self.uniprot_id
        mutation = self.mutation

        if isinstance(d, elaspic_database.UniprotDomain):
            logger.debug("Analyzing core mutation for uniprot: %s" % uniprot_id_1)
            logger.debug("model_domain_def: {}".format(d.template.model.model_domain_def))
            domain_start, domain_end = structure_tools.decode_domain_def(d.template.model.model_domain_def)
            mutation_idx = 0
            core_or_interface = "core"
            domain_start = domain_start or 1
            domain_end = domain_end or len(self.sequence.sequence)

            if int(mutation[1:-1]) < domain_start or int(mutation[1:-1]) > domain_end:
                raise errors.MutationOutsideDomainError(
                    "Mutation {} falls outside the domain with definitions {}.".format(
                        mutation, d.template.model.model_domain_def
                    )
                )

        elif isinstance(d, elaspic_database.UniprotDomainPair):
            mutation_pos = int(mutation[1:-1])
            interacting_aa_1 = self._get_interacting_aa(d, 1)
            interacting_aa_2 = self._get_interacting_aa(d, 2)
            assert uniprot_id_1 in [d.uniprot_domain_1.uniprot_id, d.uniprot_domain_2.uniprot_id]
            logger.debug("sequence: {}".format(self.sequence.sequence))

            if uniprot_id_1 == d.uniprot_domain_1.uniprot_id and mutation_pos in interacting_aa_1:
                logger.debug("Mutation is inside the first domain.")
                logger.debug("model_domain_def: {}".format(d.template.model.model_domain_def_1))
                domain_start, domain_end = structure_tools.decode_domain_def(d.template.model.model_domain_def_1)
                if domain_start is None:
                    domain_start = 1
                mutation_idx = 0
                core_or_interface = "interface"
                domain_start = domain_start or 1  # if None
                domain_end = domain_end or len(self.sequence.sequence)

            elif uniprot_id_1 == d.uniprot_domain_2.uniprot_id and mutation_pos in interacting_aa_2:
                logger.debug("Mutation is inside the second domain.")
                logger.debug("model_domain_def: {}".format(d.template.model.model_domain_def_2))
                domain_start, domain_end = structure_tools.decode_domain_def(d.template.model.model_domain_def_2)
                mutation_idx = 1
                core_or_interface = "interface"
                domain_start = domain_start or 1
                domain_end = domain_end or len(self.sequence.sequence)

            else:
                # Mutation is outside the interface
                error_message = "Mutated residue {} not involved in the interaction!".format(mutation[:-1])
                logger.error(error_message)
                logger.error("Uniprot ID: {}\tMutation: {}".format(uniprot_id_1, mutation))
                logger.error(
                    "Uniprot ID 1: {}\tInteracting AA 1: {}".format(d.uniprot_domain_1.uniprot_id, interacting_aa_1)
                )
                logger.error(
                    "Uniprot ID 2: {}\tInteracting AA 2: {}".format(d.uniprot_domain_2.uniprot_id, interacting_aa_2)
                )
                raise errors.MutationOutsideInterfaceError(error_message)

        position_domain = int(mutation[1:-1]) - domain_start + 1
        mutation_domain = mutation[0] + str(position_domain) + mutation[-1]

        class MutationData:
            def __init__(self, **kwargs):
                self.__dict__ = kwargs

        mut_data = MutationData(
            mutation_idx=mutation_idx, mutation_domain=mutation_domain, core_or_interface=core_or_interface
        )
        return mut_data