fix to ensure multiple accessions can be fetched for sources like the PDB (see jalvie...
authorjprocter <Jim Procter>
Tue, 7 Apr 2009 11:27:06 +0000 (11:27 +0000)
committerjprocter <Jim Procter>
Tue, 7 Apr 2009 11:27:06 +0000 (11:27 +0000)
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentI.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/SequenceFetcher.java

index 1312e22..981fdfa 100755 (executable)
@@ -442,7 +442,11 @@ public class Alignment implements AlignmentI
 
   }
 
-  /**    */
+  /*
+   * (non-Javadoc)
+   * 
+   * @see jalview.datamodel.AlignmentI#findIndex(jalview.datamodel.SequenceI)
+   */
   public int findIndex(SequenceI s)
   {
     int i = 0;
@@ -904,4 +908,110 @@ public class Alignment implements AlignmentI
     }
     return removed;
   }
+
+  public void append(AlignmentI toappend)
+  {
+    // TODO test this method for a future 2.5 release
+    // currently tested for use in jalview.gui.SequenceFetcher
+    boolean samegap = toappend.getGapCharacter()==getGapCharacter();
+    char oldc = toappend.getGapCharacter();
+    boolean hashidden = toappend.getHiddenSequences()!=null && toappend.getHiddenSequences().hiddenSequences!=null;
+    // get all sequences including any hidden ones
+    Vector sqs = (hashidden) ? toappend.getHiddenSequences().getFullAlignment().getSequences() : toappend.getSequences();
+    if (sqs != null)
+    {
+      Enumeration sq = sqs.elements();
+      while (sq.hasMoreElements())
+      {
+        SequenceI addedsq=(SequenceI) sq.nextElement();
+        if (!samegap)
+        {
+          char[] oldseq = addedsq.getSequence();
+          for (int c=0;c<oldseq.length;c++)
+          {
+            if (oldseq[c]==oldc)
+            {
+              oldseq[c] = gapCharacter;
+            }
+          }
+        }
+        addSequence(addedsq);
+      }
+    }
+    AlignmentAnnotation[] alan = toappend.getAlignmentAnnotation();
+    for (int a = 0; alan != null && a < alan.length; a++)
+    {
+      addAnnotation(alan[a]);
+    }
+    AlignedCodonFrame[] acod = toappend.getCodonFrames();
+    for (int a = 0; acod != null && a < acod.length; a++)
+    {
+      this.addCodonFrame(acod[a]);
+    }
+    Vector sg = toappend.getGroups();
+    if (sg != null)
+    {
+      Enumeration el = sg.elements();
+      while (el.hasMoreElements())
+      {
+        addGroup((SequenceGroup) el.nextElement());
+      }
+    }
+    if (toappend.getHiddenSequences()!=null)
+    {
+      HiddenSequences hs = toappend.getHiddenSequences();
+      if (hiddenSequences==null)
+      {
+        hiddenSequences = new HiddenSequences(this);
+      }
+      if (hs.hiddenSequences!=null)
+      {
+        for (int s=0;s<hs.hiddenSequences.length; s++)
+        {
+          // hide the newly appended sequence in the alignment
+          if (hs.hiddenSequences[s]!=null)
+          {
+            hiddenSequences.hideSequence(hs.hiddenSequences[s]);
+          }
+        }
+      }
+    }
+    if (toappend.getProperties()!=null)
+    {
+      // we really can't do very much here - just try to concatenate strings where property collisions occur.
+      Enumeration key = toappend.getProperties().keys();
+      while (key.hasMoreElements())
+      {
+        Object k = key.nextElement();
+        Object ourval = this.getProperty(k);
+        Object toapprop = toappend.getProperty(k);
+        if (ourval!=null)
+        {
+          if (ourval.getClass().equals(toapprop.getClass()) && !ourval.equals(toapprop))
+          {
+            if (ourval instanceof String)
+            {
+              // append strings
+              this.setProperty(k, ((String) ourval)+"; "+((String) toapprop));
+            } else {
+              if (ourval instanceof Vector)
+              {
+                // append vectors
+                Enumeration theirv = ((Vector) toapprop).elements();
+                while (theirv.hasMoreElements())
+                {
+                  ((Vector)ourval).addElement(theirv);
+                }
+              }
+            }
+          }
+        } else {
+          // just add new property directly
+          setProperty(k, toapprop);
+        }
+       
+      }
+    }
+  }
+
 }
index b4075a0..9254876 100755 (executable)
@@ -359,4 +359,14 @@ public interface AlignmentI
    */
   public SequenceI findName(SequenceI startAfter, String token, boolean b);
 
+  /**
+   * append sequences and annotation from another alignment object to this one.
+   * Note: this is a straight transfer of object references, and may result in 
+   * toappend's dependent data being transformed to fit the alignment (changing gap characters, etc...).
+   * If you are uncertain, use the copy Alignment copy constructor to create a new version
+   * which can be appended without side effect.
+   * @param toappend - the alignment to be appended. 
+   */
+  public void append(AlignmentI toappend);
+
 }
index 8adcb0d..6cd76dd 100755 (executable)
@@ -4059,6 +4059,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       buildSortByAnnotationScoresMenu();
     }
   }
+
+  public void setShowSeqFeatures(boolean b)
+  {
+    showSeqFeatures.setSelected(true);
+    viewport.setShowSequenceFeatures(true);
+  }
 }
 
 class PrintThread extends Thread
index ccd0f72..88b0c2b 100755 (executable)
@@ -385,14 +385,60 @@ public class SequenceFetcher extends JPanel implements Runnable
       return;
     }
     AlignmentI aresult = null;
+    Object source = database.getSelectedItem();
+    Enumeration en = new StringTokenizer(textArea.getText(), ";");
     try
     {
       guiWindow.setProgressBar("Fetching Sequences from "
               + database.getSelectedItem(), Thread.currentThread()
               .hashCode());
-      aresult = sfetch.getSourceProxy(
-              (String) sources.get(database.getSelectedItem()))
-              .getSequenceRecords(textArea.getText());
+      DbSourceProxy proxy = sfetch.getSourceProxy(
+              (String) sources.get(source));
+      if (proxy.getAccessionSeparator()==null)
+      {
+        while (en.hasMoreElements())
+        {
+          String item = (String) en.nextElement();
+          try {
+            if (aresult!=null)
+            {
+              try {
+                // give the server a chance to breathe
+                Thread.sleep(5);
+              } catch (Exception e)
+              {
+                //
+              }
+
+            }
+            AlignmentI indres = proxy.getSequenceRecords(item);
+            if (indres!=null)
+            {
+              if (aresult == null)
+              {
+                aresult = indres;
+              } else {
+                aresult.append(indres);
+              }
+            }
+          } catch (Exception e)
+          {
+            jalview.bin.Cache.log.info("Error retrieving "+item+" from "+source,e);
+          }
+        }
+      } else {
+        StringBuffer multiacc = new StringBuffer();
+        while (en.hasMoreElements())
+        {
+          multiacc.append(en.nextElement());
+          if (en.hasMoreElements())
+          {
+            multiacc.append(proxy.getAccessionSeparator());
+          }
+        }
+        aresult = proxy
+              .getSequenceRecords(multiacc.toString());
+      }
 
     } catch (Exception e)
     {
@@ -618,7 +664,19 @@ public class SequenceFetcher extends JPanel implements Runnable
         {
           title = "Retrieved from " + database.getSelectedItem();
         }
+        SequenceFeature[] sfs=null;
+        for (Enumeration sq=al.getSequences().elements(); sq.hasMoreElements();)
+        {
+          if ((sfs=((SequenceI)sq.nextElement()).getDatasetSequence().getSequenceFeatures())!=null)
+          {
+            if (sfs.length>0)
+            {
+              af.setShowSeqFeatures(true);
+              break;
+            }
+          }
 
+        }
         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
                 AlignFrame.DEFAULT_HEIGHT);