Merge branch 'jims_marckhacks' into develop
authorJim Procter <jprocter@dundee.ac.uk>
Mon, 21 Apr 2014 16:42:05 +0000 (17:42 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Mon, 21 Apr 2014 16:42:05 +0000 (17:42 +0100)
32 files changed:
examples/testdata/test_grpannot.jva [new file with mode: 0644]
resources/lang/Messages.properties
src/jalview/analysis/AlignmentUtils.java [new file with mode: 0644]
src/jalview/analysis/NJTree.java
src/jalview/analysis/PCA.java
src/jalview/analysis/scoremodels/PIDScoreModel.java [new file with mode: 0644]
src/jalview/analysis/scoremodels/PairwiseSeqScoreModel.java [new file with mode: 0644]
src/jalview/analysis/scoremodels/SWScoreModel.java [new file with mode: 0644]
src/jalview/api/analysis/ScoreModelI.java [new file with mode: 0644]
src/jalview/appletgui/AlignFrame.java
src/jalview/datamodel/AlignmentView.java
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AppJmol.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/Jalview2XML.java
src/jalview/gui/PCAPanel.java
src/jalview/gui/PopupMenu.java
src/jalview/io/AnnotationFile.java
src/jalview/jbgui/GAlignFrame.java
src/jalview/jbgui/GPCAPanel.java
src/jalview/schemes/AnnotationColourGradient.java
src/jalview/schemes/ResidueProperties.java
src/jalview/schemes/ScoreMatrix.java
src/jalview/util/MessageManager.java
src/jalview/viewmodel/AlignmentViewport.java
src/jalview/viewmodel/PCAModel.java
src/jalview/ws/DBRefFetcher.java
src/jalview/ws/jws2/AADisorderClient.java
test/jalview/analysis/AlignmentUtilsTests.java [new file with mode: 0644]
test/jalview/io/AnnotationFileIOTest.java
test/jalview/schemes/ScoreMatrixPrinter.java

diff --git a/examples/testdata/test_grpannot.jva b/examples/testdata/test_grpannot.jva
new file mode 100644 (file)
index 0000000..1259bdc
--- /dev/null
@@ -0,0 +1,5 @@
+JALVIEW_ANNOTATION
+
+SEQUENCE_GROUP mygrpa  1       10      -1      FER_CAPAA       FER_SPIOL       FER1_MAIZE
+SEQUENCE_GROUP another group   150     250     -1      FER1_MAIZE
+
index 5315376..775df57 100644 (file)
@@ -132,6 +132,9 @@ action.group_link = Group Links
 action.show_chain = Show Chain\r
 action.show_group = Show Group\r
 action.fetch_db_references = Fetch DB References\r
+action.edit = Edit\r
+action.view_flanking_regions = Show flanking regions\r
+label.view_flanking_regions = Show sequence data either side of the subsequences involved in this alignment\r
 label.str = Str:\r
 label.seq = Seq:\r
 label.structures_manager = Structures Manager\r
@@ -162,6 +165,15 @@ label.redo_command = Redo {0}
 label.principal_component_analysis = Principal Component Analysis\r
 label.average_distance_identity = Average Distance Using % Identity\r
 label.neighbour_joining_identity = Neighbour Joining Using % Identity\r
+label.treecalc_title = {0} Using {1}\r
+label.tree_calc_av = Average Distance\r
+label.tree_calc_nj = Neighbour Joining\r
+label.select_score_model = Select score model\r
+label.score_model_pid = % Identity\r
+label.score_model_blosum62 = BLOSUM62\r
+label.score_model_pam250 = PAM 250\r
+label.score_model_conservation = Physicochemical property conservation\r
+label.score_model_enhconservation = Physicochemical property conservation\r
 label.status_bar = Status bar\r
 label.out_to_textbox = Output to Textbox\r
 label.clustalx = Clustalx\r
@@ -433,6 +445,7 @@ label.calculating_tree = Calculating tree
 label.state_queueing = queuing\r
 label.state_running = running\r
 label.state_complete = complete\r
+label.state_completed = finished\r
 label.state_job_cancelled = job cancelled!!\r
 label.state_job_error = job error!\r
 label.server_error_try_later = Server Error! (try later)\r
@@ -615,6 +628,8 @@ label.2d_rna_sequence_name = 2D RNA - {0}
 label.edit_name_and_description_current_group = Edit name and description of current group.\r
 label.view_structure_for = View structure for {0}\r
 label.view_all_structures = View all {0} structures.\r
+label.view_all_representative_structures = View all {0} representative structures.\r
+label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment = "Opens a new Jmol view with all representative structures\nassociated with the current selection\nsuperimposed with the current alignment."\r
 label.associate_structure_with_sequence = Associate Structure with Sequence\r
 label.from_file = from file\r
 label.enter_pdb_id = Enter PDB Id\r
@@ -722,4 +737,5 @@ label.wswublast_client_credits = To display sequence features an exact Uniprot i
 label.blasting_for_unidentified_sequence = BLASTing for unidentified sequences
 label.select_columns_containing = Select columns containing\r
 label.select_columns_not_containing = Select columns that do not contain\r
-\r
+option.trim_retrieved_seqs = Trim retrieved sequences\r
+label.trim_retrieved_sequences = When the reference sequence is longer than the sequence that you are working with, only keep the relevant subsequences.\r
diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java
new file mode 100644 (file)
index 0000000..85699a4
--- /dev/null
@@ -0,0 +1,92 @@
+package jalview.analysis;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import jalview.datamodel.SequenceI;
+import jalview.datamodel.AlignmentI;
+
+/**
+ * grab bag of useful alignment manipulation operations
+ * Expect these to be refactored elsewhere at some point.
+ * @author jimp
+ *
+ */
+public class AlignmentUtils
+{
+
+  /**
+   * given an existing alignment, create a new alignment including all, or up to flankSize additional symbols from each sequence's dataset sequence
+   * @param core
+   * @param flankSize
+   * @return AlignmentI
+   */
+  public static AlignmentI expandContext(AlignmentI core, int flankSize)
+  {
+    List<SequenceI> sq = new ArrayList<SequenceI>();
+    int maxoffset = 0;
+    for (SequenceI s:core.getSequences())
+    {
+      SequenceI newSeq = s.deriveSequence();
+      if (newSeq.getStart()>maxoffset && newSeq.getDatasetSequence().getStart()<s.getStart())
+      {
+        maxoffset = newSeq.getStart();
+      }
+      sq.add(newSeq);
+    }
+    if (flankSize>-1) {
+      maxoffset = flankSize;
+    }
+    // now add offset to create a new expanded alignment
+    for (SequenceI s:sq)
+    {
+      SequenceI ds = s;
+      while (ds.getDatasetSequence()!=null) {
+        ds=ds.getDatasetSequence();
+      }
+      int s_end = s.findPosition(s.getStart()+s.getLength());
+      // find available flanking residues for sequence
+      int ustream_ds=s.getStart()-ds.getStart(),dstream_ds=ds.getEnd()-s_end;
+      
+      // build new flanked sequence
+      
+      // compute gap padding to start of flanking sequence
+      int offset=maxoffset - ustream_ds;
+      
+      // padding is gapChar x ( maxoffset - min(ustream_ds, flank)
+      if (flankSize>=0) {
+        if (flankSize<ustream_ds)
+        {
+        // take up to flankSize residues
+        offset = maxoffset-flankSize;
+        ustream_ds = flankSize;
+      }
+        if (flankSize<dstream_ds)
+        {
+          dstream_ds=flankSize;
+        }
+      }
+      char[] upstream = new String(ds.getSequence(s.getStart()-1-ustream_ds, s.getStart()-1)).toLowerCase().toCharArray();
+      char[] downstream = new String(ds.getSequence(s_end-1,s_end+1+dstream_ds)).toLowerCase().toCharArray();
+      char[] coreseq=s.getSequence();
+      char[] nseq = new char[offset+upstream.length+downstream.length+coreseq.length]; 
+      char c = core.getGapCharacter();
+      // TODO could lowercase the flanking regions
+      int p=0;
+      for (; p<offset;p++)
+      {
+        nseq[p] = c;
+      }
+//      s.setSequence(new String(upstream).toLowerCase()+new String(coreseq) + new String(downstream).toLowerCase());
+      System.arraycopy(upstream, 0, nseq, p, upstream.length);
+      System.arraycopy(coreseq, 0, nseq, p+upstream.length, coreseq.length);
+      System.arraycopy(downstream, 0, nseq, p+coreseq.length+upstream.length, downstream.length);
+      s.setSequence(new String(nseq));
+      s.setStart(s.getStart()-ustream_ds);
+      s.setEnd(s_end+downstream.length);
+    }
+    AlignmentI newAl = new jalview.datamodel.Alignment(sq.toArray(new SequenceI[0]));
+    newAl.setDataset(core.getDataset());
+    return newAl;
+  }
+}
index 944354f..41d599e 100644 (file)
@@ -20,6 +20,7 @@ package jalview.analysis;
 
 import java.util.*;
 
+import jalview.api.analysis.ScoreModelI;
 import jalview.datamodel.*;
 import jalview.io.*;
 import jalview.schemes.*;
@@ -254,8 +255,7 @@ public class NJTree
 
     noseqs = i++;
 
-    distance = findDistances(this.seqData
-            .getSequenceStrings(Comparison.GapChars.charAt(0)));
+    distance = findDistances();
     // System.err.println("Made distances");// dbg
     makeLeaves();
     // System.err.println("Made leaves");// dbg
@@ -716,100 +716,25 @@ public class NJTree
   }
 
   /**
-   * DOCUMENT ME!
+   * Calculate a distance matrix given the sequence input data and score model
    * 
-   * @return DOCUMENT ME!
+   * @return similarity matrix used to compute tree
    */
-  public float[][] findDistances(String[] sequenceString)
+  public float[][] findDistances()
   {
+    
     float[][] distance = new float[noseqs][noseqs];
 
-    if (pwtype.equals("PID"))
-    {
-      for (int i = 0; i < (noseqs - 1); i++)
-      {
-        for (int j = i; j < noseqs; j++)
-        {
-          if (j == i)
-          {
-            distance[i][i] = 0;
-          }
-          else
-          {
-            distance[i][j] = 100 - Comparison.PID(sequenceString[i],
-                    sequenceString[j]);
-
-            distance[j][i] = distance[i][j];
-          }
-        }
-      }
-    }
-    else
-    {
       // Pairwise substitution score (with no gap penalties)
-      ScoreMatrix pwmatrix = ResidueProperties.getScoreMatrix(pwtype);
-      if (pwmatrix == null)
+      ScoreModelI _pwmatrix = ResidueProperties.getScoreModel(pwtype);
+      if (_pwmatrix == null)
       {
-        pwmatrix = ResidueProperties.getScoreMatrix("BLOSUM62");
+        _pwmatrix = ResidueProperties.getScoreMatrix("BLOSUM62");
       }
-      int maxscore = 0;
-      int end = sequenceString[0].length();
-      for (int i = 0; i < (noseqs - 1); i++)
-      {
-        for (int j = i; j < noseqs; j++)
-        {
-          int score = 0;
-
-          for (int k = 0; k < end; k++)
-          {
-            try
-            {
-              score += pwmatrix.getPairwiseScore(
-                      sequenceString[i].charAt(k),
-                      sequenceString[j].charAt(k));
-            } catch (Exception ex)
-            {
-              System.err.println("err creating BLOSUM62 tree");
-              ex.printStackTrace();
-            }
-          }
-
-          distance[i][j] = (float) score;
-
-          if (score > maxscore)
-          {
-            maxscore = score;
-          }
-        }
-      }
-
-      for (int i = 0; i < (noseqs - 1); i++)
-      {
-        for (int j = i; j < noseqs; j++)
-        {
-          distance[i][j] = (float) maxscore - distance[i][j];
-          distance[j][i] = distance[i][j];
-        }
-      }
-
-    }
+      distance = _pwmatrix.findDistances(seqData);
     return distance;
 
-    // else
-    /*
-     * else if (pwtype.equals("SW")) { float max = -1;
-     * 
-     * for (int i = 0; i < (noseqs - 1); i++) { for (int j = i; j < noseqs; j++)
-     * { AlignSeq as = new AlignSeq(sequence[i], sequence[j], "pep");
-     * as.calcScoreMatrix(); as.traceAlignment(); as.printAlignment(System.out);
-     * distance[i][j] = (float) as.maxscore;
-     * 
-     * if (max < distance[i][j]) { max = distance[i][j]; } } }
-     * 
-     * for (int i = 0; i < (noseqs - 1); i++) { for (int j = i; j < noseqs; j++)
-     * { distance[i][j] = max - distance[i][j]; distance[j][i] = distance[i][j];
-     * } } }/
-     */
+
   }
 
   /**
index 89c6353..979968f 100755 (executable)
@@ -70,6 +70,10 @@ public class PCA implements Runnable
    */
   public PCA(String[] s, boolean nucleotides)
   {
+    this(s, nucleotides, null);
+  }
+  public PCA(String[] s, boolean nucleotides, String s_m)
+  {
 
     BinarySequence[] bs = new BinarySequence[s.length];
     int ii = 0;
@@ -83,9 +87,17 @@ public class PCA implements Runnable
 
     BinarySequence[] bs2 = new BinarySequence[s.length];
     ii = 0;
-
-    String sm = nucleotides ? "DNA" : "BLOSUM62";
-    ScoreMatrix smtrx = ResidueProperties.getScoreMatrix(sm);
+    ScoreMatrix smtrx = null;
+    String sm=s_m;
+    if (sm!=null)
+    {
+      smtrx = ResidueProperties.getScoreMatrix(sm);
+    }
+    if (smtrx==null)
+    {
+      // either we were given a non-existent score matrix or a scoremodel that isn't based on a pairwise symbol score matrix
+      smtrx = ResidueProperties.getScoreMatrix(sm=(nucleotides ? "DNA" : "BLOSUM62"));
+    }
     details.append("PCA calculation using " + sm
             + " sequence similarity matrix\n========\n\n");
     while ((ii < s.length) && (s[ii] != null))
diff --git a/src/jalview/analysis/scoremodels/PIDScoreModel.java b/src/jalview/analysis/scoremodels/PIDScoreModel.java
new file mode 100644 (file)
index 0000000..2069b50
--- /dev/null
@@ -0,0 +1,55 @@
+package jalview.analysis.scoremodels;
+
+import jalview.api.analysis.ScoreModelI;
+import jalview.datamodel.AlignmentView;
+import jalview.util.Comparison;
+
+public class PIDScoreModel implements ScoreModelI
+{
+
+  @Override
+  public float[][] findDistances(AlignmentView seqData)
+  {
+    String[] sequenceString = seqData
+            .getSequenceStrings(Comparison.GapChars.charAt(0));
+    int noseqs = sequenceString.length;
+    float[][] distance = new float[noseqs][noseqs];
+    for (int i = 0; i < (noseqs - 1); i++)
+    {
+      for (int j = i; j < noseqs; j++)
+      {
+        if (j == i)
+        {
+          distance[i][i] = 0;
+        }
+        else
+        {
+          distance[i][j] = 100 - Comparison.PID(sequenceString[i],
+                  sequenceString[j]);
+
+          distance[j][i] = distance[i][j];
+        }
+      }
+    }
+    return distance;
+  }
+
+  @Override
+  public String getName()
+  {
+    return "PID";
+  }
+
+  @Override
+  public boolean isDNA()
+  {
+    return true;
+  }
+
+  @Override
+  public boolean isProtein()
+  {
+    return true;
+  }
+
+}
diff --git a/src/jalview/analysis/scoremodels/PairwiseSeqScoreModel.java b/src/jalview/analysis/scoremodels/PairwiseSeqScoreModel.java
new file mode 100644 (file)
index 0000000..78c5f17
--- /dev/null
@@ -0,0 +1,61 @@
+package jalview.analysis.scoremodels;
+
+import jalview.api.analysis.ScoreModelI;
+import jalview.datamodel.AlignmentView;
+import jalview.schemes.ScoreMatrix;
+import jalview.util.Comparison;
+
+public abstract class PairwiseSeqScoreModel implements ScoreModelI
+{
+  abstract public int getPairwiseScore(char c, char d);
+
+  public float[][] findDistances(AlignmentView seqData)
+  {
+    String[] sequenceString = seqData
+            .getSequenceStrings(Comparison.GapChars.charAt(0));
+    int noseqs = sequenceString.length;
+    float[][] distance = new float[noseqs][noseqs];
+
+    int maxscore = 0;
+    int end = sequenceString[0].length();
+    for (int i = 0; i < (noseqs - 1); i++)
+    {
+      for (int j = i; j < noseqs; j++)
+      {
+        int score = 0;
+
+        for (int k = 0; k < end; k++)
+        {
+          try
+          {
+            score += getPairwiseScore(sequenceString[i].charAt(k),
+                    sequenceString[j].charAt(k));
+          } catch (Exception ex)
+          {
+            System.err.println("err creating " + getName() + " tree");
+            ex.printStackTrace();
+          }
+        }
+
+        distance[i][j] = (float) score;
+
+        if (score > maxscore)
+        {
+          maxscore = score;
+        }
+      }
+    }
+
+    for (int i = 0; i < (noseqs - 1); i++)
+    {
+      for (int j = i; j < noseqs; j++)
+      {
+        distance[i][j] = (float) maxscore - distance[i][j];
+        distance[j][i] = distance[i][j];
+      }
+    }
+    return distance;
+  }
+
+  abstract public int[][] getMatrix();
+}
\ No newline at end of file
diff --git a/src/jalview/analysis/scoremodels/SWScoreModel.java b/src/jalview/analysis/scoremodels/SWScoreModel.java
new file mode 100644 (file)
index 0000000..d8c6230
--- /dev/null
@@ -0,0 +1,54 @@
+package jalview.analysis.scoremodels;
+
+import jalview.analysis.AlignSeq;
+import jalview.api.analysis.ScoreModelI;
+import jalview.datamodel.AlignmentView;
+import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
+
+public class SWScoreModel implements ScoreModelI
+{
+
+  @Override
+  public float[][] findDistances(AlignmentView seqData)
+  {
+    SequenceI[] sequenceString = seqData
+            .getVisibleAlignment(Comparison.GapChars.charAt(0)).getSequencesArray();
+    int noseqs = sequenceString.length;
+    float[][] distance = new float[noseqs][noseqs];
+    
+     float max = -1;
+      
+      for (int i = 0; i < (noseqs - 1); i++) { for (int j = i; j < noseqs; j++)
+      { AlignSeq as = new AlignSeq(sequenceString[i], sequenceString[j], seqData.isNa() ? "dna" : "pep");
+      as.calcScoreMatrix(); as.traceAlignment(); as.printAlignment(System.out);
+      distance[i][j] = (float) as.maxscore;
+      
+      if (max < distance[i][j]) { max = distance[i][j]; } } }
+     
+      for (int i = 0; i < (noseqs - 1); i++) { for (int j = i; j < noseqs; j++)
+      { distance[i][j] = max - distance[i][j]; distance[j][i] = distance[i][j];
+      } } 
+     
+    return distance;
+  }
+
+  @Override
+  public String getName()
+  {
+    return "Smith Waterman Score";
+  }
+  @Override
+  public boolean isDNA()
+  {
+    return true;
+  }
+  @Override
+  public boolean isProtein()
+  {
+    return true;
+  }
+  public String toString() {
+    return "Score between two sequences aligned with Smith Waterman with default Peptide/Nucleotide matrix";
+  }
+}
diff --git a/src/jalview/api/analysis/ScoreModelI.java b/src/jalview/api/analysis/ScoreModelI.java
new file mode 100644 (file)
index 0000000..0d56033
--- /dev/null
@@ -0,0 +1,16 @@
+package jalview.api.analysis;
+
+import jalview.datamodel.AlignmentView;
+
+public interface ScoreModelI
+{
+
+  float[][] findDistances(AlignmentView seqData);
+
+  String getName();
+
+  boolean isDNA();
+
+  boolean isProtein();
+
+}
index 6ea4b94..2e39b10 100644 (file)
@@ -3164,7 +3164,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     menu1.setLabel(MessageManager.getString("action.show"));
     showColumns.setLabel(MessageManager.getString("label.all_columns"));
     showSeqs.setLabel(MessageManager.getString("label.all_sequences"));
-    menu2.setLabel(MessageManager.getString("aciton.hide"));
+    menu2.setLabel(MessageManager.getString("action.hide"));
     hideColumns.setLabel(MessageManager.getString("label.selected_columns"));
     hideSequences.setLabel(MessageManager.getString("label.selected_sequences"));
     hideAllButSelection.setLabel(MessageManager.getString("label.all_but_selected_region"));
index ea0fbe0..273a685 100644 (file)
@@ -46,6 +46,16 @@ public class AlignmentView
    */
   private Vector scGroups;
 
+  private boolean isNa=false;
+  /**
+   * false if the view concerns peptides
+   * @return
+   */
+  public boolean isNa()
+  {
+    return isNa;
+  }
+
   /**
    * Group defined over SeqCigars. Unlike AlignmentI associated groups, each
    * SequenceGroup hold just the essential properties for the group, but no
@@ -99,6 +109,7 @@ public class AlignmentView
             (selectedRegionOnly ? selection : null)),
             (selectedRegionOnly && selection != null) ? selection
                     .getStartRes() : 0);
+    isNa = alignment.isNucleotide();
     // walk down SeqCigar array and Alignment Array - optionally restricted by
     // selected region.
     // test group membership for each sequence in each group, store membership
index 8dfb9fd..46c94c4 100644 (file)
@@ -543,22 +543,27 @@ public abstract class JalviewJmolBinding implements StructureListener,
             molsel.append(chainCd);
             molsel.append("}");
           }
-          selcom[pdbfnum] = molsel.toString();
-          selectioncom.append("((");
-          selectioncom.append(selcom[pdbfnum].substring(1,
-                  selcom[pdbfnum].length() - 1));
-          selectioncom.append(" )& ");
-          selectioncom.append(pdbfnum + 1);
-          selectioncom.append(".1)");
-          if (pdbfnum < files.length - 1)
+          if (molsel.length() > 1)
           {
-            selectioncom.append("|");
+            selcom[pdbfnum] = molsel.toString();
+            selectioncom.append("((");
+            selectioncom.append(selcom[pdbfnum].substring(1,
+                    selcom[pdbfnum].length() - 1));
+            selectioncom.append(" )& ");
+            selectioncom.append(pdbfnum + 1);
+            selectioncom.append(".1)");
+            if (pdbfnum < files.length - 1)
+            {
+              selectioncom.append("|");
+            }
+          } else {
+            selcom[pdbfnum] = null;
           }
         }
       }
       for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
       {
-        if (pdbfnum == refStructure)
+        if (pdbfnum == refStructure || selcom[pdbfnum]==null || selcom[refStructure]==null)
         {
           continue;
         }
@@ -582,13 +587,17 @@ public abstract class JalviewJmolBinding implements StructureListener,
         }
         command.append(" ROTATE TRANSLATE;\n");
       }
-      System.out.println("Select regions:\n" + selectioncom.toString());
-      evalStateCommand("select *; cartoons off; backbone; select ("
-              + selectioncom.toString() + "); cartoons; ");
-      // selcom.append("; ribbons; ");
-      System.out.println("Superimpose command(s):\n" + command.toString());
-
-      evalStateCommand(command.toString());
+      if (selectioncom.length() > 0)
+      {
+        System.out.println("Select regions:\n" + selectioncom.toString());
+        evalStateCommand("select *; cartoons off; backbone; select ("
+                + selectioncom.toString() + "); cartoons; ");
+        // selcom.append("; ribbons; ");
+        System.out
+                .println("Superimpose command(s):\n" + command.toString());
+
+        evalStateCommand(command.toString());
+      }
     }
     if (selectioncom.length() > 0)
     {// finally, mark all regions that were superposed.
index d11bd31..da34013 100644 (file)
@@ -20,6 +20,7 @@ package jalview.gui;
 
 import jalview.analysis.AAFrequency;
 import jalview.analysis.AlignmentSorter;
+import jalview.analysis.AlignmentUtils;
 import jalview.analysis.Conservation;
 import jalview.analysis.CrossRef;
 import jalview.analysis.NJTree;
@@ -27,6 +28,7 @@ import jalview.analysis.ParseProperties;
 import jalview.analysis.SequenceIdMatcher;
 import jalview.api.AlignViewControllerGuiI;
 import jalview.api.AlignViewControllerI;
+import jalview.api.analysis.ScoreModelI;
 import jalview.bin.Cache;
 import jalview.commands.CommandI;
 import jalview.commands.EditCommand;
@@ -85,7 +87,6 @@ import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.seqfetcher.DbSourceProxy;
 
 import java.awt.BorderLayout;
-import java.awt.Color;
 import java.awt.Component;
 import java.awt.GridLayout;
 import java.awt.Rectangle;
@@ -117,6 +118,7 @@ import java.util.List;
 import java.util.Vector;
 
 import javax.swing.JButton;
+import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JEditorPane;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
@@ -327,6 +329,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     setMenusFromViewport(viewport);
     buildSortByAnnotationScoresMenu();
+    buildTreeMenu();
     if (viewport.wrapAlignment)
     {
       wrapMenuItem_actionPerformed(null);
@@ -2060,7 +2063,59 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
   }
+  @Override
+  protected void expand_newalign(ActionEvent e)
+  {
+    try {
+    AlignmentI alignment = AlignmentUtils.expandContext(getViewport().getAlignment(), -1);
+    AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
+            DEFAULT_HEIGHT);
+    String newtitle = new String("Flanking alignment");
 
+    if (Desktop.jalviewClipboard != null
+            && Desktop.jalviewClipboard[2] != null)
+    {
+      Vector hc = (Vector) Desktop.jalviewClipboard[2];
+      for (int i = 0; i < hc.size(); i++)
+      {
+        int[] region = (int[]) hc.elementAt(i);
+        af.viewport.hideColumns(region[0], region[1]);
+      }
+    }
+
+    // >>>This is a fix for the moment, until a better solution is
+    // found!!<<<
+    af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
+            .transferSettings(
+                    alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
+
+    // TODO: maintain provenance of an alignment, rather than just make the
+    // title a concatenation of operations.
+    {
+      if (title.startsWith("Copied sequences"))
+      {
+        newtitle = title;
+      }
+      else
+      {
+        newtitle = newtitle.concat("- from " + title);
+      }
+    }
+
+    Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
+            DEFAULT_HEIGHT);
+
+    } catch (Exception ex)
+    {
+      ex.printStackTrace();
+      System.out.println("Exception whilst pasting: " + ex);
+      // could be anything being pasted in here
+    }
+    catch (OutOfMemoryError oom)
+    {
+      new OOMWarning("Viewing flanking region of alignment", oom);
+    }
+  }
   /**
    * DOCUMENT ME!
    * 
@@ -3888,6 +3943,35 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void buildTreeMenu()
   {
+    calculateTree.removeAll();
+    // build the calculate menu
+    
+    for (final String type:new String[] {"NJ", "AV"})
+    {
+      String treecalcnm = MessageManager.getString("label.tree_calc_"+type.toLowerCase());
+      for (final Object pwtype: ResidueProperties.scoreMatrices.keySet())
+      {
+        JMenuItem tm = new JMenuItem();
+        ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
+        if (sm.isProtein()==!viewport.getAlignment().isNucleotide())
+        {
+          String smn = MessageManager.getStringOrReturn(
+                  "label.score_model_", sm.getName());
+          final String title = MessageManager.formatMessage(
+                  "label.treecalc_title", treecalcnm, smn);
+          tm.setText(title);//
+          tm.addActionListener(new java.awt.event.ActionListener()
+          {
+            public void actionPerformed(ActionEvent e)
+            {
+              NewTreePanel(type, (String) pwtype, title);
+            }
+          });
+          calculateTree.add(tm);
+        }
+
+      }
+    }
     sortByTreeMenu.removeAll();
 
     Vector comps = (Vector) PaintRefresher.components.get(viewport
@@ -5122,6 +5206,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     rfetch.setToolTipText(MessageManager.getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));\r
     webService.add(rfetch);
 
+    final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(MessageManager.getString("option.trim_retrieved_seqs"));
+    trimrs.setToolTipText(MessageManager.getString("label.trim_retrieved_sequences"));
+    trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
+    trimrs.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e) {
+      trimrs.setSelected(trimrs.isSelected());
+      Cache.setProperty("TRIM_FETCHED_DATASET_SEQS", Boolean.valueOf(trimrs.isSelected()).toString());
+    };
+    });
+    rfetch.add(trimrs);
     JMenuItem fetchr = new JMenuItem(MessageManager.getString("label.standard_databases"));\r
     fetchr.setToolTipText(MessageManager.getString("label.fetch_embl_uniprot"));\r
     fetchr.addActionListener(new ActionListener()
index cc37b66..81b88ac 100644 (file)
@@ -829,7 +829,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
 
       // need to wait around until script has finished
       while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled()
-              : (jmb.isFinishedInit() && jmb.getPdbFile().length != jmb.pdbentry.length))
+              : (jmb.isFinishedInit() && jmb.getPdbFile()!=null && jmb.getPdbFile().length != jmb.pdbentry.length))
       {
         try
         {
index d7f05dc..9e0925b 100644 (file)
@@ -1158,13 +1158,13 @@ public class FeatureSettings extends JPanel
   private String[] getDisplayedFeatureGroups()
   {
     String[] gps = null;
+    ArrayList<String> _gps = new ArrayList<String>();
     if (fr != null)
     {
 
       if (fr.featureGroups != null)
       {
         Iterator en = fr.featureGroups.keySet().iterator();
-        gps = new String[fr.featureColours.size()];
         int g = 0;
         boolean valid = false;
         while (en.hasNext())
@@ -1174,16 +1174,15 @@ public class FeatureSettings extends JPanel
           if (on != null && on.booleanValue())
           {
             valid = true;
-            gps[g++] = gp;
+            _gps.add(gp);
           }
         }
-        while (g < gps.length)
-        {
-          gps[g++] = null;
-        }
         if (!valid)
         {
           return null;
+        } else {
+          gps = new String[_gps.size()];
+          _gps.toArray(gps);
         }
       }
     }
index 28ac886..ce42174 100644 (file)
@@ -3737,6 +3737,20 @@ public class Jalview2XML
         if (sq != dsq)
         { // make this dataset sequence sq's dataset sequence
           sq.setDatasetSequence(dsq);
+          // and update the current dataset alignment
+          if (ds==null) {
+            if (dseqs!=null) {
+              if (!dseqs.contains(dsq))
+              {
+                dseqs.add(dsq);
+              }
+            } else {
+              if (ds.findIndex(dsq)<0)
+              {
+                ds.addSequence(dsq);
+              }
+            }
+          }
         }
       }
     }
@@ -3763,11 +3777,11 @@ public class Jalview2XML
            * sb.append(newres.substring(newres.length() - sq.getEnd() -
            * dsq.getEnd())); dsq.setEnd(sq.getEnd()); }
            */
-          dsq.setSequence(sb.toString());
+          dsq.setSequence(newres);
         }
         // TODO: merges will never happen if we 'know' we have the real dataset
         // sequence - this should be detected when id==dssid
-        System.err.println("DEBUG Notice:  Merged dataset sequence"); // ("
+        System.err.println("DEBUG Notice:  Merged dataset sequence (if you see this often, post at http://issues.jalview.org/browse/JAL-1474)"); // ("
         // + (pre ? "prepended" : "") + " "
         // + (post ? "appended" : ""));
       }
index 5c8d08b..ccc4697 100644 (file)
 package jalview.gui;
 
 import java.util.*;
-
 import java.awt.*;
 import java.awt.event.*;
 import java.awt.print.*;
+
 import javax.swing.*;
 
 import jalview.datamodel.*;
 import jalview.jbgui.*;
+import jalview.schemes.ResidueProperties;
 import jalview.util.MessageManager;
 import jalview.viewmodel.PCAModel;
 
@@ -109,7 +110,35 @@ public class PCAPanel extends GPCAPanel implements Runnable,
     Thread worker = new Thread(this);
     worker.start();
   }
-
+  @Override
+  protected void scoreMatrix_menuSelected()
+  {
+    scoreMatrixMenu.removeAll();
+    for (final String sm:ResidueProperties.scoreMatrices.keySet())
+    {
+      JCheckBoxMenuItem jm=new JCheckBoxMenuItem();
+      jm.setText(MessageManager.getStringOrReturn("label.score_model", sm));
+      jm.setSelected(pcaModel.getScore_matrix().equals(sm));
+      if (pcaModel.isNucleotide()==ResidueProperties.scoreMatrices.get(sm).isDNA())
+      {
+        final PCAPanel us = this;
+        jm.addActionListener(new ActionListener()
+        {
+          @Override
+          public void actionPerformed(ActionEvent e)
+          {
+            if (!pcaModel.getScore_matrix().equals((String) sm))
+            {
+              pcaModel.setScore_matrix((String) sm);
+              Thread worker = new Thread(us);
+              worker.start();
+            }
+          }
+        });
+        scoreMatrixMenu.add(jm);
+      }
+    }
+  }
   public void bgcolour_actionPerformed(ActionEvent e)
   {
     Color col = JColorChooser.showDialog(this, "Select Background Colour",
@@ -176,6 +205,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
     if (!pcaModel.isNucleotide())
     {
       pcaModel.setNucleotide(true);
+      pcaModel.setScore_matrix("DNA");
       Thread worker = new Thread(this);
       worker.start();
     }
@@ -189,6 +219,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
     if (pcaModel.isNucleotide())
     {
       pcaModel.setNucleotide(false);
+      pcaModel.setScore_matrix("BLOSUM62");
       Thread worker = new Thread(this);
       worker.start();
     }
@@ -446,6 +477,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
     }
   }
 
+  
   public void viewMenu_menuSelected()
   {
     buildAssociatedViewMenu();
index fb4e237..7d953d4 100644 (file)
@@ -493,7 +493,7 @@ public class PopupMenu extends JPopupMenu
         buildGroupURLMenu(sg, groupLinks);
       }
       // Add a 'show all structures' for the current selection
-      Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>();
+      Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>(),reppdb=new Hashtable<String,PDBEntry>();
       SequenceI sqass = null;
       for (SequenceI sq : ap.av.getSequenceSelection())
       {
@@ -501,6 +501,7 @@ public class PopupMenu extends JPopupMenu
                 .getPDBId();
         if (pes != null)
         {
+          reppdb.put(pes.get(0).getId(),pes.get(0));
           for (PDBEntry pe : pes)
           {
             pdbe.put(pe.getId(), pe);
@@ -514,15 +515,16 @@ public class PopupMenu extends JPopupMenu
       if (pdbe.size() > 0)
       {
         final PDBEntry[] pe = pdbe.values().toArray(
-                new PDBEntry[pdbe.size()]);
-        final JMenuItem gpdbview;
+                new PDBEntry[pdbe.size()]),pr = reppdb.values().toArray(
+                        new PDBEntry[reppdb.size()]);
+        final JMenuItem gpdbview,rpdbview;
         if (pdbe.size() == 1)
         {
           structureMenu.add(gpdbview = new JMenuItem(MessageManager.formatMessage("label.view_structure_for", new String[]{sqass.getDisplayId(false)})));\r
         }
         else
         {
-          structureMenu.add(gpdbview = new JMenuItem(MessageManager.formatMessage("label.view_all_structures", new String[]{new Integer(pdbe.size()).toString()})));\r
+          structureMenu.add(gpdbview = new JMenuItem(MessageManager.formatMessage("label.view_all_structures", new String[]{new Integer(pdbe.size()).toString()})));          \r
         }
         gpdbview.setToolTipText(MessageManager.getString("label.open_new_jmol_view_with_all_structures_associated_current_selection_superimpose_using_alignment"));\r
         gpdbview.addActionListener(new ActionListener()
@@ -534,6 +536,20 @@ public class PopupMenu extends JPopupMenu
             new AppJmol(ap, pe, ap.av.collateForPDB(pe));
           }
         });
+        if (reppdb.size()>1 && reppdb.size()<pdbe.size())
+        {
+          structureMenu.add(rpdbview = new JMenuItem(MessageManager.formatMessage("label.view_all_representative_structures", new String[]{new Integer(reppdb.size()).toString()})));
+          rpdbview.setToolTipText(MessageManager.getString("label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment"));
+          rpdbview.addActionListener(new ActionListener()
+          {
+
+            @Override
+            public void actionPerformed(ActionEvent e)
+            {
+              new AppJmol(ap, pr, ap.av.collateForPDB(pr));
+            }
+          });
+        }
       }
     }
     else
index 6f24361..5979a27 100755 (executable)
@@ -791,6 +791,7 @@ public class AnnotationFile
         else if (token.equalsIgnoreCase("SEQUENCE_GROUP"))
         {
           addGroup(al, st);
+          modified=true;
           continue;
         }
 
index d95e1b1..085b580 100755 (executable)
@@ -244,6 +244,8 @@ public class GAlignFrame extends JInternalFrame
   protected JMenuItem showTranslation = new JMenuItem();
 
   protected JMenuItem extractScores = new JMenuItem();
+  
+  protected JMenuItem expandAlignment = new JMenuItem();
 
   protected JMenu showProducts = new JMenu();
 
@@ -637,7 +639,15 @@ public class GAlignFrame extends JInternalFrame
         makeGrpsFromSelection_actionPerformed(e);
       }
     });
-
+    expandAlignment.setText(MessageManager.getString("action.view_flanking_regions"));
+    expandAlignment.setToolTipText(MessageManager.getString("label.view_flanking_regions"));
+    expandAlignment.addActionListener(new java.awt.event.ActionListener() {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        expand_newalign(e);
+      }
+    });
     remove2LeftMenuItem.setText(MessageManager.getString("action.remove_left"));
     remove2LeftMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_L, Toolkit.getDefaultToolkit()
@@ -1947,10 +1957,6 @@ public class GAlignFrame extends JInternalFrame
     sort.add(sortGroupMenuItem);
     sort.add(sortPairwiseMenuItem);
     sort.add(sortByTreeMenu);
-    calculateTree.add(averageDistanceTreeMenuItem);
-    calculateTree.add(neighbourTreeMenuItem);
-    calculateTree.add(avDistanceTreeBlosumMenuItem);
-    calculateTree.add(njTreeBlosumMenuItem);
     jMenu2.add(htmlMenuItem);
     jMenu2.add(epsFile);
     jMenu2.add(createPNG);
@@ -1993,6 +1999,7 @@ public class GAlignFrame extends JInternalFrame
     selectMenu.add(unGroup);
     selectMenu.add(grpsFromSelection);
     selectMenu.add(deleteGroups);
+    calculateMenu.add(expandAlignment);
     // TODO - determine if the listenToViewSelections button is needed : see bug
     // JAL-574
     // selectMenu.addSeparator();
@@ -2638,4 +2645,10 @@ public class GAlignFrame extends JInternalFrame
   {
 
   }
+
+  protected void expand_newalign(ActionEvent e)
+  {
+    // TODO Auto-generated method stub
+    
+  }
 }
index f2b8fe3..266bfc6 100755 (executable)
@@ -53,6 +53,8 @@ public class GPCAPanel extends JInternalFrame
   JMenu fileMenu = new JMenu();
 
   JMenu saveMenu = new JMenu();
+  
+  protected JMenu scoreMatrixMenu = new JMenu();
 
   JMenuItem eps = new JMenuItem();
 
@@ -221,6 +223,22 @@ public class GPCAPanel extends JInternalFrame
       {
       }
     });
+    scoreMatrixMenu.setText(MessageManager.getString("label.select_score_model"));
+    scoreMatrixMenu.addMenuListener(new MenuListener()
+    {
+      public void menuSelected(MenuEvent e)
+      {
+        scoreMatrix_menuSelected();
+      }
+
+      public void menuDeselected(MenuEvent e)
+      {
+      }
+
+      public void menuCanceled(MenuEvent e)
+      {
+      }
+    });
     showLabels.setText(MessageManager.getString("label.show_labels"));
     showLabels.addActionListener(new ActionListener()
     {
@@ -280,6 +298,7 @@ public class GPCAPanel extends JInternalFrame
     calcSettings.add(jvVersionSetting);
     calcSettings.add(nuclSetting);
     calcSettings.add(protSetting);
+    calcSettings.add(scoreMatrixMenu);
     statusPanel.setLayout(statusPanelLayout);
     statusBar.setFont(new java.awt.Font("Verdana", 0, 12));
     // statusPanel.setBackground(Color.lightGray);
@@ -312,6 +331,12 @@ public class GPCAPanel extends JInternalFrame
     viewMenu.add(associateViewsMenu);
   }
 
+  protected void scoreMatrix_menuSelected()
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
   protected void resetButton_actionPerformed(ActionEvent e)
   {
     // TODO Auto-generated method stub
index 8ca4420..1b23d13 100755 (executable)
@@ -207,7 +207,7 @@ public class AnnotationColourGradient extends ResidueColourScheme
     }
     if ((threshold == 0) || aboveThreshold(c, j))
     {
-      if (j < annotation.annotations.length
+      if (annotation.annotations!=null && j < annotation.annotations.length
               && annotation.annotations[j] != null
               && !jalview.util.Comparison.isGap(c))
       {
index 1bc5a67..aecce4b 100755 (executable)
  */
 package jalview.schemes;
 
+import jalview.analysis.scoremodels.PIDScoreModel;
+import jalview.api.analysis.ScoreModelI;
+
 import java.util.*;
 import java.util.List;
-
 import java.awt.*;
 
 public class ResidueProperties
 {
-  public static Hashtable scoreMatrices = new Hashtable();
+  public static Hashtable<String,ScoreModelI> scoreMatrices = new Hashtable();
 
   // Stores residue codes/names and colours and other things
   public static final int[] aaIndex; // aaHash version 2.1.1 and below
@@ -1416,6 +1418,45 @@ public class ResidueProperties
     propHash.put("proline", proline);
     propHash.put("polar", polar);
   }
+  static
+  {
+    int[][][] propMatrix = new int[3][maxProteinIndex][maxProteinIndex];
+    for (int i=0;i<maxProteinIndex;i++)
+    {
+      String ic="";
+      if (aa.length<i) {
+        ic+=aa[i];
+      }
+      else {ic = "-";}
+      propMatrix[0][i][i]=propHash.size();
+      propMatrix[1][i][i]=propHash.size();
+      propMatrix[2][i][i]=propHash.size();
+      for (int j=i+1;j<maxProteinIndex; j++)
+      {
+        String jc="";
+        if (aa.length<j) {
+          jc+=aa[j];
+        }
+        else {jc = "-";}
+        propMatrix[0][i][j]=0;
+        propMatrix[1][i][j]=0;
+        propMatrix[2][i][j]=0;
+        for (Enumeration<String> en= (Enumeration<String>)propHash.keys(); en.hasMoreElements(); )
+        {
+          String ph = en.nextElement();
+          Map<String,Integer> pph=(Map<String,Integer>)propHash.get(ph);
+          propMatrix[0][i][j]+= pph.get(ic).equals(pph.get(jc)) ? pph.get(ic) : -1;
+          propMatrix[1][i][j]+= pph.get(ic).equals(pph.get(jc)) ? 1 : -1;
+          propMatrix[2][i][j]+= pph.get(ic).equals(pph.get(jc)) ? pph.get(ic)*2 : 0;
+        }
+      }
+    }
+    
+    scoreMatrices.put("Conservation Pos", new ScoreMatrix("Conservation Pos",propMatrix[0],0));
+    scoreMatrices.put("Conservation Both", new ScoreMatrix("Conservation Both",propMatrix[1],0));
+    scoreMatrices.put("Conservation EnhPos", new ScoreMatrix("Conservation EnhPos",propMatrix[2],0));
+    scoreMatrices.put("PID", new PIDScoreModel());
+  }
 
   private ResidueProperties()
   {
@@ -1540,12 +1581,22 @@ public class ResidueProperties
   public static ScoreMatrix getScoreMatrix(String pwtype)
   {
     Object val = scoreMatrices.get(pwtype);
-    if (val != null)
+    if (val != null && val instanceof ScoreMatrix)
     {
       return (ScoreMatrix) val;
     }
     return null;
   }
+  /**
+   * get a ScoreModel based on its string name
+   * 
+   * @param pwtype
+   * @return scoremodel of type pwtype or null
+   */
+  public static ScoreModelI getScoreModel(String pwtype)
+  {
+    return scoreMatrices.get(pwtype);
+  }
 
   public static int getPAM250(char c, char d)
   {
index e78b92c..ab603e1 100644 (file)
  */
 package jalview.schemes;
 
-public class ScoreMatrix
+import jalview.analysis.scoremodels.PairwiseSeqScoreModel;
+import jalview.api.analysis.ScoreModelI;
+
+public class ScoreMatrix extends PairwiseSeqScoreModel implements ScoreModelI
 {
   String name;
+  
+  @Override
+  public String getName()
+  {
+    return name;
+  }
 
   /**
    * reference to integer score matrix
@@ -31,23 +40,31 @@ public class ScoreMatrix
    * 0 for Protein Score matrix. 1 for dna score matrix
    */
   int type;
-
+  /**
+   * 
+   * @param name Unique, human readable name for the matrix
+   * @param matrix Pairwise scores indexed according to appropriate symbol alphabet
+   * @param type 0 for Protein, 1 for NA
+   */
   ScoreMatrix(String name, int[][] matrix, int type)
   {
     this.matrix = matrix;
     this.type = type;
+    this.name = name;
   }
 
+  @Override
   public boolean isDNA()
   {
     return type == 1;
   }
-
+  @Override
   public boolean isProtein()
   {
     return type == 0;
   }
 
+  @Override
   public int[][] getMatrix()
   {
     return matrix;
index 5f7f0e2..0ba7566 100644 (file)
@@ -64,4 +64,25 @@ public class MessageManager {
        public static String formatMessage(String key, Object... params){
                return MessageFormat.format(rb.getString(key), (Object[]) params);
        }
+
+  /**
+   * lookup and return a key given a root and a human-readable(ish) name that when combined might resolve to an i18n string.
+   * If the key doesn't resolve, then name is returned.if the key doesn't exist.
+   * Use this for programatically constructed keys that have have a human readable alternative used in the program (e.g. BLOSUM62 and label.score_blosum62) 
+   * @param keyroot
+   * @param name
+   * @return
+   */
+  public static String getStringOrReturn(String keyroot, String name)
+  {
+    String smkey = keyroot
+            + name.toLowerCase().replaceAll(" ", "");
+    try {
+      name = rb.getString(smkey); 
+    }
+    catch (Exception x) {
+      log.finest("I18N missing key with root "+keyroot+": "+loc+"\t"+smkey);
+    }
+    return name;
+  }
 }
index 07ec95e..d49572d 100644 (file)
@@ -1505,8 +1505,7 @@ public abstract class AlignmentViewport implements AlignViewportI
         if (aan[an].autoCalculated && aan[an].groupRef != null)
         {
           oldrfs.add(aan[an].groupRef);
-          alignment.deleteAnnotation(aan[an]);
-          aan[an] = null;
+          alignment.deleteAnnotation(aan[an],false);
         }
       }
     }
index bb1519d..00cc94b 100644 (file)
@@ -35,6 +35,7 @@ public class PCAModel
     seqstrings = seqstrings2;
     seqs = seqs2;
     nucleotide = nucleotide2;
+    score_matrix = nucleotide2 ? "PID" : "BLOSUM62";
   }
 
   private volatile PCA pca;
@@ -44,6 +45,11 @@ public class PCAModel
   AlignmentView seqstrings;
 
   SequenceI[] seqs;
+  
+  /**
+   * Score matrix used to calculate PC
+   */
+  String score_matrix;
 
   /**
    * use the identity matrix for calculating similarity between sequences.
@@ -62,7 +68,7 @@ public class PCAModel
   public void run()
   {
 
-    pca = new PCA(seqstrings.getSequenceStrings(' '), nucleotide);
+    pca = new PCA(seqstrings.getSequenceStrings(' '), nucleotide, score_matrix);
     pca.setJvCalcMode(jvCalcMode);
     pca.run();
 
@@ -224,4 +230,14 @@ public class PCAModel
     jvCalcMode = state;
   }
 
+  public String getScore_matrix()
+  {
+    return score_matrix;
+  }
+
+  public void setScore_matrix(String score_matrix)
+  {
+    this.score_matrix = score_matrix;
+  }
+  
 }
index 9742bca..84eba02 100644 (file)
@@ -78,6 +78,11 @@ public class DBRefFetcher implements Runnable
 
   private SequenceI[] alseqs;
 
+  /**
+   * when true - retrieved sequences will be trimmed to cover longest derived alignment sequence 
+   */
+  private boolean trimDsSeqs=true;
+
   public DBRefFetcher()
   {
   }
@@ -124,6 +129,8 @@ public class DBRefFetcher implements Runnable
     this.dataset = ds;
     // TODO Jalview 2.5 lots of this code should be in the gui package!
     sfetcher = jalview.gui.SequenceFetcher.getSequenceFetcherSingleton(af);
+    // set default behaviour for transferring excess sequence data to the dataset 
+    trimDsSeqs = Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true);
     if (sources == null)
     {
       // af.featureSettings_actionPerformed(null);
@@ -372,7 +379,7 @@ public class DBRefFetcher implements Runnable
             if (retrieved != null)
             {
               transferReferences(sdataset, dbsource.getDbSource(),
-                      retrieved);
+                      retrieved,trimDsSeqs);
             }
           }
           else
@@ -469,12 +476,14 @@ public class DBRefFetcher implements Runnable
   /**
    * Verify local sequences in seqRefs against the retrieved sequence database
    * records.
+   * @param trimDatasetSeqs 
    * 
    */
   void transferReferences(Vector sdataset, String dbSource,
-          AlignmentI retrievedAl) // File
+          AlignmentI retrievedAl, boolean trimDatasetSeqs) // File
   // file)
   {
+    System.out.println("trimming ? "+trimDatasetSeqs);
     if (retrievedAl == null || retrievedAl.getHeight() == 0)
     {
       return;
@@ -568,6 +577,7 @@ public class DBRefFetcher implements Runnable
         // mappings are made (but content matches retrieved set)
         boolean updateRefFrame = sequence.getDBRef() == null
                 || sequence.getDBRef().length == 0;
+        // TODO:
         // verify sequence against the entry sequence
 
         String nonGapped = AlignSeq.extractGaps("-. ",
@@ -648,11 +658,19 @@ public class DBRefFetcher implements Runnable
         // unknownSequences.remove(sequence);
         int absEnd = absStart + nonGapped.length();
         absStart += 1;
+        if (!trimDatasetSeqs) {
+          // insert full length sequence from record
+          sequence.setSequence(entry.getSequenceAsString());
+          sequence.setStart(entry.getStart());
+        }
         if (updateRefFrame)
         {
           // finally, update local sequence reference frame if we're allowed
-          sequence.setStart(absStart);
-          sequence.setEnd(absEnd);
+          if (trimDatasetSeqs) {
+            // just fix start/end
+            sequence.setStart(absStart);
+            sequence.setEnd(absEnd);
+          }
           // search for alignment sequences to update coordinate frame for
           for (int alsq = 0; alsq < alseqs.length; alsq++)
           {
index 630c974..49a904c 100644 (file)
@@ -47,6 +47,7 @@ public class AADisorderClient extends JabawsCalcWorker implements
 {
 
   private static final String THRESHOLD = "THRESHOLD";
+  private static final String RANGE = "RANGE";
 
   String typeName;
 
@@ -118,6 +119,9 @@ public class AADisorderClient extends JabawsCalcWorker implements
     amap.get("Dydx").put(DONTCOMBINE, DONTCOMBINE);
     amap.get("Dydx").put(THRESHOLD, new double[]
     { 1, 0 });
+    amap.get("Dydx").put(RANGE, new float[]
+            { -1, +1 });
+
     amap.put("SmoothedScore", new HashMap<String, Object>());
     amap.get("SmoothedScore").put(INVISIBLE, INVISIBLE);
     amap.put("RawScore", new HashMap<String, Object>());
@@ -129,10 +133,18 @@ public class AADisorderClient extends JabawsCalcWorker implements
     amap.put("REM465", new HashMap<String, Object>());
     amap.get("COILS").put(THRESHOLD, new double[]
     { 1, 0.516 });
+    amap.get("COILS").put(RANGE, new float[]
+            { 0, 1 });
+
     amap.get("HOTLOOPS").put(THRESHOLD, new double[]
     { 1, 0.6 });
+    amap.get("HOTLOOPS").put(RANGE, new float[]
+            { 0, 1 });
     amap.get("REM465").put(THRESHOLD, new double[]
     { 1, 0.1204 });
+    amap.get("REM465").put(RANGE, new float[]
+            { 0, 1 });
+
 
     annotMap.put(compbio.ws.client.Services.IUPredWS.toString(),
             amap = new HashMap<String, Map<String, Object>>());
@@ -140,13 +152,19 @@ public class AADisorderClient extends JabawsCalcWorker implements
     amap.put("Short", new HashMap<String, Object>());
     amap.get("Long").put(THRESHOLD, new double[]
     { 1, 0.5 });
+    amap.get("Long").put(RANGE, new float[]
+            { 0, 1 });
     amap.get("Short").put(THRESHOLD, new double[]
     { 1, 0.5 });
+    amap.get("Short").put(RANGE, new float[]
+            { 0, 1 });
     annotMap.put(compbio.ws.client.Services.JronnWS.toString(),
             amap = new HashMap<String, Map<String, Object>>());
     amap.put("JRonn", new HashMap<String, Object>());
     amap.get("JRonn").put(THRESHOLD, new double[]
     { 1, 0.5 });
+    amap.get("JRonn").put(RANGE, new float[]
+            { 0, 1 });
   }
 
   @Override
@@ -244,16 +262,21 @@ public class AADisorderClient extends JabawsCalcWorker implements
                       service.getServiceTypeURI() + "/" + scr.getMethod(),
                       aseq, base + 1, scr);
               annot.graph = AlignmentAnnotation.LINE_GRAPH;
-              annot.visible = (annotTypeMap == null
-                      || annotTypeMap.get(scr.getMethod()) == null || annotTypeMap
-                      .get(scr.getMethod()).get(INVISIBLE) == null);
-              double[] thrsh = (annotTypeMap == null || annotTypeMap
-                      .get(scr.getMethod()) == null) ? null
-                      : (double[]) annotTypeMap.get(scr.getMethod()).get(
+              
+              Map<String,Object> styleMap = (annotTypeMap == null) ? null : annotTypeMap.get(scr.getMethod());
+              
+              annot.visible = (styleMap == null || styleMap.get(INVISIBLE) == null);
+              double[] thrsh = (styleMap==null) ? null
+                      : (double[]) styleMap.get(
                               THRESHOLD);
-              if (annotTypeMap == null
-                      || annotTypeMap.get(scr.getMethod()) == null
-                      || annotTypeMap.get(scr.getMethod()).get(DONTCOMBINE) == null)
+              float[] range = (styleMap==null) ? null : (float[]) styleMap.get(
+                      RANGE);
+              if (range!=null)
+              {
+                annot.graphMin = range[0];
+                annot.graphMax = range[1];
+              }
+              if (styleMap==null || styleMap.get(DONTCOMBINE) == null)
               {
                 {
                   if (!sameGroup)
diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java
new file mode 100644 (file)
index 0000000..2104d4a
--- /dev/null
@@ -0,0 +1,40 @@
+package jalview.analysis;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.io.AppletFormatAdapter;
+
+public class AlignmentUtilsTests 
+{
+  public static Sequence ts=new Sequence("short","ASDASDASDASDASDASDASDASDASDASDASDASDASD");
+  @Test
+  public void testExpandFlanks()
+  {
+    AlignmentI al = new Alignment(new Sequence[] {});
+    for (int i=4;i<14;i+=3)
+    {
+      SequenceI s1=ts.deriveSequence().getSubSequence(i, i+7);
+      al.addSequence(s1);
+    }
+    System.out.println(new AppletFormatAdapter().formatSequences("Clustal", al, true));
+    for (int flnk=-1;flnk<25; flnk++)
+    {
+      AlignmentI exp;
+      System.out.println("\nFlank size: "+flnk);
+      System.out.println(new AppletFormatAdapter().formatSequences("Clustal", exp=AlignmentUtils.expandContext(al, flnk), true));
+      if (flnk==-1) {
+        for (SequenceI sq:exp.getSequences())
+      {
+          String ung = sq.getSequenceAsString().replaceAll("-+", "");
+          assertTrue("Flanking sequence not the same as original dataset sequence.\n"+ung+"\n"+sq.getDatasetSequence().getSequenceAsString(),ung.equalsIgnoreCase(sq.getDatasetSequence().getSequenceAsString()));
+      }
+      }
+    }    
+  }
+}
index cfbc884..7d6a15f 100644 (file)
@@ -30,9 +30,19 @@ import org.junit.Test;
 public class AnnotationFileIOTest
 {
 
-  static String TestFiles[][] = {{ "Test example annotation import/export","examples/uniref50.fa", "examples/testdata/example_annot_file.jva" }
-          ,{"Test multiple combine annotation statements import/export","examples/uniref50.fa", "examples/testdata/test_combine_annot.jva"}
-          ,{"Test multiple combine annotation statements with sequence_ref import/export","examples/uniref50.fa", "examples/testdata/uniref50_iupred.jva"}};
+  static String TestFiles[][] =
+  {
+      { "Test example annotation import/export", "examples/uniref50.fa",
+          "examples/testdata/example_annot_file.jva" },
+      { "Test multiple combine annotation statements import/export",
+          "examples/uniref50.fa",
+          "examples/testdata/test_combine_annot.jva" },
+      {
+          "Test multiple combine annotation statements with sequence_ref import/export",
+          "examples/uniref50.fa", "examples/testdata/uniref50_iupred.jva" },
+      {
+          "Test group only annotation file parsing results in parser indicating annotation was parsed",
+          "examples/uniref50.fa", "examples/testdata/test_grpannot.jva" } };
 
   @Test
   public void exampleAnnotationFileIO() throws Exception
index a472951..2830918 100644 (file)
@@ -18,6 +18,8 @@
  */
 package jalview.schemes;
 
+import jalview.api.analysis.ScoreModelI;
+
 import java.util.Map;
 
 import org.junit.Test;
@@ -28,7 +30,7 @@ public class ScoreMatrixPrinter
   @Test
   public void printAllMatrices()
   {
-    for (Map.Entry<String,ScoreMatrix> sm:((Map<String, ScoreMatrix>) ResidueProperties.scoreMatrices).entrySet())
+    for (Map.Entry<String,ScoreModelI> sm: ResidueProperties.scoreMatrices.entrySet())
     {
       System.out.println("Matrix "+sm.getKey());
       System.out.println(sm.getValue().toString());
@@ -37,10 +39,14 @@ public class ScoreMatrixPrinter
   @Test
   public void printHTMLMatrices()
   {
-    for (Map.Entry<String,ScoreMatrix> sm:((Map<String, ScoreMatrix>) ResidueProperties.scoreMatrices).entrySet())
+    for (Map.Entry<String,ScoreModelI> _sm: ResidueProperties.scoreMatrices.entrySet())
     {
-      System.out.println("Matrix "+sm.getKey());
-      System.out.println(sm.getValue().outputMatrix(true));
+      if (_sm.getValue() instanceof ScoreMatrix)
+      {
+        ScoreMatrix sm = (ScoreMatrix) _sm.getValue();
+        System.out.println("Matrix "+_sm.getKey());
+        System.out.println(sm.outputMatrix(true));
+      }
     }
   }