001package com.hfg.bio.seq; 002 003import java.util.ArrayList; 004import java.util.Arrays; 005import java.util.Collection; 006import java.util.Date; 007import java.util.List; 008import java.util.Set; 009 010import com.hfg.bio.DbXref; 011import com.hfg.bio.seq.format.SeqCitation; 012import com.hfg.bio.seq.format.feature.FeatureKey; 013import com.hfg.bio.seq.format.feature.SeqFeature; 014import com.hfg.bio.seq.format.feature.qualifier.MolType; 015import com.hfg.bio.taxonomy.ncbi.NCBITaxon; 016import com.hfg.bio.taxonomy.SeqRepositoryDivision; 017import com.hfg.util.collection.OrderedSet; 018import com.hfg.xml.XMLNode; 019 020//------------------------------------------------------------------------------ 021/** 022 Exetended biological protein, DNA, or RNA sequence with support for features, 023 citations, db xrefs, etc. 024 <div> 025 @author J. Alex Taylor, hairyfatguy.com 026 </div> 027 */ 028//------------------------------------------------------------------------------ 029// com.hfg XML/HTML Coding Library 030// 031// This library is free software; you can redistribute it and/or 032// modify it under the terms of the GNU Lesser General Public 033// License as published by the Free Software Foundation; either 034// version 2.1 of the License, or (at your option) any later version. 035// 036// This library is distributed in the hope that it will be useful, 037// but WITHOUT ANY WARRANTY; without even the implied warranty of 038// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 039// Lesser General Public License for more details. 040// 041// You should have received a copy of the GNU Lesser General Public 042// License along with this library; if not, write to the Free Software 043// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 044// 045// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 046// jataylor@hairyfatguy.com 047//------------------------------------------------------------------------------ 048 049public abstract class BioSequencePlusImpl extends BioSequenceImpl implements BioSequencePlus 050{ 051 052 private SeqRepositoryDivision mSeqRepositoryDivision; 053 private MolType mMolType; 054 private SeqTopology mSeqTopology; 055 private List<SeqFeature> mFeatures; 056 private List<SeqCitation> mCitations; 057 private List<DbXref> mDbXRefs; 058 private Set<String> mKeywords; 059 private Date mRevisionDate; 060 private Clone mClone; 061 private NCBITaxon mNCBITaxon; 062 private List<Throwable> mParseExceptions; 063 064 //########################################################################## 065 // CONSTRUCTORS 066 //########################################################################## 067 068 //-------------------------------------------------------------------------- 069 public BioSequencePlusImpl() 070 { 071 072 } 073 074 //-------------------------------------------------------------------------- 075 public BioSequencePlusImpl(XMLNode inXML) 076 { 077 super(inXML); 078 079 // TODO: Add support for features, citations, etc. 080 } 081 082 //########################################################################## 083 // PUBLIC METHODS 084 //########################################################################## 085 086 //-------------------------------------------------------------------------- 087 public XMLNode toXMLNode() 088 { 089 XMLNode node = super.toXMLNode(); 090 091 // TODO: Add support for features, citations, etc. 092 093 return node; 094 } 095 096 //-------------------------------------------------------------------------- 097 @Override 098 public BioSequencePlusImpl clone() 099 { 100 BioSequencePlusImpl theClone = (BioSequencePlusImpl) super.clone(); 101 102 103 if (mFeatures != null) 104 { 105 // For right now this is a shallow clone of the features 106 theClone.mFeatures = new ArrayList<>(mFeatures); 107 } 108 109 if (mCitations != null) 110 { 111 // For right now this is a shallow clone of the citations 112 theClone.mCitations = new ArrayList<>(mCitations); 113 } 114 115 if (mDbXRefs != null) 116 { 117 // For right now this is a shallow clone of the dbxrefs 118 theClone.mDbXRefs = new ArrayList<>(mDbXRefs); 119 } 120 121 return theClone; 122 } 123 124 125 //-------------------------------------------------------------------------- 126 public BioSequenceImpl addFeature(SeqFeature inValue) 127 { 128 if (null == mFeatures) 129 { 130 mFeatures = new ArrayList<>(25); 131 } 132 133 mFeatures.add(inValue); 134 135 return this; 136 } 137 138 //-------------------------------------------------------------------------- 139 public List<SeqFeature> getFeatures() 140 { 141 return mFeatures; 142 } 143 144 //-------------------------------------------------------------------------- 145 public List<SeqFeature> getFeatures(FeatureKey inFeatureKey) 146 { 147 List<SeqFeature> requestedFeatures = new ArrayList<SeqFeature>(); 148 if (mFeatures != null) 149 { 150 for (SeqFeature feature : mFeatures) 151 { 152 if (feature.name().equals(inFeatureKey)) 153 { 154 requestedFeatures.add(feature); 155 } 156 } 157 } 158 159 return requestedFeatures; 160 } 161 162 //-------------------------------------------------------------------------- 163 public void clearFeatures() 164 { 165 if (mFeatures != null) 166 { 167 mFeatures.clear(); 168 } 169 } 170 171 172 //-------------------------------------------------------------------------- 173 public BioSequenceImpl setReferences(List<SeqCitation> inValues) 174 { 175 mCitations = inValues != null ? new ArrayList<>(inValues) : null; 176 177 return this; 178 } 179 180 //-------------------------------------------------------------------------- 181 public BioSequenceImpl addReference(SeqCitation inValue) 182 { 183 if (null == mCitations) 184 { 185 mCitations = new ArrayList<>(5); 186 } 187 188 mCitations.add(inValue); 189 190 return this; 191 } 192 193 //-------------------------------------------------------------------------- 194 public List<SeqCitation> getReferences() 195 { 196 return mCitations; 197 } 198 199 //-------------------------------------------------------------------------- 200 public void clearReferences() 201 { 202 if (mCitations != null) 203 { 204 mCitations.clear(); 205 } 206 } 207 208 209 //-------------------------------------------------------------------------- 210 public BioSequenceImpl addDbXref(DbXref inValue) 211 { 212 if (null == mDbXRefs) 213 { 214 mDbXRefs = new ArrayList<>(5); 215 } 216 217 mDbXRefs.add(inValue); 218 219 return this; 220 } 221 222 //-------------------------------------------------------------------------- 223 public List<DbXref> getDbXrefs() 224 { 225 return mDbXRefs; 226 } 227 228 //-------------------------------------------------------------------------- 229 public void clearDbXrefs() 230 { 231 if (mDbXRefs != null) 232 { 233 mDbXRefs.clear(); 234 } 235 } 236 237 238 //-------------------------------------------------------------------------- 239 public BioSequenceImpl addKeyword(String inValue) 240 { 241 if (null == mKeywords) 242 { 243 mKeywords = new OrderedSet<>(10); 244 } 245 246 mKeywords.add(inValue); 247 248 return this; 249 } 250 251 //-------------------------------------------------------------------------- 252 public BioSequenceImpl addKeywords(Collection<String> inValues) 253 { 254 if (inValues != null) 255 { 256 if (null == mKeywords) 257 { 258 mKeywords = new OrderedSet<>(10); 259 } 260 261 mKeywords.addAll(inValues); 262 } 263 264 return this; 265 } 266 267 //-------------------------------------------------------------------------- 268 public BioSequenceImpl addKeywords(String[] inValues) 269 { 270 if (inValues != null) 271 { 272 if (null == mKeywords) 273 { 274 mKeywords = new OrderedSet<>(10); 275 } 276 277 mKeywords.addAll(Arrays.asList(inValues)); 278 } 279 280 return this; 281 } 282 283 //-------------------------------------------------------------------------- 284 public Set<String> getKeywords() 285 { 286 return mKeywords; 287 } 288 289 //-------------------------------------------------------------------------- 290 public void clearKeywords() 291 { 292 if (mKeywords != null) 293 { 294 mKeywords.clear(); 295 } 296 } 297 298 299 //-------------------------------------------------------------------------- 300 public BioSequencePlusImpl setSeqRepositoryDivision(SeqRepositoryDivision inValue) 301 { 302 mSeqRepositoryDivision = inValue; 303 return this; 304 } 305 306 //-------------------------------------------------------------------------- 307 public SeqRepositoryDivision getSeqRepositoryDivision() 308 { 309 return mSeqRepositoryDivision; 310 } 311 312 313 //-------------------------------------------------------------------------- 314 public BioSequencePlusImpl setMolType(MolType inValue) 315 { 316 mMolType = inValue; 317 return this; 318 } 319 320 //-------------------------------------------------------------------------- 321 public MolType getMolType() 322 { 323 return mMolType; 324 } 325 326 327 //-------------------------------------------------------------------------- 328 public BioSequencePlusImpl setSeqTopology(SeqTopology inValue) 329 { 330 mSeqTopology = inValue; 331 return this; 332 } 333 334 //-------------------------------------------------------------------------- 335 public SeqTopology getSeqTopology() 336 { 337 return mSeqTopology; 338 } 339 340 341 //-------------------------------------------------------------------------- 342 public BioSequencePlusImpl setRevisionDate(Date inValue) 343 { 344 mRevisionDate = inValue; 345 return this; 346 } 347 348 //-------------------------------------------------------------------------- 349 public Date getRevisionDate() 350 { 351 return mRevisionDate; 352 } 353 354 355 //-------------------------------------------------------------------------- 356 public BioSequencePlusImpl setClone(Clone inValue) 357 { 358 mClone = inValue; 359 return this; 360 } 361 362 //-------------------------------------------------------------------------- 363 public Clone getClone() 364 { 365 return mClone; 366 } 367 368 369 //-------------------------------------------------------------------------- 370 public BioSequencePlusImpl setNCBITaxon(NCBITaxon inValue) 371 { 372 mNCBITaxon = inValue; 373 return this; 374 } 375 376 //-------------------------------------------------------------------------- 377 public NCBITaxon getNCBITaxon() 378 { 379 return mNCBITaxon; 380 } 381 382 383 384 //-------------------------------------------------------------------------- 385 public void addParseException(Throwable inException) 386 { 387 if (null == mParseExceptions) 388 { 389 mParseExceptions = new ArrayList<>(4); 390 } 391 392 mParseExceptions.add(inException); 393 } 394 395 //-------------------------------------------------------------------------- 396 public void clearParseExceptions() 397 { 398 mParseExceptions = null; 399 } 400 401 //-------------------------------------------------------------------------- 402 public List<Throwable> getParseExceptions() 403 { 404 return mParseExceptions; 405 } 406 407}