Skip to content

Commit

Permalink
Update CRAM reference test to include a genbank (gbk) referece with c…
Browse files Browse the repository at this point in the history
…hromosome aliasing
  • Loading branch information
jrobinso committed Sep 20, 2024
1 parent 068e20a commit 4448888
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions src/test/java/org/broad/igv/sam/cram/IGVReferenceSourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
Expand All @@ -43,53 +41,51 @@

public class IGVReferenceSourceTest {

public static final String FASTA_URL = "https://igv-genepattern-org.s3.amazonaws.com/genomes/seq/hg38/hg38.fa";
public static final String COMPRESSED_FASTA_URL = "https://igv-genepattern-org.s3.amazonaws.com/genomes/seq/hg38/hg38.fa.gz";
public static final String FASTA_URL = "https://igv.org/genomes/data/hg38/hg38.fa";
public static final String EXPECTED_REFERENCE_BASES = "AAACCCAGGGCAAAGAATCTGGCCCTA"; //bases at 22:27198875-271988902
public static final String GBK_URL = "https://s3.amazonaws.com/igv.broadinstitute.org/genomes/NC_012920.1.gbk";
public static final String GBK_EXPECTED_BASES = "tcatttctctaacagcagtaatattaataattttcatgat";

@Before
public void setUp() throws Exception {

}

private void assertReferenceReqionRequestsWork(final String fastaUrl) throws IOException {
GenomeManager.getInstance().loadGenome(fastaUrl);

@Test
public void testGetReferenceBasesByRegion() throws Exception {
GenomeManager.getInstance().loadGenome(IGVReferenceSourceTest.FASTA_URL);
IGVReferenceSource refSource = new IGVReferenceSource();
String expected = EXPECTED_REFERENCE_BASES;
SAMSequenceRecord rec = new SAMSequenceRecord("22", 50818468);
SAMSequenceRecord rec = new SAMSequenceRecord("chr22", 50818468);
byte[] bases = refSource.getReferenceBasesByRegion(rec, 27198874, expected.length());
assertEquals(expected.length(), bases.length);
assertEquals(expected, new String(bases, StandardCharsets.US_ASCII));
}

@Test
public void testGetReferenceBasesByRegion() throws Exception {
assertReferenceReqionRequestsWork(IGVReferenceSourceTest.FASTA_URL);
}

@Test
public void testGetReferenceBasesByRegionCompressed() throws Exception {
assertReferenceReqionRequestsWork(COMPRESSED_FASTA_URL);
// Test with a chr alias
rec = new SAMSequenceRecord("22", 50818468);
bases = refSource.getReferenceBasesByRegion(rec, 27198874, expected.length());
assertEquals(expected.length(), bases.length);
assertEquals(expected, new String(bases, StandardCharsets.US_ASCII));
}

@Test
public void testGetReferenceBasesCompressed() throws Exception {

GenomeManager.getInstance().loadGenome(COMPRESSED_FASTA_URL);

public void testGenbankReference() throws Exception {
GenomeManager.getInstance().loadGenome(GBK_URL);
String expected = GBK_EXPECTED_BASES.toUpperCase(); // Seq at NC_012920:7,279-7,318
IGVReferenceSource refSource = new IGVReferenceSource();
SAMSequenceRecord rec = new SAMSequenceRecord("22", 50818468);
byte[] bases = refSource.getReferenceBases(rec, false);

assertEquals(50818468, bases.length);
SAMSequenceRecord rec = new SAMSequenceRecord("NC_012920", 16569);
byte[] bases = refSource.getReferenceBasesByRegion(rec, 7278, expected.length());
assertEquals(expected.length(), bases.length);
assertEquals(expected, new String(bases, StandardCharsets.US_ASCII));

assertEquals('N', bases[0]);
String expected = EXPECTED_REFERENCE_BASES;
String actual = new String(Arrays.copyOfRange(bases, 27198874, 27198874 + expected.length()), StandardCharsets.US_ASCII);
assertEquals(expected, actual);
// Test with a chr alias
rec = new SAMSequenceRecord("MT", 16569);
bases = refSource.getReferenceBasesByRegion(rec, 7278, expected.length());
assertEquals(expected.length(), bases.length);
assertEquals(expected, new String(bases, StandardCharsets.US_ASCII));
}


// @Test
// public void testCompressedTiming() throws Exception {
//
Expand Down

0 comments on commit 4448888

Please sign in to comment.