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 */ 021package org.biojava.nbio.structure.io; 022 023import java.io.IOException; 024import java.io.InputStream; 025 026import org.biojava.nbio.structure.Structure; 027import org.biojava.nbio.structure.align.util.UserConfiguration; 028import org.biojava.nbio.structure.io.mmtf.MmtfActions; 029 030/** 031 * A class to read MMTF files and cache them locally. 032 * @author Anthony Bradley 033 * 034 */ 035public class MMTFFileReader extends LocalPDBDirectory { 036 037 038 public static final String[] MMTF_SPLIT_DIR = new String[]{"data","structures","divided" ,"mmtf"}; 039 public static final String[] MMTF_OBSOLETE_DIR = new String[]{"data","structures","obsolete","mmtf"}; 040 041 public static void main(String[] args) throws Exception { 042 MMTFFileReader reader = new MMTFFileReader(); 043 FileParsingParameters params = new FileParsingParameters(); 044 reader.setFileParsingParameters(params); 045 Structure struc = reader.getStructureById("1m4x"); 046 System.out.println(struc); 047 } 048 049 /** 050 * Constructs a new {@link MMTFFileReader}, initializing the extensions member variable. 051 * The path is initialized in the same way as {@link UserConfiguration}, 052 * i.e. to system property/environment variable {@link UserConfiguration#PDB_DIR}. 053 * Both autoFetch and splitDir are initialized to false 054 */ 055 public MMTFFileReader() { 056 this(null); 057 } 058 059 /** 060 * Constructs a new {@link MMTFFileReader}, initializing the extensions member variable. 061 * The path is initialized to the given path, both autoFetch and splitDir are initialized to false. 062 */ 063 public MMTFFileReader(String path) { 064 super(path); 065 addExtension(".mmtf"); 066 addExtension(".mmtf.gz"); 067 } 068 069 @Override 070 public Structure getStructure(InputStream inStream) throws IOException { 071 return MmtfActions.readFromInputStream(inStream); 072 } 073 074 @Override 075 protected String getFilename(String pdbId) { 076 return pdbId.toLowerCase()+".mmtf.gz"; 077 } 078 079 @Override 080 protected String[] getSplitDirPath() { 081 return MMTF_SPLIT_DIR; 082 } 083 084 @Override 085 protected String[] getObsoleteDirPath() { 086 return MMTF_OBSOLETE_DIR; 087 } 088 089 090}