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 Aug 2, 2010 021 * Author: Jianjiong Gao 022 * 023 */ 024 025package org.biojava.nbio.protmod.structure; 026 027import org.biojava.nbio.structure.ResidueNumber; 028 029/** 030 * Information of a group (residue or ligand) involved in a modification. 031 * @author Jianjiong Gao 032 * @since 3.0 033 */ 034public class StructureGroup 035implements Comparable<StructureGroup> { 036 037 private ResidueNumber resNum; 038 private String pdbName; 039 private Boolean isAminoAcid; 040 041 public StructureGroup(){ 042 resNum = new ResidueNumber(); 043 } 044 045 public StructureGroup( ResidueNumber resNum, 046 String pdbName, boolean isAminoAcid) { 047 this.resNum = resNum; 048 this.pdbName = pdbName; 049 this.isAminoAcid = isAminoAcid; 050 } 051 052// public StructureGroup( ResidueNumber resNum, 053// String pdbName) { 054// this(resNum, pdbName, true); 055// } 056 057 public ResidueNumber getPDBResidueNumber() { 058 return resNum; 059 } 060 061 public void setPDBResidueNumber(ResidueNumber resNum) { 062 this.resNum = resNum; 063 } 064 public String getChainId() { 065 return resNum.getChainName(); 066 } 067 068 public void setChainId(String chainId){ 069 if ( resNum == null) 070 resNum = new ResidueNumber(); 071 resNum.setChainName(chainId); 072 } 073 074 public int getResidueNumber() { 075 return resNum.getSeqNum(); 076 } 077 078 public void setResidueNumber(int seqNr){ 079 if ( resNum == null) 080 resNum = new ResidueNumber(); 081 resNum.setSeqNum(seqNr); 082 } 083 084 public Character getInsCode() { 085 return resNum.getInsCode(); 086 } 087 088 public void setInsCode(Character c){ 089 if ( resNum == null) 090 resNum = new ResidueNumber(); 091 resNum.setInsCode(c); 092 } 093 094 public String getPDBName() { 095 return pdbName; 096 } 097 098 public void setPDBName(String pdbName){ 099 this.pdbName = pdbName; 100 101 } 102 103 public void setIsAminoAcid(boolean isAminoAcid) { 104 this.isAminoAcid = isAminoAcid; 105 } 106 107 public boolean isAminoAcid() { 108 return isAminoAcid; 109 } 110 111 @Override 112 public boolean equals(Object obj) { 113 if (obj == this) 114 return true; 115 116 if (!(obj instanceof StructureGroup)) 117 return false; 118 119 StructureGroup aGroup = (StructureGroup) obj; 120 if (!resNum.equals(aGroup.resNum)) 121 return false; 122 123 return true; 124 } 125 126 @Override 127 public int hashCode() { 128 int result = 17; 129 if ( resNum != null) 130 result = result * 31 + resNum.hashCode(); 131 return result; 132 } 133 134 @Override 135 public String toString() { 136 StringBuilder sb = new StringBuilder(); 137 sb.append(pdbName); 138 sb.append('\t'); 139 sb.append(resNum.getChainName()); 140 sb.append('\t'); 141 sb.append(resNum.getSeqNum()); 142 if (resNum.getInsCode() != null) 143 sb.append(resNum.getInsCode()); 144 sb.append('\t'); 145 return sb.toString(); 146 } 147 148 @Override 149 public int compareTo(StructureGroup aGroup) { 150 int result = getChainId().compareTo(aGroup.getChainId()); 151 if (result != 0) 152 return result; 153 result = getResidueNumber()-aGroup.getResidueNumber(); 154 if (result != 0) 155 return result; 156 if (getInsCode()==null) { 157 if (aGroup.getInsCode()!=null) 158 return -1; 159 } else { 160 if (aGroup.getInsCode()==null) 161 return 1; 162 else { 163 result = getInsCode().compareTo(aGroup.getInsCode()); 164 if (result != 0) 165 return result; 166 } 167 } 168 return 0; 169 } 170}