@Override public Structure getStructureById(String pdbId) throws IOException { InputStream inStream = getInputStream(pdbId); return getStructure(inStream); }
protected boolean checkFileExists(String pdbId){ try { File path = getLocalFile(pdbId); if ( path != null) return true; } catch(IOException e) {} return false; }
boolean deleted = false; ObsoleteBehavior obsolete = getObsoleteBehavior(); setObsoleteBehavior(ObsoleteBehavior.FETCH_OBSOLETE); File existing = getLocalFile(pdbId); while(existing != null) { assert(existing.exists()); // should exist unless concurrency problems if( getFetchBehavior() == FetchBehavior.LOCAL_ONLY) { throw new RuntimeException("Refusing to delete from LOCAL_ONLY directory"); existing = getLocalFile(pdbId); setObsoleteBehavior(obsolete);
File existing = getLocalFile(pdbId); switch(fetchBehavior) { case LOCAL_ONLY: if( existing == null ) { throw new IOException(String.format("Structure %s not found in %s " + "and configured not to download.",pdbId,getPath())); } else { return existing; return downloadStructure(current, splitDirURL,false, existing); } else if(obsoleteBehavior == ObsoleteBehavior.FETCH_OBSOLETE && PDBStatus.getStatus(pdbId) == Status.OBSOLETE) { return downloadStructure(pdbId, obsoleteDirURL, true, existing); } else { return downloadStructure(pdbId, splitDirURL, false, existing);
throws IOException{ File dir = getDir(pdbId,obsolete); File realFile = new File(dir,getFilename(pdbId)); if (getFilename(pdbId).endsWith(".mmtf.gz")){ ftp = CodecUtils.getMmtfEntryUrl(pdbId, true, false); } else { ftp = String.format("%s%s/%s/%s", serverName, pathOnServer, pdbId.substring(1,3).toLowerCase(), getFilename(pdbId)); if (existingFile!=null) { serverFileDate = getLastModifiedTime(url);
String[] split = getSplitDirPath(); String[] obsolete = getObsoleteDirPath();
searchdirs.add(splitdir); if(getObsoleteBehavior() == ObsoleteBehavior.FETCH_OBSOLETE) { File obsdir = new File(obsoleteDirPath,middle); searchdirs.add(obsdir); for(String ex : getExtensions() ){ File f = new File(searchdir,prefix + pdbId.toLowerCase() + ex) ; if ( f.exists()) {
/** * Download a structure, but don't parse it yet or store it in memory. * * Used to pre-fetch large numbers of structures. * @param pdbId * @throws IOException */ public void prefetchStructure(String pdbId) throws IOException { if ( pdbId.length() != 4) throw new IOException("The provided ID does not look like a PDB ID : " + pdbId); // Check existing File file = downloadStructure(pdbId); if(!file.exists()) { throw new IOException("Structure "+pdbId+" not found and unable to download."); } }
/** * Load or download the specified structure and return it as an InputStream * for direct parsing. * @param pdbId * @return * @throws IOException */ protected InputStream getInputStream(String pdbId) throws IOException{ if ( pdbId.length() != 4) throw new IOException("The provided ID does not look like a PDB ID : " + pdbId); // Check existing File file = downloadStructure(pdbId); if(!file.exists()) { throw new IOException("Structure "+pdbId+" not found and unable to download."); } InputStreamProvider isp = new InputStreamProvider(); InputStream inputStream = isp.getInputStream(file); return inputStream; }