001package com.hfg.bio.seq.pattern; 002 003import com.hfg.math.Range; 004import com.hfg.util.StringBuilderPlus; 005 006//------------------------------------------------------------------------------ 007/** 008 Prosite pattern position. 009 <div> 010 @author J. Alex Taylor, hairyfatguy.com 011 </div> 012 */ 013//------------------------------------------------------------------------------ 014// com.hfg Library 015// 016// This library is free software; you can redistribute it and/or 017// modify it under the terms of the GNU Lesser General Public 018// License as published by the Free Software Foundation; either 019// version 2.1 of the License, or (at your option) any later version. 020// 021// This library is distributed in the hope that it will be useful, 022// but WITHOUT ANY WARRANTY; without even the implied warranty of 023// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 024// Lesser General Public License for more details. 025// 026// You should have received a copy of the GNU Lesser General Public 027// License along with this library; if not, write to the Free Software 028// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 029// 030// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 031// jataylor@hairyfatguy.com 032//------------------------------------------------------------------------------ 033 034public class PrositePatternPosition 035{ 036 private PrositePatternPositionType mType; 037 private String mResidues; 038 private Range<Integer> mCountRange; 039 private boolean mLazyMatchMode; 040 private boolean mMismatchNotAllowed; 041 042 //########################################################################### 043 // PACKAGE METHODS 044 //########################################################################### 045 046 //------------------------------------------------------------------------ 047 @Override 048 public String toString() 049 { 050 StringBuilderPlus buffer = new StringBuilderPlus(); 051 052 if (getType().equals(PrositePatternPositionType.NOT)) 053 { 054 buffer.append("^"); 055 } 056 else if (getType().equals(PrositePatternPositionType.ONE_OF)) 057 { 058 buffer.append("["); 059 } 060 061 String residues = getResidues(); 062 buffer.append(residues != null ? residues : "x"); 063 064 if (getType().equals(PrositePatternPositionType.ONE_OF)) 065 { 066 buffer.append("]"); 067 } 068 069 Range<Integer> countRange = getCountRange(); 070 if (countRange != null) 071 { 072 buffer.append("(") 073 .append(countRange.getStart()) 074 .delimitedAppend(countRange.length() > 1 ? countRange.getEnd() : "") 075 .append(")"); 076 } 077 078 return buffer.toString(); 079 } 080 081 //------------------------------------------------------------------------ 082 void setType(PrositePatternPositionType inValue) 083 { 084 mType = inValue; 085 } 086 087 //------------------------------------------------------------------------ 088 PrositePatternPositionType getType() 089 { 090 return mType; 091 } 092 093 //------------------------------------------------------------------------ 094 void setResidues(String inValue) 095 { 096 mResidues = inValue; 097 } 098 099 //------------------------------------------------------------------------ 100 String getResidues() 101 { 102 return mResidues; 103 } 104 105 //------------------------------------------------------------------------ 106 boolean matchesResidue(char inTargetResidue) 107 { 108 boolean result = false; 109 switch (mType) 110 { 111 case IS_ANY: 112 result = true; 113 break; 114 case IS: 115 case ONE_OF: 116 result = mResidues.contains(inTargetResidue + ""); 117 break; 118 case NOT: 119 result = ! mResidues.contains(inTargetResidue + ""); 120 break; 121 } 122 123 return result; 124 } 125 126 //------------------------------------------------------------------------ 127 void setCountRange(Range<Integer> inValue) 128 { 129 mCountRange = inValue; 130 } 131 132 //------------------------------------------------------------------------ 133 boolean hasCountRange() 134 { 135 return mCountRange != null; 136 } 137 138 //------------------------------------------------------------------------ 139 Range<Integer> getCountRange() 140 { 141 return mCountRange; 142 } 143 144 145 //------------------------------------------------------------------------ 146 void setUseLazyMatchMode(boolean inValue) 147 { 148 mLazyMatchMode = inValue; 149 } 150 151 //------------------------------------------------------------------------ 152 boolean useLazyMatchMode() 153 { 154 return mLazyMatchMode; 155 } 156 157 158 //------------------------------------------------------------------------ 159 void setMismatchNotAllowed(boolean inValue) 160 { 161 mMismatchNotAllowed = inValue; 162 } 163 164 //------------------------------------------------------------------------ 165 boolean mismatchNotAllowed() 166 { 167 return mMismatchNotAllowed; 168 } 169 170}