Ejemplo n.º 1
0
    def initializeMutFromAttributes(chr, start, end, ref_allele, alt_allele, build, mutation_data_factory=None):
        mutation_data_factory = MutationDataFactory() if mutation_data_factory is None else mutation_data_factory
        mut = mutation_data_factory.create(str(chr), str(start), str(end), ref_allele, alt_allele, str(build))
        varType = TranscriptProviderUtils.infer_variant_type(mut.ref_allele, mut.alt_allele)

        if TranscriptProviderUtils.is_xnp(varType):  # Snps and other xNPs
            mut.createAnnotation(annotationName=MutUtils.PRECEDING_BASES_ANNOTATION_NAME, annotationValue="")
        if varType == VariantClassification.VT_DEL:  # deletion
            preceding_bases, updated_ref_allele, updated_start, updated_end =\
                MutUtils.retrievePrecedingBasesForDeletions(mut)
            mut.ref_allele = updated_ref_allele
            mut["ref_allele"] = updated_ref_allele
            mut.alt_allele = "-"
            mut["alt_allele"] = "-"
            mut.start = updated_start
            mut["start"] = updated_start
            mut.end = updated_end
            mut["end"] = updated_end
            mut.createAnnotation(annotationName=MutUtils.PRECEDING_BASES_ANNOTATION_NAME,
                                 annotationValue=preceding_bases)
        elif varType == VariantClassification.VT_INS:  # insertion
            preceding_bases, updated_alt_allele, updated_start, updated_end = \
                MutUtils.retrievePrecedingBasesForInsertions(mut)
            mut.ref_allele = "-"
            mut["ref_allele"] = "-"
            mut.alt_allele = updated_alt_allele
            mut["alt_allele"] = updated_alt_allele
            mut.start = updated_start
            mut["start"] = updated_start
            mut.end = updated_end
            mut["end"] = updated_end
            mut.createAnnotation(annotationName=MutUtils.PRECEDING_BASES_ANNOTATION_NAME,
                                 annotationValue=preceding_bases)

        return mut
Ejemplo n.º 2
0
    def test_annotation_overwriting_on(self):
        """Test that the factory can produce a mutation that allows overwriting.  Just need to make sure no exception thrown."""
        mdf = MutationDataFactory(allow_overwriting=True)
        mut = mdf.create()

        mut.createAnnotation("blah", "123")
        self.assertTrue(mut['blah'] == "123")

        mut.createAnnotation("blah", "456")
        self.assertTrue(mut['blah'] == "456")
Ejemplo n.º 3
0
    def test_annotation_overwriting_on(self):
        """Test that the factory can produce a mutation that allows overwriting.  Just need to make sure no exception thrown."""
        mdf = MutationDataFactory(allow_overwriting=True)
        mut = mdf.create()

        mut.createAnnotation("blah", "123")
        self.assertTrue(mut['blah'] == "123")

        mut.createAnnotation("blah", "456")
        self.assertTrue(mut['blah'] == "456")
Ejemplo n.º 4
0
    def test_annotation_overwriting_off(self):
        """Test that the factory can produce a mutation that does not allow overwriting.  Make sure DuplicateAnnotationException is thrown."""
        mdf = MutationDataFactory(allow_overwriting=False)
        mut = mdf.create()

        mut.createAnnotation("blah", "123")
        self.assertTrue(mut['blah'] == "123")

        is_exception_raised = False
        try:
            mut.createAnnotation("blah", "456")
        except DuplicateAnnotationException as dae:
            is_exception_raised = True

        self.assertTrue(is_exception_raised, "DuplicateAnnotationException should have been seen, but wasn't")
Ejemplo n.º 5
0
    def initializeMutFromAttributes(chr,
                                    start,
                                    end,
                                    ref_allele,
                                    alt_allele,
                                    build,
                                    mutation_data_factory=None):
        mutation_data_factory = MutationDataFactory(
        ) if mutation_data_factory is None else mutation_data_factory
        mut = mutation_data_factory.create(str(chr), str(start), str(end),
                                           ref_allele, alt_allele, str(build))
        varType = TranscriptProviderUtils.infer_variant_type(
            mut.ref_allele, mut.alt_allele)

        if TranscriptProviderUtils.is_xnp(varType):  # Snps and other xNPs
            mut.createAnnotation(
                annotationName=MutUtils.PRECEDING_BASES_ANNOTATION_NAME,
                annotationValue="")
        if varType == VariantClassification.VT_DEL:  # deletion
            preceding_bases, updated_ref_allele, updated_start, updated_end =\
                MutUtils.retrievePrecedingBasesForDeletions(mut)
            mut.ref_allele = updated_ref_allele
            mut["ref_allele"] = updated_ref_allele
            mut.alt_allele = "-"
            mut["alt_allele"] = "-"
            mut.start = updated_start
            mut["start"] = updated_start
            mut.end = updated_end
            mut["end"] = updated_end
            mut.createAnnotation(
                annotationName=MutUtils.PRECEDING_BASES_ANNOTATION_NAME,
                annotationValue=preceding_bases)
        elif varType == VariantClassification.VT_INS:  # insertion
            preceding_bases, updated_alt_allele, updated_start, updated_end = \
                MutUtils.retrievePrecedingBasesForInsertions(mut)
            mut.ref_allele = "-"
            mut["ref_allele"] = "-"
            mut.alt_allele = updated_alt_allele
            mut["alt_allele"] = updated_alt_allele
            mut.start = updated_start
            mut["start"] = updated_start
            mut.end = updated_end
            mut["end"] = updated_end
            mut.createAnnotation(
                annotationName=MutUtils.PRECEDING_BASES_ANNOTATION_NAME,
                annotationValue=preceding_bases)

        return mut
Ejemplo n.º 6
0
    def test_annotation_overwriting_off(self):
        """Test that the factory can produce a mutation that does not allow overwriting.  Make sure DuplicateAnnotationException is thrown."""
        mdf = MutationDataFactory(allow_overwriting=False)
        mut = mdf.create()

        mut.createAnnotation("blah", "123")
        self.assertTrue(mut['blah'] == "123")

        is_exception_raised = False
        try:
            mut.createAnnotation("blah", "456")
        except DuplicateAnnotationException as dae:
            is_exception_raised = True

        self.assertTrue(
            is_exception_raised,
            "DuplicateAnnotationException should have been seen, but wasn't")