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 Jun 30, 2010 021 * Author: Andreas Prlic 022 * 023 */ 024 025package demo; 026 027 028import org.biojava.nbio.structure.Atom; 029import org.biojava.nbio.structure.Structure; 030import org.biojava.nbio.structure.StructureTools; 031import org.biojava.nbio.structure.align.StructureAlignment; 032import org.biojava.nbio.structure.align.StructureAlignmentFactory; 033import org.biojava.nbio.structure.align.ce.CeMain; 034import org.biojava.nbio.structure.align.model.AFPChain; 035import org.biojava.nbio.structure.align.model.AfpChainWriter; 036import org.biojava.nbio.structure.align.util.AFPChainScorer; 037import org.biojava.nbio.structure.align.util.AtomCache; 038import org.biojava.nbio.structure.io.FileParsingParameters; 039import org.biojava.nbio.structure.scop.*; 040 041import java.util.List; 042 043/** A class demonstrating the use of the SCOP parsing tools 044 * 045 * @author Andreas Prlic 046 * 047 */ 048public class DemoSCOP 049{ 050 public static void main(String[] args){ 051 052 DemoSCOP demo = new DemoSCOP(); 053 054 055 // this creates a local copy of SCOP 056 ScopDatabase scop = new ScopInstallation(); 057 058 // an alternative would be this one, which fetches data dynamically 059 //ScopDatabase scop = new RemoteScopInstallation(); 060 061 ScopFactory.setScopDatabase(scop); 062 063 demo.getCategories(); 064 demo.printDomainsForPDB(); 065 demo.traverseHierarchy(); 066 demo.alignSuperfamily(); 067 } 068 069 /** Traverse throught the SCOP hierarchy 070 * 071 */ 072 public void traverseHierarchy() 073 { 074 String pdbId = "4HHB"; 075 // download SCOP if required and load into memory 076 ScopDatabase scop = ScopFactory.getSCOP(); 077 078 List<ScopDomain> domains = scop.getDomainsForPDB(pdbId); 079 080 // show the hierachy for the first domain: 081 082 ScopNode node = scop.getScopNode(domains.get(0).getSunid()); 083 084 while (node != null){ 085 086 System.out.println("This node: sunid:" + node.getSunid() ); 087 System.out.println(scop.getScopDescriptionBySunid(node.getSunid())); 088 node = scop.getScopNode(node.getParentSunid()); 089 } 090 091 } 092 093 /** Get various categories 094 * 095 */ 096 public void getCategories(){ 097 // download SCOP if required and load into memory 098 ScopDatabase scop = ScopFactory.getSCOP(); 099 List<ScopDescription> superfams = scop.getByCategory(ScopCategory.Superfamily); 100 101 System.out.println("Total nr. of superfamilies:" + superfams.size()); 102 103 List<ScopDescription> folds = scop.getByCategory(ScopCategory.Fold); 104 System.out.println("Total nr. of folds:" + folds.size()); 105 106 } 107 108 public void alignSuperfamily(){ 109 // download SCOP if required and load into memory 110 ScopDatabase scop = ScopFactory.getSCOP(); 111 List<ScopDescription> superfams = scop.getByCategory(ScopCategory.Superfamily); 112 113 System.out.println("Total nr. of superfamilies:" + superfams.size()); 114 115 116 // configure where to load PDB files from and 117 // what information to load 118 AtomCache cache = new AtomCache(); 119 FileParsingParameters fileparams = new FileParsingParameters() ; 120 fileparams.setAlignSeqRes(false); 121 fileparams.setParseSecStruc(false); 122 cache.setFileParsingParams(fileparams); 123 124 // get tge first superfamily 125 ScopDescription superfam1 = superfams.get(0); 126 System.out.println("First superfamily: " + superfam1); 127 128 ScopNode node = scop.getScopNode(superfam1.getSunID()); 129 System.out.println("scopNode for first superfamily:" + node); 130 131 List<ScopDomain> doms4superfam1 = scop.getScopDomainsBySunid(superfam1.getSunID()); 132 ScopDomain dom1 = doms4superfam1.get(0); 133 134 // align the first domain against all others members of this superfamily 135 for ( int i = 1 ; i < doms4superfam1.size() ; i ++){ 136 137 ScopDomain dom2 = doms4superfam1.get(i); 138 139 try { 140 Structure s1 = cache.getStructureForDomain(dom1); 141 Structure s2 = cache.getStructureForDomain(dom2); 142 143 Atom[] ca1 = StructureTools.getAtomCAArray(s1); 144 Atom[] ca2 = StructureTools.getAtomCAArray(s2); 145 StructureAlignment ce = StructureAlignmentFactory.getAlgorithm(CeMain.algorithmName); 146 AFPChain afpChain = ce.align(ca1, ca2); 147 148 //System.out.println(afpChain.toCE(ca1, ca2)); 149 150 //StructureAlignmentDisplay.display(afpChain, ca1, ca2); 151 152 System.out.println(dom1.getScopId() + " vs. " + dom2.getScopId()+ " :" + afpChain.getProbability()); 153 double tmScore = AFPChainScorer.getTMScore(afpChain, ca1, ca2); 154 afpChain.setTMScore(tmScore); 155 System.out.println(AfpChainWriter.toScoresList(afpChain)); 156 157 } catch (Exception e){ 158 e.printStackTrace(); 159 } 160 } 161 162 } 163 164 public void printDomainsForPDB(){ 165 String pdbId = "4HHB"; 166 167 // download SCOP if required and load into memory 168 ScopDatabase scop = ScopFactory.getSCOP(); 169 170 List<ScopDomain> domains = scop.getDomainsForPDB(pdbId); 171 172 System.out.println(domains); 173 174 } 175 176 177}