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 2011-11-20 021 * 022 */ 023package org.biojava.nbio.ws.alignment.qblast; 024 025import org.biojava.nbio.ws.alignment.RemotePairwiseAlignmentOutputProperties; 026 027import java.util.HashMap; 028import java.util.HashSet; 029import java.util.Map; 030import java.util.Set; 031 032import static org.biojava.nbio.ws.alignment.qblast.BlastOutputParameterEnum.*; 033 034/** 035 * This class wraps a QBlast output parameter {@code Map} by adding several convenient parameter addition methods. Other 036 * QBlast URL API parameters should be added using {@link #setOutputOption(BlastOutputParameterEnum, String)} 037 * 038 * @author Sylvain Foisy, Diploide BioIT 039 * @author Gediminas Rimsa 040 */ 041public class NCBIQBlastOutputProperties implements RemotePairwiseAlignmentOutputProperties { 042 private static final long serialVersionUID = -9202060390925345163L; 043 044 private Map<BlastOutputParameterEnum, String> param = new HashMap<BlastOutputParameterEnum, String>(); 045 046 /** 047 * This constructor builds the parameters for the output of the GET command sent to the QBlast service with default 048 * values: 049 * 050 * <pre> 051 * FORMAT_TYPE = XML; 052 * ALIGNMENT_VIEW = Pairwise; 053 * DESCRIPTIONS = 100; 054 * ALIGNMENTS = 100; 055 * </pre> 056 */ 057 public NCBIQBlastOutputProperties() { 058 setOutputOption(FORMAT_TYPE, BlastOutputFormatEnum.XML.name()); 059 setOutputOption(ALIGNMENT_VIEW, BlastOutputAlignmentFormatEnum.Pairwise.name()); 060 setOutputOption(DESCRIPTIONS, "100"); 061 setOutputOption(ALIGNMENTS, "100"); 062 } 063 064 /** 065 * This method forwards to {@link #getOutputOption(BlastOutputParameterEnum)}. Consider using it instead. 066 */ 067 @Override 068 public String getOutputOption(String key) { 069 return getOutputOption(BlastOutputParameterEnum.valueOf(key)); 070 } 071 072 /** 073 * This method forwards to {@link #setOutputOption(BlastOutputParameterEnum, String)}. Consider using it instead. 074 */ 075 @Override 076 public void setOutputOption(String key, String val) { 077 setOutputOption(BlastOutputParameterEnum.valueOf(key), val); 078 } 079 080 /** 081 * Gets the value of specified parameter or {@code null} if it is not set 082 */ 083 public String getOutputOption(BlastOutputParameterEnum key) { 084 return param.get(key); 085 } 086 087 /** 088 * Sets the value of specified output parameter 089 */ 090 public void setOutputOption(BlastOutputParameterEnum key, String value) { 091 param.put(key, value); 092 } 093 094 /** 095 * Gets output parameters, which are currently set 096 */ 097 @Override 098 public Set<String> getOutputOptions() { 099 Set<String> result = new HashSet<String>(); 100 for (BlastOutputParameterEnum parameter : param.keySet()) { 101 result.add(parameter.name()); 102 } 103 return result; 104 } 105 106 /** 107 * Removes given parameter 108 */ 109 public void removeOutputOption(BlastOutputParameterEnum key) { 110 param.remove(key); 111 } 112 113 /** 114 * @return stream output format - a String with the value of key FORMAT_TYPE 115 */ 116 public String getOutputFormat() { 117 return getOutputOption(FORMAT_TYPE); 118 } 119 120 /** 121 * Sets the stream output format to get from the QBlast service 122 * <p/> 123 * If {@code HTML} format is selected, also adds the following parameters (which are removed if another output 124 * format is chosen): 125 * 126 * <pre> 127 * NOHEADER = true; 128 * SHOW_OVERVIEW = false; 129 * SHOW_LINKOUT = false; 130 * </pre> 131 * 132 * @param formatType : one of the output format types defined in enum 133 */ 134 public void setOutputFormat(BlastOutputFormatEnum formatType) { 135 setOutputOption(FORMAT_TYPE, formatType.name()); 136 if (BlastOutputFormatEnum.HTML.equals(formatType)) { 137 // add default parameters associated with HTML 138 setOutputOption(NOHEADER, "true"); 139 setOutputOption(SHOW_OVERVIEW, "false"); 140 setOutputOption(SHOW_LINKOUT, "false"); 141 } else { 142 // remove default parameters associated with HTML 143 removeOutputOption(NOHEADER); 144 removeOutputOption(SHOW_OVERVIEW); 145 removeOutputOption(SHOW_LINKOUT); 146 } 147 } 148 149 /** 150 * @return alignment output format - a String with the value of key ALIGNMENT_VIEW 151 */ 152 public String getAlignmentOutputFormat() { 153 return getOutputOption(ALIGNMENT_VIEW); 154 } 155 156 /** 157 * Sets the alignment output format to get from the QBlast service 158 * 159 * @param alignmentFormat : one of available alignment types 160 */ 161 public void setAlignmentOutputFormat(BlastOutputAlignmentFormatEnum alignmentFormat) { 162 setOutputOption(ALIGNMENT_VIEW, alignmentFormat.name()); 163 } 164 165 /** 166 * @return number of descriptions fetched - an int with the value of the key DESCRIPTIONS 167 */ 168 public int getDescriptionNumber() { 169 return Integer.parseInt(getOutputOption(DESCRIPTIONS)); 170 } 171 172 /** 173 * Sets the number of descriptions to fetch 174 * 175 * @param number : an int with the required number of descriptions to fetch 176 */ 177 public void setDescriptionNumber(int number) { 178 setOutputOption(DESCRIPTIONS, Integer.toString(number)); 179 } 180 181 /** 182 * @return number of alignments fetched - an int with the value of the key ALIGNMENTS 183 */ 184 public int getAlignmentNumber() { 185 return Integer.parseInt(getOutputOption(ALIGNMENTS)); 186 } 187 188 /** 189 * Set the number of alignments to fetch 190 * 191 * @param number : an int with the required number of alignments to fetch 192 */ 193 public void setAlignmentNumber(int number) { 194 setOutputOption(ALIGNMENTS, Integer.toString(number)); 195 } 196 197}