in progress...
[jalview.git] / forester / java / src / org / forester / phylogeny / data / Sequence.java
index 525bc1b..3561edc 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() {
@@ -288,8 +315,8 @@ public class Sequence implements PhylogenyData, MultipleUris, Comparable<Sequenc
         return result;
     }
 
-    public boolean hasSequenceRelations() {
-        return _seq_relations.size() > 0;
+    public boolean isHasSequenceRelations() {
+        return _seq_relations != null && _seq_relations.size() > 0;
     }
 
     public void init() {