All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.bio.seq.alignment.blast.BLAST_DatabaseMgr Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.bio.seq.alignment.blast;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hfg.bio.seq.BioSequenceType;
import com.hfg.util.collection.CollectionUtil;
import com.hfg.xml.XMLDoc;
import com.hfg.xml.XMLException;
import com.hfg.xml.XMLName;
import com.hfg.xml.XMLTag;

//==============================================================================
/**
 A BLAST sequence database manager.
 
@author J. Alex Taylor, hairyfatguy.com
*/ //============================================================================== // com.hfg XML/HTML Coding Library // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //============================================================================== public class BLAST_DatabaseMgr { private File mFile; private Map> mGroupMap; protected static XMLName XML_NAME = new XMLName("BLAST_DatabaseMgr"); //########################################################################### // CONSTRUCTORS //########################################################################### //--------------------------------------------------------------------------- public BLAST_DatabaseMgr(File inFile) throws XMLException, IOException { mFile = inFile; XMLDoc doc = new XMLDoc(inFile); XMLTag rootNode = (XMLTag) doc.getRootNode(); rootNode.verifyTagName(XML_NAME); List groupTags = rootNode.getSubtagsByName(BLAST_DatabaseGroup.XML_NAME); if (CollectionUtil.hasValues(groupTags)) { for (XMLTag groupTag : groupTags) { addGroup(new BLAST_DatabaseGroup(groupTag)); } } } //########################################################################### // PUBLIC METHODS //########################################################################### //--------------------------------------------------------------------------- public File getFile() { return mFile; } //--------------------------------------------------------------------------- public BLAST_DatabaseMgr setFile(File inValue) { mFile = inValue; return this; } //--------------------------------------------------------------------------- public void persistToFile() { XMLDoc xmlDoc = toXMLDoc(); xmlDoc.toIndentedXML(mFile, 0, 2); } //--------------------------------------------------------------------------- public void addGroup(BLAST_DatabaseGroup inGroup) { if (inGroup != null) { if (null == mGroupMap) { mGroupMap = new HashMap<>(3); } List groupList = mGroupMap.get(inGroup.getSeqType()); if (null == groupList) { groupList = new ArrayList<>(25); mGroupMap.put(inGroup.getSeqType(), groupList); } groupList.add(inGroup); } } //--------------------------------------------------------------------------- public List getGroups(BioSequenceType inType) { return (mGroupMap != null ? mGroupMap.get(inType) : null); } //--------------------------------------------------------------------------- public XMLDoc toXMLDoc() { XMLTag tag = new XMLTag(XML_NAME); if (CollectionUtil.hasValues(mGroupMap)) { for (BioSequenceType bioSequenceType : mGroupMap.keySet()) { for (BLAST_DatabaseGroup group : mGroupMap.get(bioSequenceType)) { tag.addSubtag(group.toXMLTag()); } } } XMLDoc doc = new XMLDoc(); doc.setRootNode(tag); return doc; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy