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

Changed ReadNameReadFilter to support mulitple readname inputs #8405

Merged
merged 4 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import org.broadinstitute.hellbender.utils.read.GATKRead;

import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;

/**
* Keep only reads with this read name.
* Keep only reads with one of these readnames.
*
* Should you need to provide many readnames to keep, you can provide a newline separated .list file of readnames to keep.
*
* <p>Matching is done by case-sensitive exact match.</p>
*/
Expand All @@ -18,11 +23,11 @@ public final class ReadNameReadFilter extends ReadFilter implements Serializable
private static final long serialVersionUID = 1L;

@Argument(fullName = ReadFilterArgumentDefinitions.READ_NAME_LONG_NAME, doc="Keep only reads with this read name", optional=false)
public String readName = null;
public Set<String> readNames = new LinkedHashSet<>(0);

@Override
public boolean test( final GATKRead read ) {
return read.getName() != null && read.getName().equals(readName);
return read.getName() != null && readNames.contains(read.getName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

public final class ReadsContextUnitTest extends GATKBaseTest {
Expand Down Expand Up @@ -42,7 +40,9 @@ public Object[][] getValidReadsContextData() {
// Default-constructed ReadsContexts and ReadsContexts constructed from null ReadsDataSources/intervals
// should behave as empty context objects.
ReadNameReadFilter readNameFilter = new ReadNameReadFilter();
readNameFilter.readName = "d";
readNameFilter.readNames = Collections.singleton("d");
ReadNameReadFilter twoReadNamesReadFilter = new ReadNameReadFilter();
twoReadNamesReadFilter.readNames = Set.of("d", "b");
return new Object[][]{
{new ReadsContext(
new ReadsPathDataSource(IOUtils.getPath(publicTestDir + "org/broadinstitute/hellbender/engine/reads_data_source_test1.bam")),
Expand All @@ -53,6 +53,11 @@ public Object[][] getValidReadsContextData() {
new ReadsPathDataSource(IOUtils.getPath(publicTestDir + "org/broadinstitute/hellbender/engine/reads_data_source_test1.bam")),
new SimpleInterval("1", 200, 1000), // query over larger interval with readNameFilter on "d"
readNameFilter), new String[] { "d" }
},
{new ReadsContext(
new ReadsPathDataSource(IOUtils.getPath(publicTestDir + "org/broadinstitute/hellbender/engine/reads_data_source_test1.bam")),
new SimpleInterval("1", 200, 1000), // query over larger interval with readNameFilter on "d", "b"
twoReadNamesReadFilter), new String[] { "b", "d" }
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ public void testReadNameFilter() {
ReadNameReadFilter f = new ReadNameReadFilter();

final String fred= "fred";
f.readName = fred;
f.readNames = Collections.singleton(fred);
read.setName(fred);
Assert.assertTrue(f.test(read), read.toString());//pass

Expand Down