File Parsing returns Alignments, not Sequence[]
authoramwaterhouse <Andrew Waterhouse>
Thu, 18 Jan 2007 16:21:03 +0000 (16:21 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 18 Jan 2007 16:21:03 +0000 (16:21 +0000)
13 files changed:
src/jalview/appletgui/CutAndPasteTransfer.java
src/jalview/bin/JalviewLite.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/CutAndPasteTransfer.java
src/jalview/gui/Desktop.java
src/jalview/gui/SequenceFetcher.java
src/jalview/io/AlignFile.java
src/jalview/io/AppletFormatAdapter.java
src/jalview/io/FastaFile.java
src/jalview/io/FileLoader.java
src/jalview/io/FormatAdapter.java
src/jalview/jbgui/GFinder.java
src/jalview/ws/JPredThread.java

index 86f55b8..bbbefa1 100755 (executable)
@@ -124,18 +124,18 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, MouseL
     }\r
     else if(alignFrame!=null)\r
     {\r
-      SequenceI[] sequences = null;\r
+      Alignment al = null;\r
 \r
       String format = new IdentifyFile().Identify(text, AppletFormatAdapter.PASTE);\r
       try{\r
-        sequences = new AppletFormatAdapter().readFile(text, AppletFormatAdapter.PASTE, format);\r
+        al = new AppletFormatAdapter().readFile(text, AppletFormatAdapter.PASTE, format);\r
       }catch(java.io.IOException ex)\r
       {\r
         ex.printStackTrace();\r
       }\r
-      if (sequences != null)\r
+      if (al != null)\r
       {\r
-        AlignFrame af = new AlignFrame(new Alignment(sequences), alignFrame.viewport.applet,\r
+        AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet,\r
                                        "Cut & Paste input - " + format,\r
                                        false);\r
         af.statusBar.setText("Successfully pasted alignment file");\r
index 1fbb82e..af01a99 100755 (executable)
@@ -143,16 +143,16 @@ public class JalviewLite extends Applet
 \r
       String format = new jalview.io.IdentifyFile().Identify(args[0],AppletFormatAdapter.FILE);\r
 \r
-      SequenceI[] sequences = null;\r
+     Alignment al = null;\r
      try{\r
-       sequences = new AppletFormatAdapter().readFile(args[0], AppletFormatAdapter.FILE, format);\r
+       al = new AppletFormatAdapter().readFile(args[0], AppletFormatAdapter.FILE, format);\r
      }catch(java.io.IOException ex)\r
      {\r
        ex.printStackTrace();\r
      }\r
-      if ( (sequences != null) && (sequences.length > 0))\r
+      if ( (al != null) && (al.getHeight() > 0))\r
       {\r
-        AlignFrame af = new AlignFrame(new Alignment(sequences), null, args[0], false);\r
+        AlignFrame af = new AlignFrame(al, null, args[0], false);\r
         af.statusBar.setText("Successfully loaded file " + args[0]);\r
       }\r
     }\r
@@ -296,17 +296,17 @@ public class JalviewLite extends Applet
 \r
         public void run()\r
         {\r
-            SequenceI[] sequences = null;\r
+            Alignment al = null;\r
             try{\r
-              sequences = new AppletFormatAdapter().readFile(file, protocol,\r
+              al = new AppletFormatAdapter().readFile(file, protocol,\r
                   format);\r
             }catch(java.io.IOException ex)\r
             {\r
               ex.printStackTrace();\r
             }\r
-            if ((sequences != null) && (sequences.length > 0))\r
+            if ((al != null) && (al.getHeight() > 0))\r
             {\r
-              currentAlignFrame = new AlignFrame(new Alignment(sequences),\r
+              currentAlignFrame = new AlignFrame(al,\r
                                                  applet,\r
                                                  file,\r
                                                  embedded);\r
index b466beb..48758cd 100755 (executable)
@@ -1283,7 +1283,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
      }
      else
      {
-       sequences = new FormatAdapter().readFile(str, "Paste", format);
+       sequences = new FormatAdapter().readFile(str, "Paste", format).getSequencesArray();
      }
 
      AlignmentI alignment = null;
index 1cd1c6a..4773c26 100755 (executable)
@@ -170,12 +170,12 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
     public void ok_actionPerformed(ActionEvent e)\r
     {\r
         String format = new IdentifyFile().Identify(getText(), "Paste");\r
-        SequenceI[] sequences = null;\r
+        Alignment al = null;\r
 \r
         if (FormatAdapter.isValidFormat(format))\r
         {\r
           try{\r
-            sequences = new FormatAdapter().readFile(getText(), "Paste", format);\r
+            al = new FormatAdapter().readFile(getText(), "Paste", format);\r
           }catch(java.io.IOException ex)\r
           {\r
             JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
@@ -185,18 +185,18 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
           }\r
         }\r
 \r
-        if (sequences != null)\r
+        if (al != null)\r
         {\r
           if(viewport!=null)\r
           {\r
-            for(int i=0; i<sequences.length; i++)\r
-              viewport.getAlignment().addSequence(sequences[i]);\r
+            for(int i=0; i<al.getHeight(); i++)\r
+              viewport.getAlignment().addSequence(al.getSequenceAt(i));\r
 \r
             viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
           }\r
           else\r
           {\r
-            AlignFrame af = new AlignFrame(new Alignment(sequences),\r
+            AlignFrame af = new AlignFrame(al,\r
                                            AlignFrame.DEFAULT_WIDTH,\r
                                            AlignFrame.DEFAULT_HEIGHT);\r
             af.currentFileFormat = format;\r
index 7031e99..f11b1d5 100755 (executable)
@@ -834,51 +834,6 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     }
 
-    jalview.gui.VamsasClient v_client=null;
-    public void vamsasLoad_actionPerformed(ActionEvent e)
-    {
-      if (v_client==null) {
-        // Start a session.
-        JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
-            getProperty("LAST_DIRECTORY"));
-
-        chooser.setFileView(new JalviewFileView());
-        chooser.setDialogTitle("Load Vamsas file");
-        chooser.setToolTipText("Import");
-
-        int value = chooser.showOpenDialog(this);
-
-        if (value == JalviewFileChooser.APPROVE_OPTION)
-        {
-          v_client = new jalview.gui.VamsasClient(this,
-              chooser.getSelectedFile());
-          this.vamsasLoad.setText("Session Update");
-          this.vamsasStop.setVisible(true);
-          v_client.initial_update();
-          v_client.startWatcher();
-        }
-      } else {
-        // store current data in session.
-        v_client.push_update();
-      }
-    }
-    public void vamsasStop_actionPerformed(ActionEvent e) {
-      if (v_client!=null) {
-        v_client.end_session();
-        v_client=null;
-        this.vamsasStop.setVisible(false);
-        this.vamsasLoad.setText("Start Vamsas Session...");
-      }
-    }
-    /**
-     * hide vamsas user gui bits when a vamsas document event is being handled.
-     * @param b true to hide gui, false to reveal gui
-     */
-    public void setVamsasUpdate(boolean b) {
-      jalview.bin.Cache.log.debug("Setting gui for Vamsas update "+(b ? "in progress" : "finished"));
-      vamsasLoad.setVisible(!b);
-      vamsasStop.setVisible(!b);
 
-    }
 }
 
index f4e289b..cb41e6e 100755 (executable)
@@ -286,7 +286,7 @@ public class SequenceFetcher
       }
 
       //Then read in the features and apply them to the dataset
-      SequenceI[] sequence = parseResult(result.toString(), null);
+      Alignment al = parseResult(result.toString(), null);
       for (int i = 0; i < entries.size(); i++)
       {
         UniprotEntry entry = (UniprotEntry) entries.elementAt(i);
@@ -304,7 +304,7 @@ public class SequenceFetcher
         Enumeration en2 = entry.getAccession().elements();
         while (en2.hasMoreElements())
         {
-          sequence[i].getDatasetSequence().addDBRef(new DBRefEntry(DBRefSource.UNIPROT,
+          al.getSequenceAt(i).getDatasetSequence().addDBRef(new DBRefEntry(DBRefSource.UNIPROT,
                     "0",
                     en2.nextElement().toString()));
         }
@@ -312,7 +312,7 @@ public class SequenceFetcher
 
 
 
-        sequence[i].getDatasetSequence().setPDBId(onlyPdbEntries);
+        al.getSequenceAt(i).getDatasetSequence().setPDBId(onlyPdbEntries);
         if (entry.getFeature() != null)
         {
           e = entry.getFeature().elements();
@@ -320,7 +320,7 @@ public class SequenceFetcher
           {
             SequenceFeature sf = (SequenceFeature) e.nextElement();
             sf.setFeatureGroup("Uniprot");
-            sequence[i].getDatasetSequence().addSequenceFeature( sf );
+            al.getSequenceAt(i).getDatasetSequence().addSequenceFeature( sf );
           }
         }
       }
@@ -370,23 +370,23 @@ public class SequenceFetcher
     return result;
   }
 
-  SequenceI[] parseResult(String result, String title)
+  Alignment parseResult(String result, String title)
   {
     String format = new IdentifyFile().Identify(result, "Paste");
-    SequenceI[] sequences = null;
+    Alignment al = null;
 
     if (FormatAdapter.isValidFormat(format))
     {
-      sequences = null;
-      try{ sequences = new FormatAdapter().readFile(result.toString(), "Paste",
+
+      try{ al = new FormatAdapter().readFile(result.toString(), "Paste",
                                                format);}
       catch(Exception ex){}
 
-      if (sequences != null && sequences.length > 0)
+      if (al != null && al.getHeight() > 0)
       {
         if (alignFrame == null)
         {
-          AlignFrame af = new AlignFrame(new Alignment(sequences),
+          AlignFrame af = new AlignFrame(al,
                                            AlignFrame.DEFAULT_WIDTH,
                                            AlignFrame.DEFAULT_HEIGHT
 );
@@ -408,19 +408,19 @@ public class SequenceFetcher
         }
         else
         {
-          for (int i = 0; i < sequences.length; i++)
+          for (int i = 0; i < al.getHeight(); i++)
           {
-            alignFrame.viewport.alignment.addSequence(sequences[i]);
+            alignFrame.viewport.alignment.addSequence(al.getSequenceAt(i));
 
             ////////////////////////////
             //Dataset needs extension;
             /////////////////////////////
-            Sequence ds = new Sequence(sequences[i].getName(),
+            Sequence ds = new Sequence(al.getSequenceAt(i).getName(),
                                        AlignSeq.extractGaps("-. ",
-                sequences[i].getSequenceAsString()),
-                                       sequences[i].getStart(),
-                                       sequences[i].getEnd());
-            sequences[i].setDatasetSequence(ds);
+                al.getSequenceAt(i).getSequenceAsString()),
+                                       al.getSequenceAt(i).getStart(),
+                                       al.getSequenceAt(i).getEnd());
+            al.getSequenceAt(i).setDatasetSequence(ds);
             alignFrame.viewport.alignment.getDataset().addSequence(ds);
           }
           alignFrame.viewport.setEndSeq(alignFrame.viewport.alignment.
@@ -436,12 +436,12 @@ public class SequenceFetcher
         {
           // Parse out the ids from the structured names
           boolean errors = false;
-          for (int i = 0; i < sequences.length; i++)
+          for (int i = 0; i < al.getHeight(); i++)
           {
             PDBEntry entry = new PDBEntry();
             com.stevesoft.pat.Regex idbits = new com.stevesoft.pat.Regex(
                 "PDB\\|([0-9A-z]{4})\\|(.)");
-            if (idbits.search(sequences[i].getName()))
+            if (idbits.search(al.getSequenceAt(i).getName()))
             {
               String pdbid = idbits.substring(1);
               String pdbccode = idbits.substring(2);
@@ -451,14 +451,14 @@ public class SequenceFetcher
                 entry.setProperty(new Hashtable());
               entry.getProperty().put("chains",
                                       pdbccode
-                                      + "=" + sequences[i].getStart()
-                                      + "-" + sequences[i].getEnd());
-              sequences[i].getDatasetSequence().addPDBId(entry);
+                                      + "=" + al.getSequenceAt(i).getStart()
+                                      + "-" + al.getSequenceAt(i).getEnd());
+              al.getSequenceAt(i).getDatasetSequence().addPDBId(entry);
 
               // We make a DBRefEtntry because we have obtained the PDB file from a verifiable source
               // JBPNote - PDB DBRefEntry should also carry the chain and mapping information
               DBRefEntry dbentry = new DBRefEntry(jalview.datamodel.DBRefSource.PDB,"0",pdbid);
-              sequences[i].getDatasetSequence().addDBRef(dbentry);
+              al.getSequenceAt(i).getDatasetSequence().addDBRef(dbentry);
             }
             else
             {
@@ -466,7 +466,7 @@ public class SequenceFetcher
               // that the user should know about.
               jalview.bin.Cache.log.warn(
                   "No PDBEntry constructed for sequence " + i + " : " +
-                  sequences[i].getName());
+                  al.getSequenceAt(i).getName());
               errors = true;
             }
           }
@@ -482,7 +482,7 @@ public class SequenceFetcher
                          + " from " + database.getSelectedItem());
     }
 
-    return sequences;
+    return al;
 
   }
 
index 85f23a4..a800f06 100755 (executable)
@@ -36,7 +36,7 @@ public abstract class AlignFile extends FileParse
     int noSeqs = 0;\r
     int maxLength = 0;\r
     Vector seqs;\r
-    Vector headers;\r
+    Vector annotations;\r
     long start;\r
     long end;\r
     boolean jvSuffix = true;\r
@@ -86,13 +86,24 @@ public abstract class AlignFile extends FileParse
         return s;\r
     }\r
 \r
+    public void addAnnotations(Alignment al)\r
+    {\r
+      for(int i=0; i<annotations.size(); i++)\r
+      {\r
+        al.addAnnotation(\r
+            (AlignmentAnnotation)annotations.elementAt(i)\r
+            );\r
+      }\r
+\r
+    }\r
+\r
     /**\r
      * Initialise objects to store sequence data in.\r
      */\r
     protected void initData()\r
     {\r
         seqs = new Vector();\r
-        headers = new Vector();\r
+        annotations = new Vector();\r
     }\r
 \r
     /**\r
index 24085d2..232de57 100755 (executable)
@@ -77,7 +77,7 @@
          *\r
          * @return DOCUMENT ME!\r
          */\r
-        public SequenceI[] readFile(String inFile, String type, String format)\r
+        public Alignment readFile(String inFile, String type, String format)\r
             throws java.io.IOException\r
         {\r
             this.inFile = inFile;\r
                 afile = new StockholmFile(inFile, type);\r
               }\r
 \r
+              Alignment al = new Alignment(afile.getSeqsAsArray());\r
 \r
-              return afile.getSeqsAsArray();\r
+              afile.addAnnotations(al);\r
+\r
+              return al;\r
             }\r
             catch (Exception e)\r
             {\r
                 try{\r
                   // Possible sequence is just residues with no label\r
                   afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");\r
-                  return afile.getSeqsAsArray();\r
+                  Alignment al = new Alignment(afile.getSeqsAsArray());\r
+                  afile.addAnnotations(al);\r
+                  return al;\r
+\r
                 }\r
                 catch(Exception ex)\r
                 {\r
index f257c6c..75915c1 100755 (executable)
@@ -22,6 +22,8 @@ import jalview.datamodel.*;
 \r
 import java.io.*;\r
 \r
+import java.util.*;\r
+\r
 \r
 /**\r
  * DOCUMENT ME!\r
@@ -59,21 +61,45 @@ public class FastaFile extends AlignFile
     public void parse() throws IOException\r
     {\r
         StringBuffer sb = new StringBuffer();\r
-        int count = 0;\r
+        boolean firstLine = true;\r
 \r
         String line;\r
         Sequence seq = null;\r
 \r
+        boolean annotation = false;\r
+\r
         while ((line = nextLine()) != null)\r
         {\r
             line = line.trim();\r
             if (line.length() > 0)\r
             {\r
-                if (line.charAt(0)=='>')\r
+              if (line.charAt(0)=='>')\r
                 {\r
-                    if (count != 0)\r
+                  if (line.startsWith(">#_"))\r
+                  {\r
+                    if (annotation)\r
                     {\r
-                      if (!isValidProteinSequence(sb.toString().toCharArray()))\r
+                      Annotation[] anots = new Annotation[sb.length()];\r
+                      for (int i = 0; i < sb.length(); i++)\r
+                      {\r
+                        anots[i] = new Annotation(sb.substring(i, i+1),\r
+                                                  null,\r
+                                                  ' ', 0);\r
+                      }\r
+                      AlignmentAnnotation aa = new AlignmentAnnotation(\r
+                          seq.getName().substring(2), seq.getDescription(),\r
+                          anots);\r
+\r
+                      annotations.add(aa);\r
+                    }\r
+                    annotation = true;\r
+                  }\r
+                  else\r
+                    annotation = false;\r
+\r
+                    if (!firstLine)\r
+                    {\r
+                      if (!annotation && !isValidProteinSequence(sb.toString().toCharArray()))\r
                       {\r
                         throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS\r
                                               +" : "+seq.getName()\r
@@ -81,12 +107,14 @@ public class FastaFile extends AlignFile
                       }\r
 \r
                        seq.setSequence(sb.toString());\r
-                       seqs.addElement(seq);\r
+\r
+                       if (!annotation)\r
+                         seqs.addElement(seq);\r
                     }\r
 \r
                     seq = parseId(line.substring(1));\r
+                    firstLine = false;\r
 \r
-                    count++;\r
                     sb = new StringBuffer();\r
                 }\r
                 else\r
@@ -96,8 +124,25 @@ public class FastaFile extends AlignFile
             }\r
         }\r
 \r
-        if (count > 0)\r
+        if (annotation)\r
+        {\r
+          Annotation[] anots = new Annotation[sb.length()];\r
+          for (int i = 0; i < sb.length(); i++)\r
+          {\r
+            anots[i] = new Annotation(sb.substring(i, i + 1),\r
+                                      null,\r
+                                      ' ', 0);\r
+          }\r
+          AlignmentAnnotation aa = new AlignmentAnnotation(\r
+              seq.getName().substring(2), seq.getDescription(),\r
+              anots);\r
+\r
+          annotations.add(aa);\r
+        }\r
+\r
+        else if (!firstLine)\r
         {\r
+\r
             if (!isValidProteinSequence(sb.toString().toCharArray()))\r
             {\r
                 throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS\r
index c662ccf..34e5886 100755 (executable)
@@ -133,7 +133,7 @@ public class FileLoader implements Runnable
         if (Desktop.instance != null)\r
           Desktop.instance.startLoading(file);\r
 \r
-        SequenceI[] sequences = null;\r
+        Alignment al = null;\r
 \r
         if (format.equalsIgnoreCase("Jalview"))\r
         {\r
@@ -147,7 +147,7 @@ public class FileLoader implements Runnable
           {\r
             try\r
             {\r
-              sequences = new FormatAdapter().readFile(file, protocol, format);\r
+              al = new FormatAdapter().readFile(file, protocol, format);\r
             }\r
             catch (java.io.IOException ex)\r
             {\r
@@ -155,13 +155,13 @@ public class FileLoader implements Runnable
             }\r
           }\r
 \r
-          if ( (sequences != null) && (sequences.length > 0))\r
+          if ( (al != null) && (al.getHeight() > 0))\r
           {\r
             if (viewport != null)\r
             {\r
-              for (int i = 0; i < sequences.length; i++)\r
+              for (int i = 0; i < al.getHeight(); i++)\r
               {\r
-                viewport.getAlignment().addSequence(sequences[i]);\r
+                viewport.getAlignment().addSequence(al.getSequenceAt(i));\r
               }\r
               viewport.firePropertyChange("alignment", null,\r
                                           viewport.getAlignment().getSequences());\r
@@ -169,8 +169,6 @@ public class FileLoader implements Runnable
             }\r
             else\r
             {\r
-              Alignment al = new Alignment(sequences);\r
-\r
               alignFrame = new AlignFrame(al,\r
                                            AlignFrame.DEFAULT_WIDTH,\r
                                            AlignFrame.DEFAULT_HEIGHT);\r
index a23bbba..15d4dc3 100755 (executable)
@@ -38,10 +38,12 @@ public class FormatAdapter extends AppletFormatAdapter
       {\r
         SequenceI [] tmp = new SequenceI[seqs.length];\r
         for(int i=0; i<seqs.length; i++)\r
-          tmp [i] = new Sequence(\r
+        {\r
+          tmp[i] = new Sequence(\r
               seqs[i].getName(), omitHiddenColumns[i],\r
               seqs[i].getStart(), seqs[i].getEnd());\r
-\r
+          tmp[i].setDescription(seqs[i].getDescription());\r
+        }\r
         seqs = tmp;\r
       }\r
 \r
index 3cbef12..016e9d1 100755 (executable)
@@ -23,7 +23,7 @@ import java.awt.event.*;
 import javax.swing.*;\r
 import javax.swing.event.*;\r
 import jalview.io.FormatAdapter;\r
-import jalview.datamodel.SequenceI;\r
+import jalview.datamodel.Alignment;;\r
 import java.awt.BorderLayout;\r
 \r
 public class GFinder\r
@@ -163,14 +163,14 @@ public class GFinder
         public void run()\r
         {\r
           String str = textfield.getText();\r
-          SequenceI[] sequences = null;\r
-          try{sequences = new FormatAdapter().readFile(str, "Paste", "FASTA");}\r
+          Alignment al = null;\r
+          try{al = new FormatAdapter().readFile(str, "Paste", "FASTA");}\r
           catch(Exception ex){}\r
-          if(sequences!=null && sequences.length>0)\r
+          if(al!=null && al.getHeight()>0)\r
           {\r
             str = jalview.analysis.AlignSeq.extractGaps(\r
                 jalview.util.Comparison.GapChars,\r
-                sequences[0].getSequenceAsString());\r
+                al.getSequenceAt(0).getSequenceAsString());\r
 \r
             textfield.setText(str);\r
           }\r
index 0e4e396..0c9b8d3 100644 (file)
@@ -93,8 +93,8 @@ implements WSClientI
             al = new Alignment(sqs);\r
             alcsel=(ColumnSelection) alandcolsel[1];\r
           } else {\r
-            al = new Alignment(new FormatAdapter().readFile(result.getAligfile(),\r
-                "Paste", format));\r
+            al = new FormatAdapter().readFile(result.getAligfile(),\r
+                "Paste", format);\r
             sqs = new SequenceI[al.getHeight()];\r
 \r
             for (int i = 0, j = al.getHeight(); i < j; i++)\r