001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 * Created on 16.03.2004 021 * @author Andreas Prlic 022 * 023 * 024 */ 025package org.biojava.nbio.structure.io; 026 027import org.biojava.nbio.structure.Structure; 028import org.biojava.nbio.structure.align.util.UserConfiguration; 029import java.io.IOException; 030import java.io.InputStream; 031 032/** 033 * The wrapper class for parsing a PDB file. 034 * 035 * <p> 036 * Several flags can be set for this class 037 * <ul> 038 * <li> Parameters can be set using the {@link #setFileParsingParameters(FileParsingParameters)}</li> 039 * </ul> 040 * 041 *<h2>Example</h2> 042 * <p> 043 * Q: How can I get a Structure object from a PDB file? 044 * <p> 045 * A: 046 * <pre> 047 * public {@link Structure} loadStructure(String pathToPDBFile){ 048 * {@link PDBFileReader} pdbreader = new {@link PDBFileReader}(); 049 * 050 * {@link Structure} structure = null; 051 * try{ 052 * structure = pdbreader.getStructure(pathToPDBFile); 053 * System.out.println(structure); 054 * } catch (IOException e) { 055 * e.printStackTrace(); 056 * } 057 * return structure; 058 * } 059 * </pre> 060 * 061 * Access PDB files from a directory, take care of compressed PDB files 062 * <pre> 063 * public {@link Structure} loadStructureById() { 064 * String path = "/path/to/PDB/directory/"; 065 * 066 * {@link PDBFileReader} pdbreader = new {@link PDBFileReader}(); 067 * pdbreader.setPath(path); 068 * {@link Structure} structure = null; 069 * try { 070 * structure = pdbreader.getStructureById("5pti"); 071 * } catch (IOException e){ 072 * e.printStackTrace(); 073 * } 074 * return structure; 075 * 076 * } 077 * </pre> 078 * 079 * 080 * @author Andreas Prlic 081 * 082 */ 083public class PDBFileReader extends LocalPDBDirectory { 084 085 //private static final Logger logger = LoggerFactory.getLogger(PDBFileReader.class); 086 087 public static final String[] PDB_SPLIT_DIR = new String[]{"data","structures","divided" ,"pdb"}; 088 public static final String[] PDB_OBSOLETE_DIR = new String[]{"data","structures","obsolete","pdb"}; 089 090 091 /** 092 * Constructs a new PDBFileReader, initializing the extensions member variable. 093 * The path is initialized in the same way as {@link UserConfiguration}, 094 * i.e. to system property/environment variable {@link UserConfiguration#PDB_DIR}. 095 * Both autoFetch and splitDir are initialized to false 096 */ 097 public PDBFileReader() { 098 this(null); 099 } 100 101 /** 102 * Constructs a new PDBFileReader, initializing the extensions member variable. 103 * The path is initialized to the given path, both autoFetch and splitDir are initialized to false. 104 * 105 * <p>If path is null, initialize using the system property/environment variable 106 * {@link UserConfiguration#PDB_DIR}. 107 * @param path Path to the PDB file directory 108 */ 109 public PDBFileReader(String path) { 110 super(path); 111 112 addExtension(".ent"); 113 addExtension(".pdb"); 114 addExtension(".ent.gz"); 115 addExtension(".pdb.gz"); 116 addExtension(".ent.Z"); 117 addExtension(".pdb.Z"); 118 } 119 120 @Override 121 protected String getFilename(String pdbId) { 122 return "pdb"+pdbId.toLowerCase()+".ent.gz"; 123 } 124 125 @Override 126 public Structure getStructure(InputStream inStream) throws IOException { 127 PDBFileParser pdbpars = new PDBFileParser(); 128 pdbpars.setFileParsingParameters(getFileParsingParameters()); 129 130 Structure struc = pdbpars.parsePDBFile(inStream) ; 131 return struc ; 132 } 133 134 @Override 135 protected String[] getSplitDirPath() { 136 return PDB_SPLIT_DIR; 137 } 138 139 @Override 140 protected String[] getObsoleteDirPath() { 141 return PDB_OBSOLETE_DIR; 142 } 143 144 145 146}