def annotate_mutation(self, mutation):
        #if any([c in mutation for c in self.output_headers]):
        for c in self.output_headers:
            if c in mutation:
                raise Exception(
                    'Error: Non-unique header value in annotation table (%s)' %
                    (c))

        if all([mutation.chr, mutation.start, mutation.end]):
            chrom, start, end = mutation.chr, mutation.start, mutation.end
            records = get_binned_data(self.db_obj, chrom, int(start), int(end))
            records = get_overlapping_records(records, int(start), int(end))
            if records:
                for c in self.output_headers:
                    summarized_results = get_summary_output_string(
                        [r[c].strip() for r in records])
                    mutation.createAnnotation(c,
                                              summarized_results,
                                              annotationSource=self.title)

        for header in self.output_headers:
            if header not in mutation:
                mutation.createAnnotation(header,
                                          '',
                                          annotationSource=self.title)

        return mutation
    def annotate_mutation(self, mutation):
        requiredAnnotations = ['gene', self.proteinPositionAnnotation]
        if all(field in mutation for field in requiredAnnotations):
            gene = mutation['gene']
            p = None
            transcriptProteinPos = []
            proteinChange = mutation[self.proteinPositionAnnotation].replace("p.", "")
            proteinPosition = self.proteinRegexp.match(proteinChange)
            if proteinPosition is not None:
                p = proteinPosition.group(1)

            if p is not None:
                records = get_binned_data(self.db_obj, gene, int(p), int(p))
                records = get_overlapping_records(records, int(p), int(p))

                for c in self.output_headers:
                    summarized_results = get_summary_output_string([r[c].strip() for r in records])
                    mutation.createAnnotation(c, summarized_results, annotationSource=self.title)
        else:
            missingList = []
            for r in requiredAnnotations:
                if r not in mutation:
                    missingList.append(r)
            raise MissingAnnotationException("Missing required annotation: " + str(missingList))

        for header in self.output_headers:
            if header not in mutation:
                mutation.createAnnotation(header, '', annotationSource=self.title)

        return mutation
    def annotate_mutation(self, mutation):
        # if any([c in mutation for c in self.output_headers]):
        for c in self.output_headers:
            if c in mutation:
                raise Exception("Error: Non-unique header value in annotation table (%s)" % (c))

        if all(field in mutation for field in ["chr", "start", "end", "ref_allele", "alt_allele", "strand"]):
            chr, start, end = mutation.chr, mutation.start, mutation.end
            ref_allele, alt_allele = (
                str(mutation.ref_allele),
                str(mutation.alt_allele),
            )  # changed to str incase vcf.model._Substitution object is being used
            if self.use_complementary_strand_alleles_for_negative_strand_transcripts:
                if mutation.get("strand") == "-":
                    ref_allele, alt_allele = Seq.reverse_complement(ref_allele), Seq.reverse_complement(alt_allele)

            records = get_binned_data(self.db_obj, chr, int(start), int(end))
            records = get_overlapping_records(records, int(start), int(end))
            records = [
                rec
                for rec in records
                if rec[self.ref_allele_fieldname] == ref_allele and rec[self.alt_allele_fieldname] == alt_allele
            ]
            if records:
                for c in self.output_headers:
                    summarized_results = get_summary_output_string([r[c].strip() for r in records])
                    mutation.createAnnotation(c, summarized_results, annotationSource=self.title)

        for header in self.output_headers:
            if header not in mutation:
                mutation.createAnnotation(header, "", annotationSource=self.title)

        return mutation
    def annotate_mutation(self, mutation):
        requiredAnnotations = ['gene', self.proteinPositionAnnotation]
        if all(field in mutation for field in requiredAnnotations):
            gene = mutation['gene']

            # p is a tuple (start, end)
            p = None

            transcriptProteinPos = []
            proteinChange = mutation[self.proteinPositionAnnotation].replace(
                "p.", "")

            proteinPosition = self.protein_regex_range.match(proteinChange)
            if proteinPosition is not None:

                # Get start and end AA
                p = (int(proteinPosition.group(1)),
                     int(proteinPosition.group(2)))
            else:

                # Get start and end AA as equal values, since this protein change can only have affected one AA, if any.
                proteinPosition = self.protein_regexp.match(proteinChange)
                if proteinPosition is not None:
                    p = (int(proteinPosition.group(1)),
                         int(proteinPosition.group(1)))

            if p is not None:
                records = get_binned_data(self.db_obj, gene, p[0], p[1])
                records = get_overlapping_records(records, p[0], p[1])

                for c in self.output_headers:
                    summarized_results = get_summary_output_string(
                        [r[c].strip() for r in records])
                    mutation.createAnnotation(c,
                                              summarized_results,
                                              annotationSource=self.title)
        else:
            missingList = []
            for r in requiredAnnotations:
                if r not in mutation:
                    missingList.append(r)
            raise MissingAnnotationException("Missing required annotation: " +
                                             str(missingList))

        for header in self.output_headers:
            if header not in mutation:
                mutation.createAnnotation(header,
                                          '',
                                          annotationSource=self.title)

        return mutation
    def annotate_mutation(self, mutation):
        requiredAnnotations = ['gene', self.proteinPositionAnnotation]
        if all(field in mutation for field in requiredAnnotations):
            gene = mutation['gene']

            # p is a tuple (start, end)
            p = None

            transcriptProteinPos = []
            proteinChange = mutation[self.proteinPositionAnnotation].replace("p.", "")

            proteinPosition = self.protein_regex_range.match(proteinChange)
            if proteinPosition is not None:

                # Get start and end AA
                p = (int(proteinPosition.group(1)), int(proteinPosition.group(2)))
            else:

                # Get start and end AA as equal values, since this protein change can only have affected one AA, if any.
                proteinPosition = self.protein_regexp.match(proteinChange)
                if proteinPosition is not None:
                    p = (int(proteinPosition.group(1)), int(proteinPosition.group(1)))

            if p is not None:
                records = get_binned_data(self.db_obj, gene, p[0], p[1])
                records = get_overlapping_records(records, p[0], p[1])

                for c in self.output_headers:
                    summarized_results = get_summary_output_string([r[c].strip() for r in records])
                    mutation.createAnnotation(c, summarized_results, annotationSource=self.title)
        else:
            missingList = []
            for r in requiredAnnotations:
                if r not in mutation:
                    missingList.append(r)
            raise MissingAnnotationException("Missing required annotation: " + str(missingList))

        for header in self.output_headers:
            if header not in mutation:
                mutation.createAnnotation(header, '', annotationSource=self.title)

        return mutation
    def annotate_mutation(self, mutation):
        #if any([c in mutation for c in self.output_headers]):
        for c in self.output_headers:
            if c in mutation:
                raise Exception('Error: Non-unique header value in annotation table (%s)' % (c))

        if all([mutation.chr, mutation.start, mutation.end]):
            chrom, start, end = mutation.chr, mutation.start, mutation.end
            records = get_binned_data(self.db_obj, chrom, int(start), int(end))
            records = get_overlapping_records(records, int(start), int(end))
            if records:
                for c in self.output_headers:
                    summarized_results = get_summary_output_string([r[c].strip() for r in records])
                    mutation.createAnnotation(c, summarized_results, annotationSource=self.title)

        for header in self.output_headers:
            if header not in mutation:
                mutation.createAnnotation(header, '', annotationSource=self.title)

        return mutation
Beispiel #7
0
    def annotate_mutation(self, mutation):
        #if any([c in mutation for c in self.output_headers]):
        for c in self.output_headers:
            if c in mutation:
                raise Exception(
                    'Error: Non-unique header value in annotation table (%s)' %
                    (c))

        if all(field in mutation for field in
               ['chr', 'start', 'end', 'ref_allele', 'alt_allele', 'strand']):
            chr, start, end = mutation.chr, mutation.start, mutation.end
            ref_allele, alt_allele = str(mutation.ref_allele), str(
                mutation.alt_allele
            )  #changed to str incase vcf.model._Substitution object is being used
            if self.use_complementary_strand_alleles_for_negative_strand_transcripts:
                if mutation.get('strand') == '-':
                    ref_allele, alt_allele = Seq.reverse_complement(
                        ref_allele), Seq.reverse_complement(alt_allele)

            records = get_binned_data(self.db_obj, chr, int(start), int(end))
            records = get_overlapping_records(records, int(start), int(end))
            records = [
                rec for rec in records
                if rec[self.ref_allele_fieldname] == ref_allele
                and rec[self.alt_allele_fieldname] == alt_allele
            ]
            if records:
                for c in self.output_headers:
                    summarized_results = get_summary_output_string(
                        [r[c].strip() for r in records])
                    mutation.createAnnotation(c,
                                              summarized_results,
                                              annotationSource=self.title)

        for header in self.output_headers:
            if header not in mutation:
                mutation.createAnnotation(header,
                                          '',
                                          annotationSource=self.title)

        return mutation