Skip to content

Commit cd99d0e

Browse files
committed
Fixing the sifts test to not use external resources, biojava#606
1 parent 65326fa commit cd99d0e

3 files changed

Lines changed: 59 additions & 4 deletions

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/io/sifts/SiftsChainToUniprotMapping.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* SiftsChainEntry entry2 = sifts.getByChainId("1hiv", "A");
5050
* System.out.println(entry1.equals(entry2)); // true
5151
* </pre>
52-
*
52+
* See SIFTS project documentation: https://www.ebi.ac.uk/pdbe/docs/sifts/
5353
* @author dmyersturnbull
5454
* @see SiftsChainEntry
5555
* @since 3.0.7
@@ -59,7 +59,7 @@ public class SiftsChainToUniprotMapping {
5959
private final static Logger logger = LoggerFactory.getLogger(SiftsChainToUniprotMapping.class);
6060

6161

62-
private static File DEFAULT_FILE;
62+
public static File DEFAULT_FILE;
6363

6464
private static final String DEFAULT_FILENAME = "pdb_chain_uniprot.tsv";
6565
private static final URL DEFAULT_URL;
@@ -113,7 +113,12 @@ public static SiftsChainToUniprotMapping load(boolean useOnlyLocal) throws IOExc
113113
}
114114
}
115115

116-
private static SiftsChainToUniprotMapping build() throws IOException {
116+
/**
117+
* Builds the mapping by reading SIFTS the tsv file set in {@link #DEFAULT_FILE} variable.
118+
* @return
119+
* @throws IOException
120+
*/
121+
public static SiftsChainToUniprotMapping build() throws IOException {
117122
SiftsChainToUniprotMapping sifts = new SiftsChainToUniprotMapping();
118123
BufferedReader br = new BufferedReader(new FileReader(DEFAULT_FILE));
119124
String line = "";

biojava-structure/src/test/java/org/biojava/nbio/structure/io/sifts/SiftsChainToUniprotMappingTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,37 @@
2525

2626
import org.junit.Test;
2727

28+
import java.io.BufferedReader;
29+
import java.io.File;
2830
import java.io.IOException;
31+
import java.io.InputStreamReader;
32+
import java.io.PrintWriter;
2933

3034
import static org.junit.Assert.assertEquals;
3135

3236
/**
3337
* Tests {@link SiftsChainToUniprotMapping}.
3438
* @author dmyersturnbull
39+
* @author Jose Duarte
3540
* @since 3.0.7
41+
* @since 5.0.0 uses mock SIFTS data to avoid download of full file
3642
*/
3743
public class SiftsChainToUniprotMappingTest {
3844

3945
@Test
4046
public void test() throws IOException {
41-
SiftsChainToUniprotMapping sifts = SiftsChainToUniprotMapping.load();
47+
SiftsChainToUniprotMapping.DEFAULT_FILE = File.createTempFile("biojavaSiftsTest-", "");
48+
SiftsChainToUniprotMapping.DEFAULT_FILE.deleteOnExit();
49+
50+
BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("mock_sifts.tsv")));
51+
PrintWriter pw = new PrintWriter(SiftsChainToUniprotMapping.DEFAULT_FILE);
52+
String line;
53+
while ( (line = br.readLine())!=null)
54+
pw.println(line);
55+
pw.close();
56+
br.close();
57+
58+
SiftsChainToUniprotMapping sifts = SiftsChainToUniprotMapping.build();
4259
SiftsChainEntry entry = sifts.getByChainId("1hiv", "A");
4360
assertEquals("1hiv", entry.getPdbId());
4461
assertEquals("A", entry.getChainId());
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Mock SIFTS file for test SiftsChainToUniprotMappingTest
2+
# A few lines from beginning of file plus 1hiv entry needed for test.
3+
PDB CHAIN SP_PRIMARY RES_BEG RES_END PDB_BEG PDB_END SP_BEG SP_END
4+
101m A P02185 1 154 0 153 1 154
5+
102l A P00720 1 40 1 40 1 40
6+
102l A P00720 42 165 41 None 41 164
7+
102m A P02185 1 154 0 153 1 154
8+
103l A P00720 1 40 1 None 1 40
9+
103l A P00720 44 167 41 None 41 164
10+
103m A P02185 1 154 0 153 1 154
11+
104l A P00720 1 44 1 44 1 44
12+
104l A P00720 47 166 45 None 45 164
13+
104l B P00720 1 44 1 44 1 44
14+
104l B P00720 47 166 45 None 45 164
15+
104m A P02185 1 153 1 153 2 154
16+
105m A P02185 1 153 1 153 2 154
17+
106m A P02185 1 154 0 153 1 154
18+
107l A P00720 1 164 1 None 1 164
19+
107m A P02185 1 154 0 153 1 154
20+
108l A P00720 1 164 1 None 1 164
21+
108m A P02185 1 154 0 153 1 154
22+
109l A P00720 1 164 1 None 1 164
23+
109m A P02185 1 154 0 153 1 154
24+
10gs A P09211 1 209 None 209 2 210
25+
10gs B P09211 1 209 None 209 2 210
26+
10mh A P05102 1 327 1 327 1 327
27+
110l A P00720 1 164 1 None 1 164
28+
110m A P02185 1 154 0 153 1 154
29+
111l A P00720 1 164 1 None 1 164
30+
111m A P02185 1 154 0 153 1 154
31+
112l A P00720 1 164 1 None 1 164
32+
1hiv A P04585 1 99 1 99 489 587
33+
1hiv B P04585 1 99 1 99 489 587

0 commit comments

Comments
 (0)