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 */
021package org.biojava.bio.seq.io.agave;
022import java.util.Iterator;
023import java.util.List;
024
025import org.biojava.bio.Annotation;
026
027/**
028 * Dumping the data from biojava with source of agave into agave format
029 * @author Hanning Ni     Doubletwist Inc
030 *
031 */
032public class Agave2AgaveAnnotFilter extends SimpleAnnotFilter{
033
034  public static final AGAVEAnnotFilterFactory AGAVE_AGAVE_ANNOT_FILTER_FACTORY
035    = new AGAVEAnnotFilterFactory() {
036    public AGAVEAnnotFilter getInstance() {
037      return new Agave2AgaveAnnotFilter();
038    }
039  };
040
041  Agave2AgaveAnnotFilter() {
042  }
043
044    /**     */
045   public String getAccession(Annotation annot)
046   {
047       if( annot == null ) return (String)null ;
048       return (String) UtilHelper.getProperty(annot, "accession");
049   }
050
051   /**       */
052    public String getKeyword(Annotation annot)
053    {
054        if( annot == null ) return (String)null ;
055        return (String) UtilHelper.getProperty(annot,"keyword");
056    }
057
058    /**      */
059    public String getOrganism(Annotation annot)
060    {
061        if( annot == null ) return (String)null ;
062        return (String) UtilHelper.getProperty(annot,"organism_name");
063    }
064
065    public String getElementId(Annotation annot)
066    {
067        if( annot == null ) return (String)null ;
068         return (String) UtilHelper.getProperty(annot,"element_id");
069    }
070
071    public String getLabel(Annotation annot)
072    {
073        if( annot == null ) return (String)null ;
074         return (String) UtilHelper.getProperty(annot,"label");
075    }
076
077    /**      */
078    public String getDescription(Annotation annot)
079    {
080        if( annot == null ) return (String)null ;
081         return (String) UtilHelper.getProperty(annot,"description");
082    }
083
084    /**        */
085    public String getNote(Annotation annot)
086    {
087        if( annot == null ) return (String)null ;
088         return (String) UtilHelper.getProperty(annot,"note");
089    }
090
091    /**         */
092     public String getVersion(Annotation annot)
093     {
094        if( annot == null ) return (String)null ;
095         return (String) UtilHelper.getProperty(annot,"version");
096     }
097
098     /**        */
099     public String getOS(Annotation annot)
100     {
101         if( annot == null ) return (String)null ;
102         return (String) UtilHelper.getProperty(annot,"organism_name");
103     }
104
105     /**        */
106     public String getMolType(Annotation annot)
107     {
108          if( annot == null ) return (String)null ;
109           return (String) UtilHelper.getProperty(annot,"molecule_type");
110     }
111
112     public String getTaxonId(Annotation annot)
113     {
114         if( annot == null ) return (String)null ;
115          return (String) UtilHelper.getProperty(annot,"taxon_id");
116     }
117
118     public String getCloneId(Annotation annot)
119     {
120         if( annot == null ) return (String)null ;
121          return (String) UtilHelper.getProperty(annot,"clone_id");
122     }
123
124     public String getCloneLibrary(Annotation annot)
125     {
126         if( annot == null ) return (String)null ;
127          return (String) UtilHelper.getProperty(annot,"clone_library");
128     }
129
130     public String getChromosome(Annotation annot)
131     {
132         if( annot == null ) return (String)null ;
133          return (String) UtilHelper.getProperty(annot,"chromosome");
134     }
135
136     public String getMapPosition(Annotation annot)
137     {
138         if( annot == null ) return (String)null ;
139          return (String) UtilHelper.getProperty(annot,"map_position");
140     }
141
142     public String getEcNumber(Annotation annot)
143     {
144         if( annot == null ) return (String)null ;
145          return (String) UtilHelper.getProperty(annot,"ec_number");
146     }
147
148     public String getCreateDate(Annotation annot)
149     {
150         if( annot == null ) return (String)null ;
151          return (String) UtilHelper.getProperty(annot,"create_date");
152     }
153
154     public String getUpdateDate(Annotation annot)
155     {
156         if( annot == null ) return (String)null ;
157          return (String) UtilHelper.getProperty(annot,"update_date");
158     }
159
160     public AGAVEXrefs[] getXrefs(Annotation annot)
161    {
162        if( annot == null ) return (AGAVEXrefs[])null ;
163        Object ob = UtilHelper.getProperty(annot,"xrefs") ;
164        if( ob != null && ob instanceof List)
165        {
166            AGAVEXrefs[] set = new AGAVEXrefs[1];
167            return (AGAVEXrefs[])((List)ob).toArray( set ) ;
168        }
169        return (AGAVEXrefs[]) null ;
170    }
171
172    public AGAVERelatedAnnot[]  getRelatedAnnot(Annotation annot)
173    {
174        if( annot == null ) return (AGAVERelatedAnnot[])null ;
175        Object ob = UtilHelper.getProperty(annot,"related_annot");
176        if( ob != null && ob instanceof List)
177        {
178            AGAVERelatedAnnot[] set = new AGAVERelatedAnnot[1];
179            return (AGAVERelatedAnnot[])((List)ob).toArray( set ) ;
180        }
181        return (AGAVERelatedAnnot[]) null ;
182    }
183
184    public String getGroupOrder(Annotation annot)
185    {
186         if( annot == null ) return (String)null ;
187         return (String) UtilHelper.getProperty(annot,"group_order");
188    }
189
190    public String getFeatureType(Annotation annot)
191    {
192         if( annot == null ) return (String)null ;
193         return (String) UtilHelper.getProperty(annot,"feature_type");
194    }
195    public String getResultType(Annotation annot)
196    {
197         if( annot == null ) return (String)null ;
198         return (String) UtilHelper.getProperty(annot,"result_type");
199    }
200
201    public String getConfidence(Annotation annot)
202    {
203         if( annot == null ) return (String)null ;
204         return (String) UtilHelper.getProperty(annot,"confidence");
205    }
206
207    public String getMatchAlign(Annotation annot)
208    {
209         if( annot == null ) return (String)null ;
210         return (String) UtilHelper.getProperty(annot,"match_align");
211    }
212
213    public AGAVEMatchRegion getMatchRegion(Annotation annot)
214    {
215        if( annot == null ) return (AGAVEMatchRegion)null ;
216        return (AGAVEMatchRegion) UtilHelper.getProperty(annot,"match_region");
217    }
218
219    public AGAVEQueryRegion getQueryRegion(Annotation annot)
220    {
221        if( annot == null ) return (AGAVEQueryRegion)null ;
222       return (AGAVEQueryRegion) UtilHelper.getProperty(annot,"query_region") ;
223    }
224
225    public String getAlignUnits(Annotation annot)
226    {
227        if( annot == null ) return (String)null ;
228        return (String) UtilHelper.getProperty(annot,"align_units");
229    }
230
231    public String getMatchDesc(Annotation annot)
232    {
233        if( annot == null ) return (String)null ;
234        return (String) UtilHelper.getProperty(annot,"match_desc");
235    }
236
237    public String[] getElementIds(Annotation annot)
238    {
239        if( annot == null ) return (String[])null ;
240        Object ob = UtilHelper.getProperty(annot,"element_ids");
241        if( ob != null && ob instanceof List)
242        {
243            String[] set = new String[1];
244            return (String[])((List)ob).toArray( set ) ;
245        }
246        return (String[]) null ;
247    }
248
249    public AGAVEMapLocation[]  getMapLocation(Annotation annot)
250    {
251        if( annot == null ) return (AGAVEMapLocation[])null ;
252        Object ob = UtilHelper.getProperty(annot,"map_location");
253        if( ob != null && ob instanceof List)
254        {
255            AGAVEMapLocation[] set = new AGAVEMapLocation[1];
256            return (AGAVEMapLocation[])((List)ob).toArray( set ) ;
257        }
258        return (AGAVEMapLocation[]) null ;
259    }
260
261    public AGAVEDbId[] getAltIds(Annotation annot)
262    {
263        if( annot == null ) return (AGAVEDbId[])null ;
264        Object ob = UtilHelper.getProperty(annot,"alt_ids");
265        if( ob != null && ob instanceof List)
266        {
267            AGAVEDbId[] set = new AGAVEDbId[1];
268            return (AGAVEDbId[])((List)ob).toArray( set ) ;
269        }
270        return (AGAVEDbId[]) null ;
271    }
272
273
274    public String getClassifySystem(Annotation annot)
275    {
276        return (String) UtilHelper.getProperty(annot,"system");
277    }
278
279    public String getClassifyId(Annotation annot)
280    {
281         return (String) UtilHelper.getProperty(annot,"id");
282    }
283
284    public String getClassifyType(Annotation annot)
285    {
286         return (String) UtilHelper.getProperty(annot,"type");
287    }
288
289    public AGAVEDbId getDbId(Annotation annot)
290    {
291        return (AGAVEDbId) UtilHelper.getProperty(annot,"db_id");
292    }
293
294    public AGAVEIdAlias[] getIdAlias(Annotation annot)
295    {
296        Object ob = UtilHelper.getProperty(annot,"id_alias");
297        if( ob != null && ob instanceof List)
298        {
299            AGAVEIdAlias[] set = new AGAVEIdAlias[1];
300            return (AGAVEIdAlias[])((List)ob).toArray( set ) ;
301        }
302        return (AGAVEIdAlias[]) null ;
303    }
304
305    public String[] getExonIds(Annotation annot)
306    {
307        Object ob = UtilHelper.getProperty(annot,"exons");
308        if( ob != null && ob instanceof List)
309        {
310            String[] set = new String[1];
311            return (String[])((List)ob).toArray( set ) ;
312        }
313        return (String[]) null ;
314    }
315
316    public String getChromNum(Annotation annot)
317    {
318         return (String) UtilHelper.getProperty(annot,"chromosome_number");
319    }
320
321    /**        */
322    public AGAVEProperty[] getProperty(Annotation annot, String type)
323    {
324        for (Iterator i = annot.keys().iterator(); i.hasNext();)
325        {
326            String key = (String) i.next();
327            Object ob = UtilHelper.getProperty(annot,key)  ;
328            if( ob instanceof List && ((List)ob).get(0) instanceof AGAVEProperty)
329            {
330                AGAVEProperty[] tmp = new AGAVEProperty[ 1 ] ;
331                return (AGAVEProperty[])((List)ob).toArray( tmp ) ;
332            }
333         }
334         return (AGAVEProperty[]) null ;
335     }
336}