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 */
021
022package org.biojavax.bio.alignment.blast;
023
024import java.util.HashMap;
025import java.util.Set;
026
027import org.biojava.bio.BioException;
028import org.biojavax.bio.alignment.RemotePairwiseAlignmentOutputProperties;
029
030/**
031 * The actual implementation of the RemotePairwiseAlignmentOutputProperties 
032 * interface for the QBlast service.
033 * 
034 * The constructor for this class builds an object with default format values. Any modification will 
035 * either use the generic method setOutputOption method or use the wrapper methods that are actually 
036 * build around the generic method.
037
038 * @author Sylvain Foisy, Diploide BioIT
039 * @since 1.8
040 *
041 */
042public class RemoteQBlastOutputProperties implements
043                RemotePairwiseAlignmentOutputProperties {
044
045        private static final long serialVersionUID = 1L;
046        private HashMap<String, String> out = new HashMap<String, String>();
047        private String outFormat = "FORMAT_TYPE=Text";
048        private String alignFormat = "ALIGNMENT_VIEW=Pairwise";
049
050        private int descNumbers = 100;
051        private int alignNumbers = 100;
052
053        /**
054         * This constructor build the parameters for the default output of the GET command sent to the QBlast service.
055         * Here are the default values:
056         * 
057         * FORMAT_TYPE = Text;
058         * ALIGNMENT_VIEW = Pairwise
059         * DESCRIPTIONS = 100;
060         * ALIGNMENTS = 100;
061         * 
062         */
063        public RemoteQBlastOutputProperties() {
064                this.out.put("FORMAT_TYPE", outFormat);
065                this.out.put("ALIGNMENT_VIEW", alignFormat);
066                this.out.put("DESCRIPTIONS", "DESCRIPTIONS=" + descNumbers);
067                this.out.put("ALIGNMENTS", "ALIGNMENTS=" + alignNumbers);
068        }
069
070        /**
071         * Simply returns stream output format for the actual RemoteQBlastOutputProperties object
072         * 
073         * @return a String with the value of key FORMAT_TYPE.
074         */
075        public String getOutputFormat() {
076                return this.out.get("FORMAT_TYPE");
077        }
078
079        /**
080         * This method is use to set the stream output format to get from the QBlast service
081         * 
082         * @param rf :an enum from RemoteQBlastOutputFormat
083         * @throws BioException if the enum is neither of RemoteQBlastOutputFormat.TEXT/XML/HTML
084         */
085        public void setOutputFormat(RemoteQBlastOutputFormat rf)
086                        throws BioException {
087                switch (rf) {
088                case TEXT:
089                        this.outFormat = "FORMAT_TYPE=Text";
090                        this.out.put("FORMAT_TYPE", outFormat);
091                        break;
092                case XML:
093                        this.outFormat = "FORMAT_TYPE=XML";
094                        this.out.put("FORMAT_TYPE", outFormat);
095                        break;
096                case HTML:
097                        this.outFormat = "FORMAT_TYPE=HTML";
098                        this.out.put("FORMAT_TYPE", outFormat);
099                        break;
100                default:
101                        throw new BioException(
102                                        "Unacceptable selection of format type. Only values text / XML / HTML accepted");
103                }
104        }
105
106        /**
107         * Method that returns the alignment output format for this actual RemoteQBlastOutputProperties object
108         * 
109         * @return a String with the value of key ALIGNMENT_VIEW
110         */
111        public String getAlignmentOutputFormat() {
112                return this.out.get("ALIGNMENT_VIEW");
113        }
114
115        /**
116         * This method is use to set the alignment output format to get from the QBlast service
117         * 
118         * @param rf :an enum from RemoteQBlastOutputFormat
119         * @throws BioException if the enum is neither of RemoteQBlastOutputFormat.PAIRWISE/QUERY_ANCHORED/QUERY_ANCHORED_NO_IDENTITIES/FLAT_QUERY_ANCHORED
120         *         FLAT_QUERY_ANCHORED_NO_IDENTITIES/TABULAR
121         */
122        public void setAlignmentOutputFormat(RemoteQBlastOutputFormat rf)
123                        throws BioException {
124                switch (rf) {
125                case PAIRWISE:
126                        this.alignFormat = "ALIGNMENT_VIEW=Pairwise";
127                        this.out.put("ALIGNMENT_VIEW", alignFormat);
128                        break;
129                case QUERY_ANCHORED:
130                        this.alignFormat = "ALIGNMENT_VIEW=QueryAnchored";
131                        this.out.put("ALIGNMENT_VIEW", alignFormat);
132                        break;
133                case QUERY_ANCHORED_NO_IDENTITIES:
134                        this.alignFormat = "ALIGNMENT_VIEW=QueryAnchoredNoIdentities";
135                        this.out.put("ALIGNMENT_VIEW", alignFormat);
136                        break;
137                case FLAT_QUERY_ANCHORED:
138                        this.alignFormat = "ALIGNMENT_VIEW=FlatQueryAnchored";
139                        this.out.put("ALIGNMENT_VIEW", alignFormat);
140                        break;
141                case FLAT_QUERY_ANCHORED_NO_IDENTITIES:
142                        this.alignFormat = "ALIGNMENT_VIEW=FlatQueryAnchoredNoIdentities";
143                        this.out.put("ALIGNMENT_VIEW", alignFormat);
144                        break;
145                case TABULAR:
146                        this.alignFormat = "ALIGNMENT_VIEW=Tabular";
147                        this.out.put("ALIGNMENT_VIEW", alignFormat);
148                        break;
149                default:
150                        throw new BioException(
151                                        "Unacceptable selection of alignment type. Only values Pairwise / QueryAnchored / QueryAnchoredNoIdentities / FlatQueryAnchored / FlatQueryAnchoredNoIdentities / Tabular accepted");
152                }
153        }
154
155        /**
156         * A method that simply returns the number of descriptions fetched with this RemoteQBlastOutputProperties object.
157         * 
158         * @return an int with the value of the key DESCRIPTIONS
159         */
160        public int getDescriptionNumber() {
161                String val = this.out.get("DESCRIPTIONS");
162                String vals[] = val.split("=");
163                int i = Integer.parseInt(vals[1]);
164
165                return i;
166        }
167
168        /**
169         * A method to set the number of descriptions to fetch to the GET command.
170         * 
171         * @param i :an int with the required number of descriptions to fetch.
172         */
173        public void setDescriptionNumber(int i) {
174                this.descNumbers = i;
175                this.out.put("DESCRIPTIONS", "DESCRIPTIONS=" + descNumbers);
176        }
177
178        /**
179         * A method that simply returns the number of alignments fetched with this RemoteQBlastOutputProperties object.
180         * 
181         * @return an int with the value of the key ALIGNMENTS.
182         */     
183        public int getAlignmentNumber() {
184                String val = this.out.get("ALIGNMENTS");
185                String vals[] = val.split("=");
186                int i = Integer.parseInt(vals[1]);
187
188                return i;
189        }
190
191        /**
192         * A method to set the number of alignments to fetch to the GET command.
193         * 
194         * @param i :an int with the required number of alignments to fetch.
195         */
196
197        public void setAlignmentNumber(int i) {
198                this.alignNumbers = i;
199                this.out.put("ALIGNMENTS", "ALIGNMENTS=" + alignNumbers);
200        }
201
202        /**
203         * Method that returns any value associated to any key for this RemoteQBlastOutputProperties object.
204         * 
205         */
206        public String getOutputOption(String o) throws BioException{
207                if(out.containsKey(o)){
208                        return this.out.get(o);}
209                else{
210                        throw new BioException("The key named "+o+" is not set in this RemoteQBlastOutputProperties object");
211                }
212        }
213
214        public void setOutputOption(String o, String v) {
215                this.out.put(o, v);
216        }
217
218        public Set<String> getOutputOptions() {
219                return out.keySet();
220        }
221
222}