Adjust seq limits for visual and dataset sequences
authoramwaterhouse <Andrew Waterhouse>
Tue, 1 Nov 2005 11:32:35 +0000 (11:32 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 1 Nov 2005 11:32:35 +0000 (11:32 +0000)
src/jalview/gui/AlignFrame.java
src/jalview/gui/Desktop.java
src/jalview/io/SequenceFeatureFetcher.java
src/jalview/io/WSWUBlastClient.java

index 1d408db..77396c9 100755 (executable)
@@ -617,7 +617,6 @@ public class AlignFrame
   {\r
     if (viewport.getSelectionGroup() == null)\r
     {\r
-      System.out.println("nothing selected");\r
       return;\r
     }\r
 \r
@@ -687,13 +686,14 @@ public class AlignFrame
       seqs[i].setDBRef(seq.getDBRef());\r
       seqs[i].setSequenceFeatures(seq.getSequenceFeatures());\r
       seqs[i].setDatasetSequence(seq.getDatasetSequence());\r
+\r
     }\r
 \r
-    Desktop.jalviewClipboard = new Object[]{seqs,  viewport.alignment.getDataset()};\r
     FastaFile ff = new FastaFile();\r
     ff.addDBPrefix( viewport.showDBPrefix );\r
     ff.addJVSuffix( viewport.showJVSuffix );\r
     c.setContents(new StringSelection( ff.print(seqs)), this);\r
+    Desktop.jalviewClipboard = new Object[]{seqs,  viewport.alignment.getDataset()};\r
   }\r
 \r
   /**\r
@@ -749,8 +749,9 @@ public class AlignFrame
        sequences = (SequenceI[])Desktop.jalviewClipboard[0];\r
      }\r
      else\r
+     {\r
        sequences = new FormatAdapter().readFile(str, "Paste", format);\r
-\r
+     }\r
 \r
       if (newAlignment)\r
       {\r
@@ -782,8 +783,24 @@ public class AlignFrame
       {\r
         //!newAlignment\r
         for (int i = 0; i < sequences.length; i++)\r
+        {\r
           viewport.alignment.addSequence(sequences[i]);\r
+          if(sequences[i].getDatasetSequence()==null)\r
+          {\r
+             ////////////////////////////\r
+            //Datset needs extension;\r
+            /////////////////////////////\r
+            Sequence ds = new Sequence(sequences[i].getName(),\r
+                                       AlignSeq.extractGaps("-. ", sequences[i].getSequence()),\r
+                                       sequences[i].getStart(),\r
+                                       sequences[i].getEnd());\r
+            sequences[i].setDatasetSequence(ds);\r
+            viewport.alignment.getDataset().addSequence(ds);\r
+\r
 \r
+          }\r
+\r
+        }\r
         viewport.setEndSeq(viewport.alignment.getHeight());\r
         viewport.alignment.getWidth();\r
         viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
@@ -1369,13 +1386,13 @@ public class AlignFrame
   {\r
     viewport.showSequenceFeatures(sequenceFeatures.isSelected());\r
 \r
-   // if (viewport.showSequenceFeatures &&\r
-     //   ! ( (Alignment) viewport.alignment.getDataset()).featuresAdded)\r
+    if (viewport.showSequenceFeatures &&\r
+        ! ( (Alignment) viewport.alignment.getDataset()).featuresAdded)\r
     {\r
-     // System.out.println("new fetcher");\r
-    //  new SequenceFeatureFetcher(viewport.\r
-     //     alignment,\r
-     //     alignPanel);\r
+      System.out.println("new fetcher");\r
+      new SequenceFeatureFetcher(viewport.\r
+         alignment,\r
+          alignPanel);\r
     }\r
 \r
     featureSettings.setEnabled(true);\r
index ba9d9a6..7569831 100755 (executable)
@@ -19,7 +19,6 @@
 package jalview.gui;
 
 import jalview.io.*;
-import jalview.datamodel.*;
 
 import java.awt.*;
 import java.awt.datatransfer.*;
index 35a9a95..f3f144c 100755 (executable)
@@ -43,13 +43,12 @@ public class SequenceFeatureFetcher implements Runnable
 {\r
 \r
   AlignmentI align;\r
+  AlignmentI dataset;\r
   AlignmentPanel ap;\r
   ArrayList unknownSequences;\r
   CutAndPasteTransfer output = new CutAndPasteTransfer();\r
   StringBuffer sbuffer = new StringBuffer();\r
 \r
-  Vector localCache = new Vector();\r
-\r
   Vector getUniprotEntries(File file)\r
   {\r
 \r
@@ -66,23 +65,11 @@ public class SequenceFeatureFetcher implements Runnable
       unmar.setIgnoreExtraElements(true);\r
       unmar.setMapping(map);\r
       uni = (UniprotFile) unmar.unmarshal(new FileReader(file));\r
-      localCache.addAll( uni.getUniprotEntries() );\r
-\r
-      // 3. marshal the data with the total price back and print the XML in the console\r
-    //    Marshaller marshaller = new Marshaller(\r
-      //      new FileWriter(jalview.bin.Cache.getProperty("UNIPROT_CACHE"))\r
-     //       );\r
-       //  marshaller.setMapping(map);\r
-       //  marshaller.marshal(uni);\r
 \r
     }\r
     catch (Exception e)\r
     {\r
       System.out.println("Error getUniprotEntries() "+e);\r
-     // e.printStackTrace();\r
-     // if(!updateLocalCache)\r
-      //  file.delete();\r
-\r
     }\r
     return uni.getUniprotEntries();\r
   }\r
@@ -96,7 +83,8 @@ public class SequenceFeatureFetcher implements Runnable
   public SequenceFeatureFetcher(AlignmentI align, AlignmentPanel ap)\r
   {\r
     unknownSequences = new ArrayList();\r
-    this.align = align.getDataset();\r
+    this.align = align;\r
+    this.dataset = align.getDataset();\r
     this.ap = ap;\r
 \r
     Thread thread = new Thread(this);\r
@@ -111,7 +99,7 @@ public class SequenceFeatureFetcher implements Runnable
     try\r
     {\r
       int seqIndex = 0;\r
-      Vector sequences = align.getSequences();\r
+      Vector sequences = dataset.getSequences();\r
 \r
       while (seqIndex < sequences.size())\r
       {\r
@@ -121,8 +109,11 @@ public class SequenceFeatureFetcher implements Runnable
              seqIndex++, i++)\r
         {\r
           SequenceI sequence = (SequenceI) sequences.get(seqIndex);\r
-          ids.add(sequence.getName());\r
-          unknownSequences.add(sequence.getName());\r
+          if(!ids.contains(sequence.getName()))\r
+          {\r
+            ids.add(sequence.getName());\r
+            unknownSequences.add(sequence.getName());\r
+          }\r
         }\r
 \r
         ///////////////////////////////////\r
@@ -142,7 +133,7 @@ public class SequenceFeatureFetcher implements Runnable
 \r
           if (file != null)\r
           {\r
-            ReadUniprotFile(file, align, ids);\r
+            ReadUniprotFile(file, ids);\r
           }\r
         }\r
       }\r
@@ -160,6 +151,9 @@ public class SequenceFeatureFetcher implements Runnable
           "Save your alignment to maintain the updated id.\n\n" +\r
           sbuffer.toString());\r
       Desktop.addInternalFrame(output, "Sequence names updated ", 600, 300);\r
+      // The above is the dataset, we must now find out the index\r
+      // of the viewed sequence\r
+\r
     }\r
 \r
     if (unknownSequences.size() > 0)\r
@@ -174,7 +168,7 @@ public class SequenceFeatureFetcher implements Runnable
        new WSWUBlastClient(ap, align, unknownSequences);\r
     }\r
     else\r
-       ((Alignment)align).featuresAdded = true;\r
+       ((Alignment)dataset).featuresAdded = true;\r
 \r
 \r
     ap.repaint();\r
@@ -187,7 +181,7 @@ public class SequenceFeatureFetcher implements Runnable
    * @param out DOCUMENT ME!\r
    * @param align DOCUMENT ME!\r
    */\r
-  void ReadUniprotFile(File file, AlignmentI align, Vector ids)\r
+  void ReadUniprotFile(File file, Vector ids)\r
   {\r
     if(!file.exists())\r
       return;\r
@@ -203,14 +197,13 @@ public class SequenceFeatureFetcher implements Runnable
     {\r
       entry = (UniprotEntry) entries.elementAt(i);\r
       String idmatch = entry.getAccession().elementAt(0).toString();\r
-      sequence = align.findName(idmatch);\r
+      sequence = dataset.findName(idmatch);\r
 \r
       if (sequence == null)\r
       {\r
         //Sequence maybe Name, not Accession\r
-\r
         idmatch = entry.getName().elementAt(0).toString();;\r
-        sequence = align.findName(idmatch);\r
+        sequence = dataset.findName(idmatch);\r
       }\r
 \r
       if (sequence == null)\r
@@ -239,17 +232,47 @@ public class SequenceFeatureFetcher implements Runnable
       int absEnd = absStart + nonGapped.toString().length();\r
       absStart += 1;\r
 \r
-      if ( (absStart != sequence.getStart()) ||\r
-          (absEnd != sequence.getEnd()))\r
+      sequence.setSequenceFeatures(entry.getFeatures());\r
+      sequence.setStart(absStart);\r
+      sequence.setEnd(absEnd);\r
+\r
+      if ( (absStart != sequence.getStart()) || (absEnd != sequence.getEnd()))\r
       {\r
         sbuffer.append("Updated: " + sequence.getName() + " " +\r
                        sequence.getStart() + "/" + sequence.getEnd() +\r
                        "  to  " + absStart + "/" + absEnd + "\n");\r
       }\r
 \r
-      sequence.setSequenceFeatures(entry.getFeatures());\r
-      sequence.setStart(absStart);\r
-      sequence.setEnd(absEnd);\r
+\r
+\r
+      int n = 0;\r
+      SequenceI seq2;\r
+      while (n < align.getHeight())\r
+      {\r
+        //This loop enables multiple sequences with the same\r
+        //id to have features added and seq limits updated\r
+        seq2 = align.getSequenceAt(n);\r
+        if (seq2.getName().equals(idmatch))\r
+        {\r
+\r
+          nonGapped = AlignSeq.extractGaps("-. ", seq2.getSequence());\r
+\r
+          absStart = sequence.getSequence().indexOf(nonGapped);\r
+          absEnd = absStart + nonGapped.toString().length() - 1;\r
+\r
+          sbuffer.append("Updated: VISUAL " + seq2.getName() + " " +\r
+                         seq2.getStart() + "/" + seq2.getEnd() +\r
+                         "  to  " + (absStart + sequence.getStart()) + "/" +\r
+\r
+                         (absEnd + sequence.getStart()) + "\n");\r
+\r
+          seq2.setStart(absStart + sequence.getStart());\r
+          seq2.setEnd(absEnd + sequence.getStart());\r
+\r
+        }\r
+\r
+        n++;\r
+      }\r
     }\r
   }\r
 }\r
index 2e3ccfa..8e4532c 100755 (executable)
@@ -138,6 +138,38 @@ public class WSWUBlastClient
 \r
     void updateIds()\r
     {\r
+      int reply = JOptionPane.showConfirmDialog(\r
+          Desktop.desktop, "Automatically update suggested ids?",\r
+          "Auto replace sequence ids", JOptionPane.YES_NO_OPTION);\r
+\r
+      if (reply == JOptionPane.YES_OPTION)\r
+      {\r
+        Enumeration keys = suggestedIds.keys();\r
+        while(keys.hasMoreElements())\r
+        {\r
+          String oldid = keys.nextElement().toString();\r
+          SequenceI sequence = al.findName(oldid);\r
+          sequence.setName( suggestedIds.get(oldid).toString() );\r
+\r
+          sequence = sequence.getDatasetSequence();\r
+          if(sequence!=null)\r
+          {\r
+\r
+            sequence.setName(suggestedIds.get(oldid).toString());\r
+\r
+            Vector entries = sequence.getDBRef();\r
+            if(entries!=null)\r
+            {\r
+              DBRefEntry entry = (DBRefEntry) entries.elementAt(0);\r
+              sequence.addDBRef(new jalview.datamodel.DBRefEntry("UNIPROT",\r
+                  "0",\r
+                  entry.getAccessionId()));\r
+            }\r
+          }\r
+          System.out.println("replace "+oldid+" with "+suggestedIds.get(oldid));\r
+        }\r
+      }\r
+      ap.repaint();\r
 \r
     }\r
 \r
@@ -182,32 +214,7 @@ public class WSWUBlastClient
 \r
             if (jobsRunning == 0)\r
             {\r
-              int reply = JOptionPane.showConfirmDialog(\r
-                  Desktop.desktop, "Automatically update suggested ids?",\r
-                  "Auto replace sequence ids", JOptionPane.YES_NO_OPTION);\r
-\r
-              if (reply == JOptionPane.YES_OPTION)\r
-              {\r
-                Enumeration keys = suggestedIds.keys();\r
-                while(keys.hasMoreElements())\r
-                {\r
-                  String oldid = keys.nextElement().toString();\r
-                  SequenceI sequence = al.findName(oldid);\r
-                  sequence.setName( suggestedIds.get(oldid).toString() );\r
-\r
-                  sequence = al.getDataset().findName(oldid);\r
-                  Vector entries = sequence.getDBRef();\r
-                  DBRefEntry entry = (DBRefEntry) entries.elementAt(0);\r
-                  sequence.addDBRef(new jalview.datamodel.DBRefEntry("UNIPROT",\r
-                      "0",\r
-                      entry.getAccessionId()));\r
-\r
-                  sequence.setName(suggestedIds.get(oldid).toString());\r
-\r
-                  System.out.println("replace "+oldid+" with "+suggestedIds.get(oldid));\r
-                }\r
-              }\r
-              ap.repaint();\r
+              updateIds();\r
             }\r
         }\r
     }\r