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.quaternary;
022
023import java.util.Collections;
024import java.util.List;
025
026
027/** A class to resolve the operators for transformations
028 *
029 * @author Peter Rose
030 *
031 */
032public class OperatorResolver {
033
034        /**
035         * Unary operator expressions are parsed stored unary operations.
036         * For example the operator expression "(1,2,3,4)" is stored as a list 1,2,3,4
037         */
038        private List<String> unaryOperators = Collections.emptyList();
039        /**
040         * Binary Operator expressions are parsed and stored as ordered pairs of
041         * binary operators. For example the operator expression "(1-60)(61-88)"
042         * is saved as a list of pairs {1,61}, {1,62}, .., {1,88}, ... {60,88}.
043         */
044        private List<OrderedPair<String>> binaryOperators = Collections.emptyList();
045
046
047        /**
048         * Parses the operator expression and save the operators as a list
049         * of unary or binary operators (i.e. matrix multiplication, see below).
050         * Operation expressions are given in a compact notation and specify
051         * matrices from the operations list.
052         * An operation expression can be a comma-separated list 1, 5, 9,
053         * a dash-delimited range 1-60 or a matrix multiplication involving two
054         * or more lists or ranges. For instance, (X0)(1-20) specifies the
055         * portion of the X174 procapsid crystal asymmetric unit belonging to
056         * the first independent virus particle and corresponds
057         * to the 20 transformations [X0][1], [X0][2], ... , [X0][20].
058         * See C. Lawson, Acta Cryst., D64, 874-882, 2008.
059         *
060         * @param operatorExpression the operator expression to be parsed
061         */
062        public  void parseOperatorExpressionString(String operatorExpression) throws IllegalArgumentException {
063                String expression = operatorExpression.trim();
064
065                // remove single quotes, i.e. '(1-49)' in 1CGM
066                expression = expression.replaceAll("'", "");
067
068                if (BioAssemblyTools.isUnaryExpression(expression)) {
069                        unaryOperators = BioAssemblyTools.parseUnaryOperatorExpression(expression);
070                } else {
071                        binaryOperators = BioAssemblyTools.parseBinaryOperatorExpression(expression);
072                }
073
074                //System.out.println("OperatorResolver: unary: " + unaryOperators + " | binary: " + binaryOperators);
075        }
076
077
078
079
080
081        public void setUnaryOperators(List<String> unaryOperators) {
082                this.unaryOperators = unaryOperators;
083        }
084
085
086
087
088
089        public void setBinaryOperators(List<OrderedPair<String>> binaryOperators) {
090                this.binaryOperators = binaryOperators;
091        }
092
093        /**
094         * Returns a list of operators for this assembly. The operators
095         * refer to the transformations that should be applied to
096         * the asym ids to generate this macromolecular assembly.
097         * @return the unary operators for this assembly
098         */
099        public List<String> getUnaryOperators() {
100                return unaryOperators;
101        }
102
103        /**
104         * Returns a list of operators for this assembly. The operators
105         * refer to the transformations that should be applied to
106         * the asym ids to generate this macromolecular assembly.
107         * Each ordered pair refers to the multiplication
108         * of the two transformation matrices in the
109         * pdbx_structure_oper_list category.
110         * @return the binary operators for this assembly
111         */
112        public List<OrderedPair<String>> getBinaryOperators() {
113                return binaryOperators;
114        }
115
116
117}