Can specify PDB chain to map sequence to - only used by applet so far
authoramwaterhouse <Andrew Waterhouse>
Tue, 1 May 2007 12:25:38 +0000 (12:25 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 1 May 2007 12:25:38 +0000 (12:25 +0000)
src/jalview/appletgui/APopupMenu.java
src/jalview/appletgui/AppletJmol.java
src/jalview/appletgui/CutAndPasteTransfer.java
src/jalview/bin/JalviewLite.java
src/jalview/gui/AppJMol.java
src/jalview/gui/Jalview2XML.java
src/jalview/gui/PopupMenu.java
src/jalview/structure/StructureSelectionManager.java

index 072621b..41b5076 100755 (executable)
@@ -517,14 +517,14 @@ public class APopupMenu
 \r
       if ( ap.av.applet.jmolAvailable )\r
        new jalview.appletgui.AppletJmol(entry,\r
-                                        new Sequence[]\r
-                                        {seq},\r
+                                        new Sequence[]{seq},\r
+                                        null,\r
                                         ap,\r
                                         AppletFormatAdapter.URL);\r
      else\r
        new MCview.AppletPDBViewer(entry,\r
-                                  new Sequence[]\r
-                                  {seq},\r
+                                  new Sequence[]{seq},\r
+                                  null,\r
                                   ap,\r
                                   AppletFormatAdapter.URL);\r
 \r
index 4951516..29cc070 100644 (file)
@@ -67,6 +67,7 @@ public class AppletJmol extends Frame
   TextField inputLine;
   TextArea history;
   SequenceI[] sequence;
+  String [] chains;
   StructureSelectionManager ssm;
   RenderPanel renderPanel;
   AlignmentPanel ap;
@@ -78,11 +79,13 @@ public class AppletJmol extends Frame
 
   public AppletJmol(PDBEntry pdbentry,
                     SequenceI[] seq,
+                    String[] chains,
                     AlignmentPanel ap,
                     String protocol)
   {
     this.ap = ap;
     this.sequence = seq;
+    this.chains = chains;
     this.pdbentry = pdbentry;
 
    String alreadyMapped = StructureSelectionManager
@@ -92,7 +95,7 @@ public class AppletJmol extends Frame
     if (alreadyMapped != null)
     {
        StructureSelectionManager.getStructureSelectionManager()
-            .setMapping(seq, pdbentry.getFile(), protocol);
+            .setMapping(seq, chains, pdbentry.getFile(), protocol);
        //PROMPT USER HERE TO ADD TO NEW OR EXISTING VIEW?
        //FOR NOW, LETS JUST OPEN A NEW WINDOW
     }
@@ -616,14 +619,14 @@ public class AppletJmol extends Frame
       MCview.PDBfile pdb;
       if (loadedInline)
       {
-        pdb = ssm.setMapping(sequence,
+        pdb = ssm.setMapping(sequence,chains,
                                 pdbentry.getFile(),
                                 AppletFormatAdapter.PASTE);
         pdbentry.setFile("INLINE"+pdb.id);
       }
       else
       {
-         pdb = ssm.setMapping(sequence,
+         pdb = ssm.setMapping(sequence,chains,
                               pdbentry.getFile(),
                               AppletFormatAdapter.URL);
       }
index 2506752..78d7ba7 100755 (executable)
@@ -128,15 +128,15 @@ public class CutAndPasteTransfer
 \r
       if ( alignFrame.alignPanel.av.applet.jmolAvailable )\r
         new jalview.appletgui.AppletJmol(pdb,\r
-                                         new Sequence[]\r
-                                         {seq},\r
+                                         new Sequence[]{seq},\r
+                                         null,\r
                                          alignFrame.alignPanel,\r
                                          AppletFormatAdapter.PASTE);\r
       else\r
 \r
         new MCview.AppletPDBViewer(pdb,\r
-                                   new Sequence[]\r
-                                   {seq},\r
+                                   new Sequence[]{seq},\r
+                                   null,\r
                                    alignFrame.alignPanel,\r
                                    AppletFormatAdapter.PASTE);\r
 \r
index 4e2d4b7..292c659 100755 (executable)
@@ -157,19 +157,6 @@ public class JalviewLite
    */
   public void init()
   {
-    try
-    {
-      if (!System.getProperty("java.version").startsWith("1.1"))
-      {
-        Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
-        jmolAvailable = true;
-      }
-    }
-    catch (java.lang.ClassNotFoundException ex)
-    {
-      System.out.println("Jmol not available - Using MCview for structures");
-    }
-
     int r = 255;
     int g = 255;
     int b = 255;
@@ -217,6 +204,9 @@ public class JalviewLite
       }
     }
 
+    LoadJmolThread jmolAvailable = new LoadJmolThread();
+    jmolAvailable.start();
+
     final JalviewLite applet = this;
     if (getParameter("embedded") != null
         && getParameter("embedded").equalsIgnoreCase("true"))
@@ -246,33 +236,6 @@ public class JalviewLite
     }
   }
 
-  public static void main(String[] args)
-  {
-    if (args.length != 1)
-    {
-      System.out.println("\nUsage: java -jar jalviewApplet.jar fileName\n");
-      System.exit(1);
-    }
-
-    String format = new jalview.io.IdentifyFile().Identify(args[0],
-        AppletFormatAdapter.FILE);
-
-    Alignment al = null;
-    try
-    {
-      al = new AppletFormatAdapter().readFile(args[0], AppletFormatAdapter.FILE,
-                                              format);
-    }
-    catch (java.io.IOException ex)
-    {
-      ex.printStackTrace();
-    }
-    if ( (al != null) && (al.getHeight() > 0))
-    {
-      AlignFrame af = new AlignFrame(al, null, args[0], false);
-      af.statusBar.setText("Successfully loaded file " + args[0]);
-    }
-  }
 
   /**
    * Initialises and displays a new java.awt.Frame
@@ -345,9 +308,30 @@ public class JalviewLite
       g.drawString("Jalview Applet", 50, this.getSize().height / 2 - 30);
       g.drawString("Loading Data...", 50, this.getSize().height / 2);
     }
+  }
+
 
+  class LoadJmolThread extends Thread
+  {
+    public void run()
+    {
+      try
+      {
+        if (!System.getProperty("java.version").startsWith("1.1"))
+        {
+          Class.forName("org.jmol.adapter.smarter.SmarterJmolAdapter");
+          jmolAvailable = true;
+          System.out.println("JMOL FOUND");
+        }
+      }
+      catch (java.lang.ClassNotFoundException ex)
+      {
+        System.out.println("Jmol not available - Using MCview for structures");
+      }
+    }
   }
 
+
   class LoadingThread
       extends Thread
   {
@@ -380,6 +364,11 @@ public class JalviewLite
 
     public void run()
     {
+      startLoading();
+    }
+
+    private void startLoading()
+    {
       Alignment al = null;
       try
       {
@@ -507,67 +496,106 @@ public class JalviewLite
           }
         }
 
+        /*
+         <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B PDB|1GAQ|1GAQ|C">
 
-        param = getParameter("PDBFILE");
-        if (param != null)
-        {
+         <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
 
-          PDBEntry pdb = new PDBEntry();
+         <param name="PDBfile3" value="1q0o Q45135_9MICO">
+        */
 
-          String seqstring;
-          SequenceI [] seqs = null;
 
-          if(param.indexOf(" ")>-1)
+        int pdbFileCount = 0;
+        do{
+          if (pdbFileCount > 0)
+            param = getParameter("PDBFILE" + pdbFileCount);
+          else
+            param = getParameter("PDBFILE");
+
+          if (param != null)
           {
-            seqstring = param.substring(param.indexOf(" ")+1);
-            param = param.substring(0, param.indexOf(" "));
-            StringTokenizer st = new StringTokenizer(seqstring);
-            Vector tmp = new Vector();
-            while(st.hasMoreTokens())
+            PDBEntry pdb = new PDBEntry();
+
+            String seqstring;
+            SequenceI[] seqs = null;
+            String [] chains = null;
+
+            StringTokenizer st = new StringTokenizer(param, " ");
+
+            if (st.countTokens() < 2)
             {
-              tmp.addElement((Sequence) currentAlignFrame.
-                getAlignViewport().getAlignment().
-                findName(st.nextToken()));
-            }
+              String sequence = applet.getParameter("PDBSEQ");
+              if (sequence != null)
+                seqs = new SequenceI[]
+                    {
+                    (Sequence) currentAlignFrame.
+                    getAlignViewport().getAlignment().
+                    findName(sequence)};
 
-            seqs = new SequenceI[tmp.size()];
-            tmp.copyInto(seqs);
-          }
-          else
-          {
-            String sequence = applet.getParameter("PDBSEQ");
-            if (sequence != null)
-              seqs = new SequenceI[]
-                  {
-                  (Sequence) currentAlignFrame.
-                  getAlignViewport().getAlignment().
-                  findName(sequence)};
-          }
+            }
+            else
+            {
+              param = st.nextToken();
+              Vector tmp = new Vector();
+              Vector tmp2 = new Vector();
+
+              while (st.hasMoreTokens())
+              {
+                seqstring = st.nextToken();
+                StringTokenizer st2 = new StringTokenizer(seqstring,"=");
+                if(st2.countTokens()>1)
+                {
+                  //This is the chain
+                  tmp2.addElement(st2.nextToken());
+                  seqstring = st2.nextToken();
+                }
+                tmp.addElement( (Sequence) currentAlignFrame.
+                                 getAlignViewport().getAlignment().
+                                 findName(seqstring));
+              }
+
+              seqs = new SequenceI[tmp.size()];
+              tmp.copyInto(seqs);
+              if(tmp2.size()==tmp.size())
+              {
+                chains = new String[tmp2.size()];
+                tmp2.copyInto(chains);
+              }
+            }
 
-         // if (!inArchive(param) || jmolAvailable)
-          {
             param = addProtocol(param);
-          }
-
-          pdb.setFile(param);
+            pdb.setFile(param);
 
-          for(int i=0; i<seqs.length; i++)
-          {
-            ((Sequence)seqs[i]).addPDBId(pdb);
+            if(seqs!=null)
+            {
+              for (int i = 0; i < seqs.length; i++)
+              {
+                ( (Sequence) seqs[i]).addPDBId(pdb);
+              }
+
+              if (jmolAvailable)
+              {
+                new jalview.appletgui.AppletJmol(pdb,
+                                                 seqs,
+                                                 chains,
+                                                 currentAlignFrame.alignPanel,
+                                                 protocol);
+                lastFrameX += 40;
+                lastFrameY+=40;
+              }
+              else
+                    new MCview.AppletPDBViewer(pdb,
+                                           seqs,
+                                           chains,
+                                           currentAlignFrame.alignPanel,
+                                           protocol);
+            }
           }
 
-          if (jmolAvailable)
-            new jalview.appletgui.AppletJmol(pdb,
-                                             seqs,
-                                             currentAlignFrame.alignPanel,
-                                             protocol);
-          else
-
-            new MCview.AppletPDBViewer(pdb,
-                                       seqs,
-                                       currentAlignFrame.alignPanel,
-                                       protocol);
+          pdbFileCount++;
         }
+        while(pdbFileCount < 10);
+
       }
       else
       {
index e3aa9ea..3f2d895 100644 (file)
@@ -49,6 +49,7 @@ public class AppJMol
   ScriptWindow scriptWindow;
   PDBEntry pdbentry;
   SequenceI[] sequence;
+  String [] chains;
   StructureSelectionManager ssm;
   JSplitPane splitPane;
   RenderPanel renderPanel;
@@ -68,6 +69,7 @@ public class AppJMol
     pdbentry = new PDBEntry();
     pdbentry.setFile(file);
     pdbentry.setId(id);
+    this.chains = chains;
     this.sequence = seq;
     this.ap = ap;
     this.setBounds(bounds);
@@ -104,7 +106,7 @@ public synchronized void addSequence(SequenceI [] seq)
      sequence = tmp;
    }
 
-  public AppJMol(PDBEntry pdbentry, SequenceI[] seq, AlignmentPanel ap)
+  public AppJMol(PDBEntry pdbentry, SequenceI[] seq, String [] chains, AlignmentPanel ap)
   {
     //////////////////////////////////
     //Is the pdb file already loaded?
@@ -123,7 +125,7 @@ public synchronized void addSequence(SequenceI [] seq)
       if (option == JOptionPane.YES_OPTION)
       {
         StructureSelectionManager.getStructureSelectionManager()
-            .setMapping(seq, alreadyMapped, AppletFormatAdapter.FILE);
+            .setMapping(seq, chains, alreadyMapped, AppletFormatAdapter.FILE);
         if (ap.seqPanel.seqCanvas.fr!=null) {
           ap.seqPanel.seqCanvas.fr.featuresAdded();
           ap.paintAlignment(true);
@@ -739,7 +741,7 @@ public synchronized void addSequence(SequenceI [] seq)
 
       //FILE LOADED OK
       ssm = StructureSelectionManager.getStructureSelectionManager();
-      MCview.PDBfile pdbFile = ssm.setMapping(sequence, pdbentry.getFile(), AppletFormatAdapter.FILE);
+      MCview.PDBfile pdbFile = ssm.setMapping(sequence,chains,pdbentry.getFile(), AppletFormatAdapter.FILE);
       ssm.addStructureViewerListener(this);
       Vector chains = new Vector();
       for(int i=0; i<pdbFile.chains.size(); i++)
index 49b022c..198db44 100755 (executable)
@@ -1915,7 +1915,7 @@ public class Jalview2XML
               else if(comp!=null)
               {
                 StructureSelectionManager.getStructureSelectionManager()
-                    .setMapping(seq, pdbFile,
+                    .setMapping(seq, null, pdbFile,
                                 jalview.io.AppletFormatAdapter.FILE);
 
                 ( (AppJMol) comp).addSequence(seq);
index d43a015..2cd6ce5 100755 (executable)
@@ -189,7 +189,7 @@ public class PopupMenu
               SequenceI [] seqs2 = new SequenceI[seqs.size()];\r
               seqs.toArray(seqs2);\r
 \r
-              new AppJMol(pdb, seqs2, ap);\r
+              new AppJMol(pdb, seqs2, null, ap);\r
             }\r
           });\r
           viewStructureMenu.add(menuItem);\r
index 10f99a4..5af3d8e 100644 (file)
@@ -69,9 +69,11 @@ public class StructureSelectionManager
      There will be better ways of doing this in the future, for now we'll use
      the tried and tested MCview pdb mapping
    */
-  synchronized public MCview.PDBfile setMapping(SequenceI[] sequence,
-                           String pdbFile,
-                           String protocol)
+  synchronized public MCview.PDBfile setMapping(
+      SequenceI[] sequence,
+      String[] targetChains,
+      String pdbFile,
+      String protocol)
   {
     MCview.PDBfile pdb = null;
     try
@@ -84,15 +86,19 @@ public class StructureSelectionManager
       return null;
     }
 
+    String targetChain;
     for (int s = 0; s < sequence.length; s++)
     {
-      String targetChain = "";
-
-      if (sequence[s].getName().indexOf("|") > -1)
+      if(targetChains!=null && targetChains[s]!=null)
+        targetChain = targetChains[s];
+      else if (sequence[s].getName().indexOf("|") > -1)
       {
         targetChain = sequence[s].getName().substring(
             sequence[s].getName().lastIndexOf("|") + 1);
       }
+      else
+        targetChain = "";
+
 
       int max = -10;
       AlignSeq maxAlignseq = null;