Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VariantContextBuilder does not perform a deep copy #255

Open
d-cameron opened this issue May 19, 2015 · 5 comments
Open

VariantContextBuilder does not perform a deep copy #255

d-cameron opened this issue May 19, 2015 · 5 comments
Assignees

Comments

@d-cameron
Copy link
Contributor

When using VariantContextBuilder to create a new variant based on an existing variant, the underlying objects and collections are not copied nor are they wrapped with copy-on-write semantics. Making changes to a copied variant change the original variant as well.

Failing unit test for VariantContextUnitTest.java

@Test
    public void testFilterUnaffectedByClonedVariants() {
        VariantContext vc1 = new VariantContextBuilder("source", "contig", 1, 1, Arrays.asList(Tref, A)).filter("TEST").make();
        VariantContext vc2 = new VariantContextBuilder(vc1).filter("TEST2").make();
        Assert.assertFalse(vc1.getFilters().equals(vc2.getFilters()));
    }
@yfarjoun
Copy link
Contributor

attributes are protected against this, I guess filters need the same
treatment.

On Tue, May 19, 2015 at 3:13 AM, Daniel Cameron notifications@github.com
wrote:

When using VariantContextBuilder to create a new variant based on an
existing variant, the underlying objects and collections are not copied nor
are they wrapped with copy-on-write semantics. Making changes to a copied
variant change the original variant as well.

Failing unit test for VariantContextUnitTest.java

@test
public void testFilterUnaffectedByClonedVariants() {
VariantContext vc1 = new VariantContextBuilder("source", "contig", 1, 1, Arrays.asList(Tref, A)).filter("TEST").make();
VariantContext vc2 = new VariantContextBuilder(vc1).filter("TEST2").make();
Assert.assertFalse(vc1.getFilters().equals(vc2.getFilters()));
}


Reply to this email directly or view it on GitHub
#255.

@d-cameron
Copy link
Contributor Author

Yes, attributesCanBeModified does look pretty obvious when reviewing the code again. Depending on when GenotypesContext is/is not immutable, genotypes might also be an issue.

@yfarjoun
Copy link
Contributor

yfarjoun commented Apr 1, 2019

also include a test without calling make():

@Test
    public void testFilterUnaffectedByClonedVariants() {
        VariantContext vc1 = new VariantContextBuilder("source", "contig", 1, 1, Arrays.asList(Tref, A)).filter("TEST").make();
        VariantContext vc2 = new VariantContextBuilder(vc1).filter("TEST2");
        Assert.assertFalse(vc1.getFilters().equals(vc2.getFilters()));
    }

@yfarjoun yfarjoun self-assigned this Apr 3, 2019
@yfarjoun
Copy link
Contributor

yfarjoun commented Apr 3, 2019

this is actually worse. I can get it to fail on filters (as reported) attributes, genotypes and alleles....

@yfarjoun
Copy link
Contributor

yfarjoun commented Apr 3, 2019

submitting a PR with tests for comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants