Skip to content

Commit

Permalink
- added tests that exercise the CRAM readers as well.
Browse files Browse the repository at this point in the history
- finals
  • Loading branch information
yfarjoun committed Apr 5, 2024
1 parent 0f038a1 commit c314f54
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/test/java/picard/fingerprint/CrosscheckFingerprintsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import picard.PicardException;
import picard.cmdline.CommandLineProgramTest;
import picard.util.TabbedTextFileWithHeaderParser;
import picard.util.TestNGUtil;
import picard.vcf.SamTestUtils;
import picard.vcf.VcfTestUtils;

Expand All @@ -30,7 +31,6 @@
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
Expand All @@ -43,6 +43,8 @@ public class CrosscheckFingerprintsTest extends CommandLineProgramTest {
private final File HAPLOTYPE_MAP_SHORT = new File(TEST_DATA_DIR, "Homo_sapiens_assembly19.haplotype_database.subset.short_dictionary.txt");
private final File HAPLOTYPE_MAP_FOR_CRAMS = new File(TEST_DATA_DIR, "Homo_sapiens_assembly19.haplotype_database.subset.shifted.for.crams.txt");

private final File HAPLOTYPE_MAP_FOR_CRAMS_SHORT = new File(TEST_DATA_DIR, "Homo_sapiens_assembly19.haplotype_database.subset.shifted.for.crams.short_dictionary.txt");

private final File NA12891_r1_sam = new File(TEST_DATA_DIR, "NA12891.over.fingerprints.r1.sam");
private final File NA12891_r2_sam = new File(TEST_DATA_DIR, "NA12891.over.fingerprints.r2.sam");
private final File NA12891_r1_sam_shifted_for_cram = new File(TEST_DATA_DIR, "NA12891.over.fingerprints.shifted.for.crams.r1.sam");
Expand Down Expand Up @@ -149,7 +151,6 @@ public String getCommandLineProgramName() {
return CrosscheckFingerprints.class.getSimpleName();
}

@DataProvider(name = "bamFilesRGs")
public Object[][] bamAndCramFilesRGs() {
return new Object[][] {
{NA12891_r1, NA12891_r2, false, 0, (NA12891_r1_RGs + NA12891_r2_RGs) * (NA12891_r1_RGs + NA12891_r2_RGs )},
Expand Down Expand Up @@ -179,10 +180,18 @@ public Object[][] bamAndCramFilesRGs() {
};
}

private Object[][] haplotypeMaps(){
return new Object[][]{{HAPLOTYPE_MAP}, {HAPLOTYPE_MAP_SHORT}};
}
@DataProvider(name = "bamFilesRGs")
public Iterator<Object[]> bamFilesRGsAndHapMaps(){
return TestNGUtil.interaction(bamAndCramFilesRGs(),haplotypeMaps());
}

@Test(dataProvider = "bamFilesRGs")
public void testCrossCheckRGs(final File file1, final File file2, final boolean expectAllMatch, final int expectedRetVal, final int expectedNMetrics) throws IOException {
public void testCrossCheckRGs(final File file1, final File file2, final boolean expectAllMatch, final int expectedRetVal, final int expectedNMetrics, final File haplotypeMap) throws IOException {

File metrics = File.createTempFile("Fingerprinting", "NA1291.RG.crosscheck_metrics");
final File metrics = File.createTempFile("Fingerprinting", "NA1291.RG.crosscheck_metrics");
metrics.deleteOnExit();

final List<String> args = new ArrayList<>(Arrays.asList("INPUT=" + file1.getAbsolutePath(),
Expand All @@ -196,7 +205,7 @@ public void testCrossCheckRGs(final File file1, final File file2, final boolean
args.add("R=" + referenceForCrams);
args.add("HAPLOTYPE_MAP=" + HAPLOTYPE_MAP_FOR_CRAMS);
} else {
args.add("HAPLOTYPE_MAP=" + HAPLOTYPE_MAP);
args.add("HAPLOTYPE_MAP=" + haplotypeMap.getAbsolutePath());
}

doTest(args.toArray(new String[0]), metrics, expectedRetVal, expectedNMetrics, CrosscheckMetric.DataType.READGROUP, expectAllMatch);
Expand All @@ -205,7 +214,7 @@ public void testCrossCheckRGs(final File file1, final File file2, final boolean
@Test(dataProvider = "bamFilesRGs")
public void testCrossCheckRGs_with_short_dictionary(final File file1, final File file2, final boolean expectAllMatch, final int expectedRetVal, final int expectedNMetrics) throws IOException {

File metrics = File.createTempFile("Fingerprinting", "NA1291.RG.crosscheck_metrics");
final File metrics = File.createTempFile("Fingerprinting", "NA1291.RG.crosscheck_metrics");
metrics.deleteOnExit();

final List<String> args = new ArrayList<>(Arrays.asList("INPUT=" + file1.getAbsolutePath(),
Expand Down Expand Up @@ -238,7 +247,7 @@ public Object[][] cramsWithNoReference() {

@Test(dataProvider = "cramsWithNoReference")
public void testCramsWithNoReference(final File file1, final File file2) throws IOException {
File metrics = File.createTempFile("Fingerprinting", "NA12891.RG.crosscheck_metrics");
final File metrics = File.createTempFile("Fingerprinting", "NA12891.RG.crosscheck_metrics");
metrics.deleteOnExit();

final String[] args = {"INPUT=" + file1.getAbsolutePath(),
Expand All @@ -251,8 +260,11 @@ public void testCramsWithNoReference(final File file1, final File file2) throws
Assert.assertEquals(crossChecker.instanceMain(args), 1);
}

@DataProvider(name = "cramBamComparison")
public Object[][] cramBamComparison() {
private Object[][] haplotypeMapsForCram(){
return new Object[][]{{HAPLOTYPE_MAP_FOR_CRAMS}, {HAPLOTYPE_MAP_FOR_CRAMS_SHORT}};
}

private Object[][] cramBamComparison() {
return new Object[][]{
{NA12891_r1_shifted_bam, NA12891_r2_shifted_bam, NA12891_r1_cram, NA12891_r2_cram},
{NA12891_r1_shifted_bam, NA12892_r1_shifted_bam, NA12891_r1_cram, NA12892_r1_cram},
Expand All @@ -263,25 +275,30 @@ public Object[][] cramBamComparison() {
};
}

@DataProvider(name = "cramBamComparison")
public Iterator<Object[]> cramBamComparisonWithHapMap() {
return TestNGUtil.interaction(cramBamComparison(), haplotypeMapsForCram());
}

@Test(dataProvider = "cramBamComparison")
public void testCramBamComparison(final File bam1, final File bam2, final File cram1, final File cram2) throws IOException {
File metricsBam = File.createTempFile("Fingerprinting.bam.comparison", "crosscheck_metrics");
public void testCramBamComparison(final File bam1, final File bam2, final File cram1, final File cram2, final File haplotypeMap) throws IOException {
final File metricsBam = File.createTempFile("Fingerprinting.bam.comparison", "crosscheck_metrics");
metricsBam.deleteOnExit();
File metricsCram = File.createTempFile("Fingerprinting.cram.comparison", "crosscheck_metrics");
final File metricsCram = File.createTempFile("Fingerprinting.cram.comparison", "crosscheck_metrics");
metricsCram.deleteOnExit();

final List<String> argsBam = new ArrayList<>(Arrays.asList("INPUT=" + bam1.getAbsolutePath(),
"INPUT=" + bam2.getAbsolutePath(),
"OUTPUT=" + metricsBam.getAbsolutePath(),
"LOD_THRESHOLD=" + -2.0,
"HAPLOTYPE_MAP=" + HAPLOTYPE_MAP_FOR_CRAMS)
"HAPLOTYPE_MAP=" + haplotypeMap.getAbsolutePath())
);

final List<String> argsCram = new ArrayList<>(Arrays.asList("INPUT=" + cram1.getAbsolutePath(),
"INPUT=" + cram2.getAbsolutePath(),
"OUTPUT=" + metricsCram.getAbsolutePath(),
"LOD_THRESHOLD=" + -2.0,
"HAPLOTYPE_MAP=" + HAPLOTYPE_MAP_FOR_CRAMS,
"HAPLOTYPE_MAP=" + haplotypeMap.getAbsolutePath(),
"R=" + referenceForCrams)
);

Expand Down Expand Up @@ -442,10 +459,10 @@ public Object[][] bamFilesSMs() {

@Test(dataProvider = "bamFilesSMs")
public void testCrossCheckSMs(final File file1, final File file2, final int expectedRetVal, final int numberOfSamples) throws IOException {
File metrics = File.createTempFile("Fingerprinting", "NA1291.SM.crosscheck_metrics");
final File metrics = File.createTempFile("Fingerprinting", "NA1291.SM.crosscheck_metrics");
metrics.deleteOnExit();

File matrix = File.createTempFile("Fingerprinting", "NA1291.SM.matrix");
final File matrix = File.createTempFile("Fingerprinting", "NA1291.SM.matrix");
matrix.deleteOnExit();

final String[] args = new String[]{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@HD VN:1.5
@SQ SN:1 LN:1001 M5:af506819d4b9357827ce128b6c83a816 UR:file:reference.shifted.for.crams.fasta
@SQ SN:3 LN:2001 M5:bfecd72141fd7c10b33f04958736baef UR:file:reference.shifted.for.crams.fasta
@SQ SN:4 LN:1001 M5:ac7d9a3274b2f1fa8eac3f01b3ff9b43 UR:file:reference.shifted.for.crams.fasta
@SQ SN:5 LN:1001 M5:468698a81368c9d42bd876a2dae5c330 UR:file:reference.shifted.for.crams.fasta
#CHROMOSOME POSITION NAME MAJOR_ALLELE MINOR_ALLELE MAF ANCHOR_SNP PANELS
1 251 rs7555566 A G 0.223794
3 251 rs17272796 C T 0.623026
4 251 rs6834736 C G 0.512884
5 251 rs2862058 A G 0.349127

0 comments on commit c314f54

Please sign in to comment.