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 Sep 15, 2009 021 * Author: Andreas Prlic 022 * 023 */ 024 025package org.biojava.nbio.structure.align.ce; 026 027 028import org.biojava.nbio.structure.Atom; 029import org.biojava.nbio.structure.Group; 030import org.biojava.nbio.structure.StructureException; 031import org.biojava.nbio.structure.align.AbstractStructureAlignment; 032import org.biojava.nbio.structure.align.StructureAlignment; 033import org.biojava.nbio.structure.align.model.AFPChain; 034import org.biojava.nbio.structure.jama.Matrix; 035 036/** The main class of the Java implementation of the Combinatorial Extension Algorithm (CE), 037 * as has been originally developed by I. Shindyalov and P.Bourne (1998). 038 * The original CE paper is available from here: <a href="http://peds.oxfordjournals.org/cgi/content/short/11/9/739">http://peds.oxfordjournals.org/cgi/content/short/11/9/739</a> 039 * 040 * For a demo of how to use this algorithm, visit the BioJava web site: 041 * <a href="">CE usage example</a>. 042 * 043 * The BioJava CE version is based on CE version 2.3 (2003 or 2004). 044 * 045 * @author Andreas Prlic. 046 * 047 */ 048public class CeMain extends AbstractStructureAlignment implements StructureAlignment { 049 050 public static final String algorithmName = "jCE"; 051 052 /** 053 * version history: 054 * 1.2 - Added more parameters to the command line, including -maxOptRMSD 055 * 1.1 - Additional parameters 056 * 1.0 - Initial port from C code 057 */ 058 public static final String version = "1.2"; 059 060 protected CeParameters params; 061 protected CECalculator calculator; 062 private Atom[] ca2clone; 063 064 public CeMain(){ 065 super(); 066 params = new CeParameters(); 067 calculator = new CECalculator(params); 068 } 069 070 071 /** 072 * Example Parameters: 073 * 074 * -pdbFilePath /tmp -autoFetch -printCE -pdb1 1cnv -pdb2 3cna 075 * 076 */ 077 public static void main(String[] args) throws Exception { 078 CeUserArgumentProcessor processor = new CeUserArgumentProcessor(); //Responsible for creating a CeMain instance 079 processor.process(args); 080 } 081 082 /** 083 * Align ca2 onto ca1. 084 */ 085 @Override 086 public AFPChain align(Atom[] ca1, Atom[] ca2, Object param) throws StructureException{ 087 if ( ! (param instanceof CeParameters)) 088 throw new IllegalArgumentException("CE algorithm needs an object of call CeParameters as argument."); 089 090 params = (CeParameters) param; 091 092 // we don't want to rotate input atoms, do we? 093 ca2clone = new Atom[ca2.length]; 094 095 int pos = 0; 096 for (Atom a : ca2){ 097 Group g = (Group)a.getGroup().clone(); // works because each group has only a CA atom 098 099 ca2clone[pos] = g.getAtom(a.getName()); 100 101 pos++; 102 } 103 104 calculator = new CECalculator(params); 105 106 //Build alignment ca1 to ca2-ca2 107 AFPChain afpChain = new AFPChain(algorithmName); 108 afpChain = calculator.extractFragments(afpChain, ca1, ca2clone); 109 calculator.traceFragmentMatrix( afpChain,ca1, ca2clone); 110 calculator.nextStep( afpChain,ca1, ca2clone); 111 112 afpChain.setAlgorithmName(getAlgorithmName()); 113 afpChain.setVersion(version); 114 115 // Try to guess names 116 117 if (ca1.length!=0 && ca1[0].getGroup().getChain()!=null && ca1[0].getGroup().getChain().getStructure()!=null) 118 afpChain.setName1(ca1[0].getGroup().getChain().getStructure().getName()); 119 120 if (ca2.length!=0 && ca2[0].getGroup().getChain()!=null && ca2[0].getGroup().getChain().getStructure()!=null) 121 afpChain.setName2(ca2[0].getGroup().getChain().getStructure().getName()); 122 123 if ( afpChain.getNrEQR() == 0) 124 return afpChain; 125 126 // Set the distance matrix 127 128 int winSize = params.getWinSize(); 129 int winSizeComb1 = (winSize-1)*(winSize-2)/2; 130 double[][] m = calculator.initSumOfDistances(ca1.length, ca2.length, winSize, winSizeComb1, ca1, ca2clone); 131 afpChain.setDistanceMatrix(new Matrix(m)); 132 afpChain.setSequentialAlignment(true); 133 134 return afpChain; 135 } 136 137 138 139 140 @Override 141 public AFPChain align(Atom[] ca1, Atom[] ca2) throws StructureException { 142 143 if (params == null) 144 params = new CeParameters(); 145 146 return align(ca1,ca2,params); 147 } 148 149 @Override 150 public String getAlgorithmName() { 151 152 return CeMain.algorithmName; 153 } 154 155 @Override 156 public ConfigStrucAligParams getParameters() { 157 158 return params; 159 } 160 161 @Override 162 public void setParameters(ConfigStrucAligParams params){ 163 if (! (params instanceof CeParameters )){ 164 throw new IllegalArgumentException("provided parameter object is not of type CeParameter"); 165 } 166 this.params = (CeParameters) params; 167 } 168 169 @Override 170 public String getVersion() { 171 return CeMain.version; 172 } 173 174 public CECalculator getCECalculator() { 175 return calculator; 176 } 177}