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