001package com.hfg.bio.seq.alignment.blast; 002 003 004import java.util.ArrayList; 005import java.util.List; 006 007import com.hfg.bio.seq.BioSequenceType; 008import com.hfg.util.StringUtil; 009import com.hfg.util.collection.CollectionUtil; 010import com.hfg.xml.XMLName; 011import com.hfg.xml.XMLTag; 012 013//============================================================================== 014/** 015 Container for a group of BLAST sequence databases. 016 <div> 017 @author J. Alex Taylor, hairyfatguy.com 018 </div> 019 */ 020//============================================================================== 021// com.hfg XML/HTML Coding Library 022// 023// This library is free software; you can redistribute it and/or 024// modify it under the terms of the GNU Lesser General Public 025// License as published by the Free Software Foundation; either 026// version 2.1 of the License, or (at your option) any later version. 027// 028// This library is distributed in the hope that it will be useful, 029// but WITHOUT ANY WARRANTY; without even the implied warranty of 030// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 031// Lesser General Public License for more details. 032// 033// You should have received a copy of the GNU Lesser General Public 034// License along with this library; if not, write to the Free Software 035// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 036// 037// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 038// jataylor@hairyfatguy.com 039//============================================================================== 040 041public class BLAST_DatabaseGroup 042{ 043 044 private String mName; 045 private BioSequenceType mSeqType; 046 private List<BLAST_Database> mDatabases; 047 048 protected static XMLName XML_NAME = new XMLName("BLAST_DatabaseGroup"); 049 private static XMLName XML_NAME_ATT = new XMLName("name"); 050 private static XMLName XML_SEQ_TYPE_ATT = new XMLName("seqType"); 051 052 053 054 //########################################################################### 055 // PUBLIC METHODS 056 //########################################################################### 057 058 //--------------------------------------------------------------------------- 059 public BLAST_DatabaseGroup(String inName, BioSequenceType inType) 060 { 061 mName = inName; 062 mSeqType = inType; 063 } 064 065 //--------------------------------------------------------------------------- 066 public BLAST_DatabaseGroup(XMLTag inXMLTag) 067 { 068 inXMLTag.verifyTagName(XML_NAME); 069 mName = inXMLTag.getAttributeValue(XML_NAME_ATT); 070 071 String bioSequenceTypeString = inXMLTag.getAttributeValue(XML_SEQ_TYPE_ATT); 072 if (! StringUtil.isSet(bioSequenceTypeString)) 073 { 074 throw new RuntimeException("No " + StringUtil.singleQuote(XML_SEQ_TYPE_ATT) + " specified for group " + StringUtil.singleQuote(mName) + "!"); 075 } 076 077 mSeqType = BioSequenceType.valueOf(bioSequenceTypeString); 078 079 List<XMLTag> dbTags = inXMLTag.getSubtagsByName(BLAST_Database.XML_NAME); 080 if (CollectionUtil.hasValues(dbTags)) 081 { 082 for (XMLTag dbTag : dbTags) 083 { 084 addDatabase(new BLAST_Database(dbTag)); 085 } 086 } 087 } 088 089 090 //########################################################################### 091 // PUBLIC METHODS 092 //########################################################################### 093 094 //--------------------------------------------------------------------------- 095 public XMLTag toXMLTag() 096 { 097 XMLTag tag = new XMLTag(XML_NAME); 098 tag.setAttribute(XML_NAME_ATT, name()); 099 tag.setAttribute(XML_SEQ_TYPE_ATT, getSeqType()); 100 101 if (CollectionUtil.hasValues(getDatabases())) 102 { 103 for (BLAST_Database db : getDatabases()) 104 { 105 tag.addSubtag(db.toXMLTag()); 106 } 107 } 108 109 return tag; 110 } 111 112 //--------------------------------------------------------------------------- 113 @Override 114 public String toString() 115 { 116 return name(); 117 } 118 119 //--------------------------------------------------------------------------- 120 public String name() 121 { 122 return mName; 123 } 124 125 //--------------------------------------------------------------------------- 126 public BioSequenceType getSeqType() 127 { 128 return mSeqType; 129 } 130 131 //--------------------------------------------------------------------------- 132 public void addDatabase(BLAST_Database inValue) 133 { 134 if (null == mDatabases) 135 { 136 mDatabases = new ArrayList<>(10); 137 } 138 139 mDatabases.add(inValue); 140 } 141 142 //--------------------------------------------------------------------------- 143 public List<BLAST_Database> getDatabases() 144 { 145 return mDatabases; 146 } 147 148}