2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.io.parsers.phyloxml.data;
28 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
29 import org.forester.io.parsers.phyloxml.XmlElement;
30 import org.forester.io.parsers.util.PhylogenyParserException;
31 import org.forester.phylogeny.data.Accession;
32 import org.forester.phylogeny.data.Annotation;
33 import org.forester.phylogeny.data.DomainArchitecture;
34 import org.forester.phylogeny.data.Sequence;
35 import org.forester.phylogeny.data.Uri;
37 public class SequenceParser implements PhylogenyDataPhyloXmlParser {
39 private static final PhylogenyDataPhyloXmlParser _instance;
42 _instance = new SequenceParser();
44 catch ( final Throwable e ) {
45 throw new RuntimeException( e.getMessage() );
49 private SequenceParser() {
53 public Sequence parse( final XmlElement element ) throws PhylogenyParserException {
54 final Sequence sequence = new Sequence();
55 if ( element.isHasAttribute( PhyloXmlMapping.SEQUENCE_TYPE ) ) {
56 sequence.setType( element.getAttribute( PhyloXmlMapping.SEQUENCE_TYPE ) );
58 if ( element.isHasAttribute( PhyloXmlMapping.SEQUENCE_SOURCE_ID ) ) {
59 sequence.setSourceId( element.getAttribute( PhyloXmlMapping.SEQUENCE_SOURCE_ID ) );
61 for( int i = 0; i < element.getNumberOfChildElements(); ++i ) {
62 final XmlElement child_element = element.getChildElement( i );
63 if ( child_element.getQualifiedName().equals( PhyloXmlMapping.SEQUENCE_LOCATION ) ) {
64 sequence.setLocation( child_element.getValueAsString() );
66 else if ( child_element.getQualifiedName().equals( PhyloXmlMapping.SEQUENCE_NAME ) ) {
67 sequence.setName( child_element.getValueAsString() );
69 else if ( child_element.getQualifiedName().equals( PhyloXmlMapping.SEQUENCE_MOL_SEQ ) ) {
70 if ( child_element.isHasAttribute( PhyloXmlMapping.SEQUENCE_MOL_SEQ_ALIGNED_ATTR ) ) {
71 sequence.setMolecularSequenceAligned( Boolean.parseBoolean( child_element
72 .getAttribute( PhyloXmlMapping.SEQUENCE_MOL_SEQ_ALIGNED_ATTR ) ) );
74 sequence.setMolecularSequence( child_element.getValueAsString() );
76 else if ( child_element.getQualifiedName().equals( PhyloXmlMapping.ACCESSION ) ) {
77 sequence.setAccession( ( Accession ) AccessionParser.getInstance().parse( child_element ) );
79 else if ( child_element.getQualifiedName().equals( PhyloXmlMapping.SEQUENCE_SYMBOL ) ) {
80 sequence.setSymbol( child_element.getValueAsString() );
82 else if ( child_element.getQualifiedName().equals( PhyloXmlMapping.ANNOTATION ) ) {
83 sequence.addAnnotation( ( Annotation ) AnnotationParser.getInstance().parse( child_element ) );
85 else if ( child_element.getQualifiedName().equals( PhyloXmlMapping.SEQUENCE_DOMAIN_ARCHITECURE ) ) {
86 sequence.setDomainArchitecture( ( DomainArchitecture ) DomainArchitectureParser.getInstance()
87 .parse( child_element ) );
89 else if ( child_element.getQualifiedName().equals( PhyloXmlMapping.URI ) ) {
90 sequence.addUri( ( Uri ) UriParser.getInstance().parse( child_element ) );
96 public static PhylogenyDataPhyloXmlParser getInstance() {