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 Jan 21, 2010
021 *
022 */
023package demo;
024
025
026import org.biojava.nbio.structure.Atom;
027import org.biojava.nbio.structure.Structure;
028import org.biojava.nbio.structure.StructureTools;
029import org.biojava.nbio.structure.align.StructureAlignment;
030import org.biojava.nbio.structure.align.StructureAlignmentFactory;
031import org.biojava.nbio.structure.align.ce.CeMain;
032import org.biojava.nbio.structure.align.ce.CeParameters;
033import org.biojava.nbio.structure.align.model.AFPChain;
034import org.biojava.nbio.structure.align.util.AFPChainScorer;
035import org.biojava.nbio.structure.align.util.AtomCache;
036import org.biojava.nbio.structure.align.xml.AFPChainXMLConverter;
037
038
039/** Example of how to run a structure alignment using the CE algorithm.
040 *
041 * @author Andreas Prlic
042 *
043 */
044public class DemoCE {
045
046        public static void main(String[] args){
047
048                //String name1 = "4hhb.A";
049                //String name2 = "4hhb.B";
050
051                String name1 = "1cdg.A";
052                String name2 = "1tim.B";
053
054
055
056                AtomCache cache = new AtomCache();
057
058                Structure structure1 = null;
059                Structure structure2 = null;
060
061                try {
062
063                   StructureAlignment algorithm  = StructureAlignmentFactory.getAlgorithm(CeMain.algorithmName);
064
065                        structure1 = cache.getStructure(name1);
066                        structure2 = cache.getStructure(name2);
067
068                        Atom[] ca1 = StructureTools.getAtomCAArray(structure1);
069                        Atom[] ca2 = StructureTools.getAtomCAArray(structure2);
070
071                        // get default parameters
072                        CeParameters params = new CeParameters();
073
074                        // add more print
075                        params.setShowAFPRanges(true);
076
077                        // set the maximum gap size to unlimited
078                        params.setMaxGapSize(-1);
079
080                        AFPChain afpChain = algorithm.align(ca1,ca2,params);
081
082                        afpChain.setName1(name1);
083                        afpChain.setName2(name2);
084
085                        // flexible original results:
086                        System.out.println(afpChain.toFatcat(ca1,ca2));
087
088                        System.out.println(afpChain.toRotMat());
089                        //System.out.println(afpChain.toCE(ca1, ca2));
090
091                        System.out.println(AFPChainXMLConverter.toXML(afpChain,ca1,ca2));
092
093                        double tmScore = AFPChainScorer.getTMScore(afpChain, ca1, ca2);
094                        afpChain.setTMScore(tmScore);
095
096                        //System.out.println(AfpChainWriter.toWebSiteDisplay(afpChain, ca1, ca2));
097
098                        printScores(afpChain);
099                } catch (Exception e) {
100                        e.printStackTrace();
101                        return;
102                }
103        }
104
105        private static void printScores(AFPChain afpChain) {
106                System.out.println("=====================");
107                System.out.println("The main scores for the alignment:");
108
109                System.out.println("EQR       :\t" + afpChain.getNrEQR() + "\t The number of residues on structurally equivalent positions.")  ;
110                System.out.println("RMSD      :\t" + String.format("%.2f",afpChain.getTotalRmsdOpt() )+ "\t The RMSD of the alignment");
111                System.out.println("Z-score   :\t" + afpChain.getProbability() + "\t The Z-score of the alignment (CE)");
112                System.out.println("TM-score  :\t" + String.format("%.2f",afpChain.getTMScore()) + "\t The TM-score of the alignment.");
113                System.out.println("");
114                System.out.println("Other scores:");
115                System.out.println("Identity  :\t" + String.format("%.2f",afpChain.getIdentity())   + "\t The percent of residues that are sequence-identical in the alignment.");
116                System.out.println("Similarity:\t" + String.format("%.2f",afpChain.getSimilarity()) + "\t The percent of residues in the alignment that are sequence-similar.");
117                System.out.println("Coverage1 :\t" + afpChain.getCoverage1() + " %\t Percent of protein 1 that is covered with the alignment.");
118                System.out.println("Coverage2 :\t" + afpChain.getCoverage2() + " %\t Percent of protein 2 that is covered with the alignment.");
119                int dab = afpChain.getCa1Length()+afpChain.getCa2Length() - 2 * afpChain.getNrEQR();
120                System.out.println("Distance  :\t" + dab + "\t Distance between folds a,b ");
121                double sab = 2 * afpChain.getNrEQR() / (double)( afpChain.getCa1Length() + afpChain.getCa2Length());
122                System.out.println("Rel. Sim. :\t" + String.format("%.2f",sab) + "\t Relative similarity");
123
124
125
126        }
127}