diff --git a/src/test/java/org/broad/igv/sam/cram/IGVReferenceSourceTest.java b/src/test/java/org/broad/igv/sam/cram/IGVReferenceSourceTest.java index 6021445bf..6e0eacd22 100644 --- a/src/test/java/org/broad/igv/sam/cram/IGVReferenceSourceTest.java +++ b/src/test/java/org/broad/igv/sam/cram/IGVReferenceSourceTest.java @@ -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; @@ -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 { //