Copy and paste uses FASTA format
authoramwaterhouse <Andrew Waterhouse>
Wed, 14 Sep 2005 15:42:08 +0000 (15:42 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 14 Sep 2005 15:42:08 +0000 (15:42 +0000)
src/jalview/gui/AlignFrame.java
src/jalview/jbgui/GFinder.java

index 7984991..9762258 100755 (executable)
@@ -560,15 +560,16 @@ public class AlignFrame
   {\r
     if (viewport.getSelectionGroup() == null)\r
     {\r
+      System.out.println("null here");\r
       return;\r
     }\r
 \r
     SequenceGroup sg = viewport.getSelectionGroup();\r
 \r
     Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();\r
-    StringBuffer buffer = new StringBuffer();\r
 \r
     Hashtable orderedSeqs = new Hashtable();\r
+    SequenceI [] seqs = new SequenceI[sg.getSize()];\r
 \r
     for (int i = 0; i < sg.getSize(); i++)\r
     {\r
@@ -598,6 +599,8 @@ public class AlignFrame
           index++;\r
         }\r
       }\r
+\r
+\r
       //FIND START RES\r
       //Returns residue following index if gap\r
       startRes = seq.findPosition(sg.getStartRes());\r
@@ -620,14 +623,15 @@ public class AlignFrame
         endRes += seq.getStart() - 1;\r
       }\r
 \r
-      buffer.append(seq.getName() + "\t" +\r
-                    startRes + "\t" +\r
-                    endRes + "\t" +\r
-                    seq.getSequence(sg.getStartRes(),\r
-                                    sg.getEndRes() + 1) + "\n");\r
+      seqs[i] = new Sequence(seq.getName(),\r
+                             seq.getSequence(sg.getStartRes(), sg.getEndRes()+1),\r
+                             startRes,\r
+                             endRes);\r
     }\r
 \r
-    c.setContents(new StringSelection(buffer.toString()), null);\r
+    System.out.println("BLOBL"+FastaFile.print(seqs));\r
+\r
+    c.setContents(new StringSelection(FastaFile.print(seqs)), null);\r
   }\r
 \r
   /**\r
@@ -670,33 +674,14 @@ public class AlignFrame
       }\r
 \r
       String str = (String) contents.getTransferData(DataFlavor.stringFlavor);\r
-      StringTokenizer st = new StringTokenizer(str);\r
-      ArrayList seqs = new ArrayList();\r
 \r
-      while (st.hasMoreElements())\r
-      {\r
-        String name = st.nextToken();\r
-        int start = Integer.parseInt(st.nextToken());\r
-        int end = Integer.parseInt(st.nextToken());\r
-        Sequence sequence = new Sequence(name, st.nextToken(), start,\r
-                                         end);\r
+      String format = IdentifyFile.Identify(str, "Paste");\r
+      SequenceI[] sequences = FormatAdapter.readFile(str, "Paste", format);\r
 \r
-        if (!newAlignment)\r
-        {\r
-          viewport.alignment.addSequence(sequence);\r
-        }\r
-        else\r
-        {\r
-          seqs.add(sequence);\r
-        }\r
-      }\r
 \r
       if (newAlignment)\r
       {\r
-        SequenceI[] newSeqs = new SequenceI[seqs.size()];\r
-        seqs.toArray(newSeqs);\r
-\r
-        AlignFrame af = new AlignFrame(new Alignment(newSeqs));\r
+        AlignFrame af = new AlignFrame(new Alignment(sequences));\r
         String newtitle = new String("Copied sequences");\r
 \r
         if (title.startsWith("Copied sequences"))\r
@@ -713,6 +698,10 @@ public class AlignFrame
       }\r
       else\r
       {\r
+        //!newAlignment\r
+        for (int i = 0; i < sequences.length; i++)\r
+          viewport.alignment.addSequence(sequences[i]);\r
+\r
         viewport.setEndSeq(viewport.alignment.getHeight());\r
         viewport.alignment.getWidth();\r
         viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
index 32d2f24..8ece84d 100755 (executable)
@@ -22,6 +22,10 @@ import java.awt.*;
 import java.awt.event.*;\r
 import javax.swing.*;\r
 import javax.swing.event.*;\r
+import jalview.io.FormatAdapter;\r
+import jalview.datamodel.SequenceI;\r
+import java.awt.datatransfer.DataFlavor;\r
+import jalview.io.IdentifyFile;\r
 \r
 public class GFinder\r
     extends JPanel\r
@@ -155,17 +159,21 @@ public class GFinder
 \r
   public void textfield_caretUpdate(CaretEvent e)\r
   {\r
-    if (textfield.getText().indexOf("\t") > -1)\r
+    if (textfield.getText().indexOf(">") > -1)\r
     {\r
       SwingUtilities.invokeLater(new Runnable()\r
       {\r
         public void run()\r
         {\r
-          String text = textfield.getText();\r
-          text = text.substring(text.lastIndexOf("\t") + 1).trim();\r
-          text = jalview.analysis.AlignSeq.extractGaps(\r
-              jalview.util.Comparison.GapChars, text);\r
-          textfield.setText(text);\r
+          String str = textfield.getText();\r
+          SequenceI[] sequences = FormatAdapter.readFile(str, "Paste", "FASTA");\r
+          if(sequences!=null && sequences.length>0)\r
+          {\r
+            str = jalview.analysis.AlignSeq.extractGaps(\r
+                jalview.util.Comparison.GapChars, sequences[0].getSequence());\r
+\r
+            textfield.setText(str);\r
+          }\r
         }\r
       });\r
     }\r