|
| 1 | +/* |
| 2 | + * To change this license header, choose License Headers in Project Properties. |
| 3 | + * To change this template file, choose Tools | Templates |
| 4 | + * and open the template in the editor. |
| 5 | + */ |
| 6 | +package org.biojava.nbio.core.search.io.blast; |
| 7 | + |
| 8 | +import java.io.File; |
| 9 | +import java.io.FileOutputStream; |
| 10 | +import java.io.IOException; |
| 11 | +import java.io.InputStream; |
| 12 | +import java.io.OutputStream; |
| 13 | +import java.net.URL; |
| 14 | +import java.util.ArrayList; |
| 15 | +import java.util.List; |
| 16 | +import org.biojava.nbio.core.search.io.Hit; |
| 17 | +import org.biojava.nbio.core.search.io.Hsp; |
| 18 | +import org.biojava.nbio.core.search.io.Result; |
| 19 | +import org.biojava.nbio.core.sequence.io.util.ClasspathResource; |
| 20 | +import org.junit.After; |
| 21 | +import org.junit.AfterClass; |
| 22 | +import org.junit.Before; |
| 23 | +import org.junit.BeforeClass; |
| 24 | +import org.junit.Test; |
| 25 | +import static org.junit.Assert.*; |
| 26 | +import org.junit.Ignore; |
| 27 | + |
| 28 | +/** |
| 29 | + * |
| 30 | + * @author pavanpa |
| 31 | + */ |
| 32 | +public class BlastXMLQueryTest { |
| 33 | + |
| 34 | + public BlastXMLQueryTest() { |
| 35 | + } |
| 36 | + |
| 37 | + @BeforeClass |
| 38 | + public static void setUpClass() { |
| 39 | + } |
| 40 | + |
| 41 | + @AfterClass |
| 42 | + public static void tearDownClass() { |
| 43 | + } |
| 44 | + |
| 45 | + @Before |
| 46 | + public void setUp() { |
| 47 | + } |
| 48 | + |
| 49 | + @After |
| 50 | + public void tearDown() { |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Test of setFile method, of class BlastXMLQuery. |
| 55 | + */ |
| 56 | + @Test |
| 57 | + public void testSetFile() { |
| 58 | + System.out.println("setFile"); |
| 59 | + File f = null; |
| 60 | + BlastXMLQuery instance = new BlastXMLQuery(); |
| 61 | + instance.setFile(f); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Test of createObjects method, of class BlastXMLQuery. |
| 66 | + */ |
| 67 | + @Test |
| 68 | + public void testCreateObjects() throws Exception { |
| 69 | + System.out.println("createObjects"); |
| 70 | + String resource = "/org/biojava/nbio/core/search/io/blast/testBlastReport.xml"; |
| 71 | + |
| 72 | + URL resourceURL = getClass().getResource(resource); |
| 73 | + File file = new File(resourceURL.getFile()); |
| 74 | + |
| 75 | + BlastXMLQuery instance = new BlastXMLQuery(); |
| 76 | + instance.setFile(file); |
| 77 | + |
| 78 | + //instance.setQueryReferences(null); |
| 79 | + //instance.setDatabaseReferences(null); |
| 80 | + ArrayList<Result> result = instance.createObjects(Double.MAX_VALUE); |
| 81 | + |
| 82 | + // test with random manual selected results |
| 83 | + BlastHsp hsp1hit1res1 = new BlastHspBuilder() |
| 84 | + .setHspNum(1) |
| 85 | + .setHspBitScore(377.211) |
| 86 | + .setHspEvalue(8.04143e-093) |
| 87 | + .setHspQueryFrom(1) |
| 88 | + .setHspQueryTo(224) |
| 89 | + .setHspHitFrom(1035) |
| 90 | + .setHspHitTo(811) |
| 91 | + .setHspQueryFrame(-1) |
| 92 | + .setHspIdentity(213) |
| 93 | + .setHspPositive(213) |
| 94 | + .setHspGaps(5) |
| 95 | + .setHspAlignLen(227) |
| 96 | + .setHspQseq("CTGACGACAGCCATGCACCACCTGTCTCGACTTTCCCCCGAAGGGCACCTAATGTATCTCTACCTCGTTAGTCGGATGTCAAGACCTGGTAAGGTTTTTTCGCGTATCTTCGAATTAAACCACATACTCCACTGCTTGTGCGG-CCCCCGTCAATTCCTTTGAGTTTCAACCTTGCGGCCGTACTCCC-AGGTGGA-TACTTATTGTGTTAACTCCGGCACGGAAGG") |
| 97 | + .setHspHseq("CTGACGACAACCATGCACCACCTGTCTCAACTTTCCCC-GAAGGGCACCTAATGTATCTCTACTTCGTTAGTTGGATGTCAAGACCTGGTAAGGTT-CTTCGCGTTGCTTCGAATTAAACCACATACTCCACTGCTTGTGCGGGCCCCCGTCAATTCCTTTGAGTTTCAACCTTGCGGTCGTACTCCCCAGGTGGATTACTTATTGTGTTAACTCCGGCACAGAAGG") |
| 98 | + .setHspIdentityString("||||||||| |||||||||||||||||| ||||||||| |||||||||||||||||||||||| |||||||| ||||||||||||||||||||||| ||||||| |||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||| ||||||||| ||||||| |||||||||||||||||||||||| |||||") |
| 99 | + .createBlastHsp(); |
| 100 | + BlastHit hit1res1 = new BlastHitBuilder() |
| 101 | + .setHitNum(1) |
| 102 | + .setHitId("gnl|BL_ORD_ID|2006") |
| 103 | + .setHitDef("gi|265679047|ref|NR_029355.1| Clostridium methylpentosum DSM 5476 strain R2 16S ribosomal RNA, partial sequence") |
| 104 | + .setHitAccession("2006") |
| 105 | + .setHitLen(1435) |
| 106 | + .createBlastHit(); |
| 107 | + |
| 108 | + BlastResult res1 = new BlastResultBuilder() |
| 109 | + .setProgram("blastn") |
| 110 | + .setVersion("BLASTN 2.2.29+") |
| 111 | + .setReference("Zheng Zhang, Scott Schwartz, Lukas Wagner, and Webb Miller (2000), "A greedy algorithm for aligning DNA sequences", J Comput Biol 2000; 7(1-2):203-14.") |
| 112 | + .setQueryID("Query_1") |
| 113 | + .setQueryDef("42DKN:00022:00047") |
| 114 | + .setQueryLength(226) |
| 115 | + .createBlastResult(); |
| 116 | + |
| 117 | + Result expRes1 = result.get(0); |
| 118 | + Hit expHit1res1 = expRes1.iterator().next(); |
| 119 | + Hsp expHsp1hit1res1 = expHit1res1.iterator().next(); |
| 120 | + |
| 121 | + // result test |
| 122 | + assertEquals(expRes1, res1); |
| 123 | + |
| 124 | + // hit test |
| 125 | + assertEquals(expHit1res1, hit1res1); |
| 126 | + |
| 127 | + // hsp test |
| 128 | + assertEquals(expHsp1hit1res1, hsp1hit1res1); |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Test of getFileExtensions method, of class BlastXMLQuery. |
| 133 | + */ |
| 134 | + @Test |
| 135 | + @Ignore public void testGetFileExtensions() { |
| 136 | + System.out.println("getFileExtensions"); |
| 137 | + BlastXMLQuery instance = new BlastXMLQuery(); |
| 138 | + List<String> expResult = null; |
| 139 | + List<String> result = instance.getFileExtensions(); |
| 140 | + assertEquals(expResult, result); |
| 141 | + // TODO review the generated test code and remove the default call to fail. |
| 142 | + fail("The test case is a prototype."); |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * Test of setQueryReferences method, of class BlastXMLQuery. |
| 147 | + */ |
| 148 | + @Test |
| 149 | + @Ignore public void testSetQueryReferences() { |
| 150 | + System.out.println("setQueryReferences"); |
| 151 | + List sequences = null; |
| 152 | + BlastXMLQuery instance = new BlastXMLQuery(); |
| 153 | + instance.setQueryReferences(sequences); |
| 154 | + // TODO review the generated test code and remove the default call to fail. |
| 155 | + fail("The test case is a prototype."); |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * Test of setDatabaseReferences method, of class BlastXMLQuery. |
| 160 | + */ |
| 161 | + @Test |
| 162 | + @Ignore public void testSetDatabaseReferences() { |
| 163 | + System.out.println("setDatabaseReferences"); |
| 164 | + List sequences = null; |
| 165 | + BlastXMLQuery instance = new BlastXMLQuery(); |
| 166 | + instance.setDatabaseReferences(sequences); |
| 167 | + // TODO review the generated test code and remove the default call to fail. |
| 168 | + fail("The test case is a prototype."); |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * Test of storeObjects method, of class BlastXMLQuery. |
| 173 | + */ |
| 174 | + @Test |
| 175 | + public void testStoreObjects() throws Exception { |
| 176 | + // not implemented yet |
| 177 | + } |
| 178 | + |
| 179 | + private File unpackResourceFile(String resource) { |
| 180 | + |
| 181 | + File file = null; |
| 182 | + URL res = getClass().getResource(resource); |
| 183 | + if (res == null) { |
| 184 | + throw new RuntimeException(" not supported"); |
| 185 | + } |
| 186 | + if (res.toString().startsWith("jar:")) { |
| 187 | + try { |
| 188 | + InputStream input = getClass().getResourceAsStream(resource); |
| 189 | + file = File.createTempFile("javawrapped", ".exe"); |
| 190 | + //if (!DEBUG) file.deleteOnExit(); |
| 191 | + file.setExecutable(true, true); |
| 192 | + OutputStream out = new FileOutputStream(file); |
| 193 | + int read; |
| 194 | + byte[] bytes = new byte[1024]; |
| 195 | + |
| 196 | + while ((read = input.read(bytes)) != -1) { |
| 197 | + out.write(bytes, 0, read); |
| 198 | + } |
| 199 | + out.close(); |
| 200 | + out.flush(); |
| 201 | + } catch (IOException ex) { |
| 202 | + throw new RuntimeException("Resource not available for this OS!"); |
| 203 | + } |
| 204 | + } else { |
| 205 | + //this will probably work in your IDE, but not from a JAR |
| 206 | + file = new File(res.getFile()); |
| 207 | + } |
| 208 | + |
| 209 | + if (file == null) { |
| 210 | + throw new RuntimeException("Error: File " + file + " not found!"); |
| 211 | + } |
| 212 | + return file; |
| 213 | + } |
| 214 | + |
| 215 | +} |
0 commit comments