Skip to content

Commit 17e641c

Browse files
committed
More fixes for PDB_DIR reading, plus some #111 and #155
1 parent 325c3a8 commit 17e641c

2 files changed

Lines changed: 40 additions & 45 deletions

File tree

biojava3-structure/src/main/java/org/biojava/bio/structure/io/LocalCacheStructureProvider.java

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
import org.biojava.bio.structure.Structure;
1515
import org.biojava.bio.structure.StructureException;
16-
import org.biojava.bio.structure.align.ce.AbstractUserArgumentProcessor;
16+
import org.biojava.bio.structure.align.util.UserConfiguration;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
1719

1820

1921

@@ -25,6 +27,8 @@
2527
*/
2628
public class LocalCacheStructureProvider implements StructureProvider{
2729

30+
private static final Logger logger = LoggerFactory.getLogger(LocalCacheStructureProvider.class);
31+
2832
FileParsingParameters params ;
2933

3034
String path;
@@ -38,14 +42,9 @@ public LocalCacheStructureProvider(){
3842

3943
// set the path to cache files
4044

45+
UserConfiguration config = new UserConfiguration();
4146

42-
String defaultPath = System.getProperty(AbstractUserArgumentProcessor.PDB_DIR);
43-
if ( defaultPath == null) {
44-
String property = "java.io.tmpdir";
45-
defaultPath = System.getProperty(property);
46-
}
47-
48-
setPath(defaultPath);
47+
setPath(config.getPdbFilePath());
4948

5049
}
5150

@@ -75,8 +74,7 @@ public Structure getStructureById(String pdbId) throws IOException {
7574
}
7675

7776
private PDBFileReader getPdbFilereader(){
78-
PDBFileReader reader = new PDBFileReader();
79-
reader.setPath(path);
77+
PDBFileReader reader = new PDBFileReader(path);
8078
reader.setAutoFetch(true);
8179
reader.setFileParsingParameters(params);
8280
reader.setPdbDirectorySplit(isSplit);
@@ -134,42 +132,36 @@ private void downloadBiolUnit(String pdbId, File localFile) throws IOException{
134132

135133
String ur = String.format(u,pdbId);
136134

137-
System.out.println("Fetching " + ur);
135+
logger.info("Fetching " + ur);
138136

139137
// prepare destination
140-
System.out.println("writing to " + localFile);
141-
142-
try {
143-
URL url = new URL(ur);
144-
145-
InputStream uStream = url.openStream();
146-
InputStream conn = new GZIPInputStream(uStream);
147-
148-
149-
FileOutputStream outPut = new FileOutputStream(localFile);
150-
GZIPOutputStream gzOutPut = new GZIPOutputStream(outPut);
151-
PrintWriter pw = new PrintWriter(gzOutPut);
152-
153-
BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(conn));
154-
String line;
155-
while ((line = fileBuffer.readLine()) != null) {
156-
pw.println(line);
157-
}
158-
pw.flush();
159-
pw.close();
160-
161-
outPut.flush();
162-
outPut.close();
163-
conn.close();
164-
uStream.close();
165-
166-
} catch (Exception e){
167-
System.err.println("Problem while downloading PDB ID " + pdbId + " from " + ur );
168-
169-
//e.printStackTrace();
170-
throw new IOException("Could not download biol. unit for PDB ID " + pdbId);
171-
138+
logger.info("writing to " + localFile);
139+
140+
141+
URL url = new URL(ur);
142+
143+
InputStream uStream = url.openStream();
144+
InputStream conn = new GZIPInputStream(uStream);
145+
146+
147+
FileOutputStream outPut = new FileOutputStream(localFile);
148+
GZIPOutputStream gzOutPut = new GZIPOutputStream(outPut);
149+
PrintWriter pw = new PrintWriter(gzOutPut);
150+
151+
BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(conn));
152+
String line;
153+
while ((line = fileBuffer.readLine()) != null) {
154+
pw.println(line);
172155
}
156+
pw.flush();
157+
pw.close();
158+
159+
outPut.flush();
160+
outPut.close();
161+
conn.close();
162+
uStream.close();
163+
164+
173165
}
174166

175167
public void setFileParsingParameters(FileParsingParameters params) {

biojava3-structure/src/main/java/org/biojava/bio/structure/scop/ScopInstallation.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@
4343

4444
import org.biojava.bio.structure.Structure;
4545
import org.biojava.bio.structure.StructureTools;
46-
import org.biojava.bio.structure.align.ce.AbstractUserArgumentProcessor;
4746
import org.biojava.bio.structure.align.util.UserConfiguration;
4847
import org.biojava3.core.util.InputStreamProvider;
48+
import org.slf4j.Logger;
49+
import org.slf4j.LoggerFactory;
4950

5051

5152
/** This class provides access to the SCOP protein structure classification.
@@ -68,6 +69,8 @@
6869
public class ScopInstallation implements LocalScopDatabase {
6970

7071
public static final String DEFAULT_VERSION = "1.75";
72+
73+
private static final Logger logger = LoggerFactory.getLogger(ScopInstallation.class);
7174

7275
protected String scopVersion;
7376

@@ -790,7 +793,7 @@ protected void downloadComFile() throws FileNotFoundException, IOException{
790793
}
791794

792795
protected void downloadFileFromRemote(URL remoteURL, File localFile) throws FileNotFoundException, IOException{
793-
System.out.println("downloading " + remoteURL + " to: " + localFile);
796+
logger.info("Downloading " + remoteURL + " to: " + localFile);
794797
FileOutputStream out = new FileOutputStream(localFile);
795798

796799
InputStream in = remoteURL.openStream();

0 commit comments

Comments
 (0)