(no commit message)
[jalview.git] / forester / java / src / org / forester / phylogeny / data / Sequence.java
index afc342b..fd366c6 100644 (file)
@@ -37,6 +37,8 @@ import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
 import org.forester.io.writers.PhylogenyWriter;
+import org.forester.sequence.MolecularSequence;
+import org.forester.sequence.MolecularSequence.TYPE;
 import org.forester.util.ForesterUtil;
 
 public class Sequence implements PhylogenyData, MultipleUris, Comparable<Sequence> {
@@ -60,6 +62,31 @@ public class Sequence implements PhylogenyData, MultipleUris, Comparable<Sequenc
         init();
     }
 
+    public Sequence( final MolecularSequence mol_seq ) {
+        init();
+        setMolecularSequence( mol_seq.getMolecularSequenceAsString() );
+        setName( mol_seq.getIdentifier() );
+        String type;
+        if ( mol_seq.getType() == TYPE.AA ) {
+            type = "protein";
+        }
+        else if ( mol_seq.getType() == TYPE.DNA ) {
+            type = "dna";
+        }
+        else if ( mol_seq.getType() == TYPE.RNA ) {
+            type = "rna";
+        }
+        else {
+            throw new IllegalArgumentException( "unknown sequence type " + mol_seq.getType() );
+        }
+        try {
+            setType( type );
+        }
+        catch ( final PhyloXmlDataFormatException e ) {
+            throw new IllegalArgumentException( "don't know how to handle type " + mol_seq.getType() );
+        }
+    }
+
     public void addAnnotation( final Annotation annotation ) {
         getAnnotations().add( annotation );
     }
@@ -131,7 +158,7 @@ public class Sequence implements PhylogenyData, MultipleUris, Comparable<Sequenc
 
     /**
      * Not a deep copy.
-     * 
+     *
      */
     @Override
     public PhylogenyData copy() {
@@ -455,9 +482,6 @@ public class Sequence implements PhylogenyData, MultipleUris, Comparable<Sequenc
                 annotation.toPhyloXML( writer, level, my_ind );
             }
         }
-        if ( getDomainArchitecture() != null ) {
-            getDomainArchitecture().toPhyloXML( writer, level, my_ind );
-        }
         if ( ( getCrossReferences() != null ) && !getCrossReferences().isEmpty() ) {
             writer.write( ForesterUtil.LINE_SEPARATOR );
             writer.write( my_ind );
@@ -469,6 +493,9 @@ public class Sequence implements PhylogenyData, MultipleUris, Comparable<Sequenc
             writer.write( my_ind );
             PhylogenyDataUtil.appendClose( writer, PhyloXmlMapping.SEQUENCE_X_REFS );
         }
+        if ( getDomainArchitecture() != null ) {
+            getDomainArchitecture().toPhyloXML( writer, level, my_ind );
+        }
         writer.write( ForesterUtil.LINE_SEPARATOR );
         writer.write( indentation );
         PhylogenyDataUtil.appendClose( writer, PhyloXmlMapping.SEQUENCE );