Skip to content

Commit

Permalink
More fixes for PDB_DIR reading, plus some biojava#111 and biojava#155
Browse files Browse the repository at this point in the history
  • Loading branch information
josemduarte committed Oct 1, 2014
1 parent 325c3a8 commit 17e641c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

import org.biojava.bio.structure.Structure;
import org.biojava.bio.structure.StructureException;
import org.biojava.bio.structure.align.ce.AbstractUserArgumentProcessor;
import org.biojava.bio.structure.align.util.UserConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



Expand All @@ -25,6 +27,8 @@
*/
public class LocalCacheStructureProvider implements StructureProvider{

private static final Logger logger = LoggerFactory.getLogger(LocalCacheStructureProvider.class);

FileParsingParameters params ;

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

// set the path to cache files

UserConfiguration config = new UserConfiguration();

String defaultPath = System.getProperty(AbstractUserArgumentProcessor.PDB_DIR);
if ( defaultPath == null) {
String property = "java.io.tmpdir";
defaultPath = System.getProperty(property);
}

setPath(defaultPath);
setPath(config.getPdbFilePath());

}

Expand Down Expand Up @@ -75,8 +74,7 @@ public Structure getStructureById(String pdbId) throws IOException {
}

private PDBFileReader getPdbFilereader(){
PDBFileReader reader = new PDBFileReader();
reader.setPath(path);
PDBFileReader reader = new PDBFileReader(path);
reader.setAutoFetch(true);
reader.setFileParsingParameters(params);
reader.setPdbDirectorySplit(isSplit);
Expand Down Expand Up @@ -134,42 +132,36 @@ private void downloadBiolUnit(String pdbId, File localFile) throws IOException{

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

System.out.println("Fetching " + ur);
logger.info("Fetching " + ur);

// prepare destination
System.out.println("writing to " + localFile);

try {
URL url = new URL(ur);

InputStream uStream = url.openStream();
InputStream conn = new GZIPInputStream(uStream);


FileOutputStream outPut = new FileOutputStream(localFile);
GZIPOutputStream gzOutPut = new GZIPOutputStream(outPut);
PrintWriter pw = new PrintWriter(gzOutPut);

BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(conn));
String line;
while ((line = fileBuffer.readLine()) != null) {
pw.println(line);
}
pw.flush();
pw.close();

outPut.flush();
outPut.close();
conn.close();
uStream.close();

} catch (Exception e){
System.err.println("Problem while downloading PDB ID " + pdbId + " from " + ur );

//e.printStackTrace();
throw new IOException("Could not download biol. unit for PDB ID " + pdbId);

logger.info("writing to " + localFile);


URL url = new URL(ur);

InputStream uStream = url.openStream();
InputStream conn = new GZIPInputStream(uStream);


FileOutputStream outPut = new FileOutputStream(localFile);
GZIPOutputStream gzOutPut = new GZIPOutputStream(outPut);
PrintWriter pw = new PrintWriter(gzOutPut);

BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(conn));
String line;
while ((line = fileBuffer.readLine()) != null) {
pw.println(line);
}
pw.flush();
pw.close();

outPut.flush();
outPut.close();
conn.close();
uStream.close();


}

public void setFileParsingParameters(FileParsingParameters params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@

import org.biojava.bio.structure.Structure;
import org.biojava.bio.structure.StructureTools;
import org.biojava.bio.structure.align.ce.AbstractUserArgumentProcessor;
import org.biojava.bio.structure.align.util.UserConfiguration;
import org.biojava3.core.util.InputStreamProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


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

public static final String DEFAULT_VERSION = "1.75";

private static final Logger logger = LoggerFactory.getLogger(ScopInstallation.class);

protected String scopVersion;

Expand Down Expand Up @@ -790,7 +793,7 @@ protected void downloadComFile() throws FileNotFoundException, IOException{
}

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

InputStream in = remoteURL.openStream();
Expand Down

0 comments on commit 17e641c

Please sign in to comment.