Merge branch 'features/JAL-3417_sdppred_calcs' into features/r2_11_2_JAL-3417_sdppred
authorJim Procter <j.procter@dundee.ac.uk>
Wed, 23 Feb 2022 12:47:31 +0000 (12:47 +0000)
committerJim Procter <j.procter@dundee.ac.uk>
Wed, 23 Feb 2022 12:47:31 +0000 (12:47 +0000)
examples/groovy/sdppred_testing.groovy [new file with mode: 0644]
src/jalview/analysis/SeqsetUtils.java
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentI.java
src/jalview/datamodel/SequenceCollectionI.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/viewmodel/AlignmentViewport.java
src/jalview/workers/AnnotationWorker.java

diff --git a/examples/groovy/sdppred_testing.groovy b/examples/groovy/sdppred_testing.groovy
new file mode 100644 (file)
index 0000000..64199cc
--- /dev/null
@@ -0,0 +1,70 @@
+
+import jalview.bin.Jalview
+import jalview.io.gff.GffConstants;
+import jalview.workers.AnnotationProviderI
+import jalview.workers.AlignmentAnnotationFactory
+import jalview.datamodel.*;
+  
+/*
+ * Define something that counts each visible feature type
+ */
+def sdppredCounter =
+    [
+     getNames: { visibleFeatures as String[] }, 
+     getDescriptions:  { visibleFeatures as String[] },
+     getMinColour: { [0, 255, 255] as int[] }, // cyan
+     getMaxColour: { [0, 0, 255] as int[] }, // blue
+     count: 
+         { res, feats -> 
+             getCounts.call(feats) 
+         },
+     calculateAnnotation: 
+         { al, feat_rend ->         
+         ProfilesI a_prof=al.getSequenceConsensusHash();
+         al_width = a_prof.getEndColumn();
+//         jalview.datamodel.Annotation ai[] = new jalview.datamodel.Annotation[al_width];
+         def sg_profs = [];
+         al.getGroups().each({group -> sg_profs << group.getSequenceConsensusHash() });
+         if (sg_profs==null) {
+           return null;
+         }
+         annot = new Annotation[al_width];
+         for (int c=0;c<al_width;c++) {
+           def al_p=a_prof.get(c);
+           if (al_p!=null) {
+           def al_ng = al_p.getNonGapped()
+           if (al_p.getCounts()!=null) {
+           al_p = al_p.getCounts().getSymbolCounts();
+           def tot_count=[foo:0];
+           for (int a=al_p.values.length-1;a>-1;a--) {
+             tot_count << [(al_p.symbols[a]):(al_p.values[a])]
+           }
+           Ip=0.0;
+           if (al_ng>0) {
+             sg_profs.each({sg_prof -> 
+               if (sg_prof!=null) {count = sg_prof.get(c);
+               if ((count!=null) && (count.getCounts()!=null)) {
+                 g_size = count.getHeight();
+                 count = count.getCounts().getSymbolCounts(); 
+                 for (int a=count.values.length-1;a>-1; a--) {
+                   Ip+= (count.values[a]/al_ng) * Math.log((count.values[a]*al_ng)/(g_size*tot_count[(count.symbols[a])]));
+                 }
+               }
+               }
+             });
+           annot[c]=new Annotation((float) Ip);
+
+           }
+         }
+         }
+         }
+         AlignmentAnnotation annotrow = new AlignmentAnnotation("SDPpred","SDP calculation results",annot);
+         annotrow.setCalcId("SDPPRED");
+         return [annotrow];
+     }
+     ] as AnnotationProviderI
+
+/*
+ * and register the counter
+ */
+AlignmentAnnotationFactory.newCalculator(sdppredCounter)
index fdca89d..a018dee 100755 (executable)
@@ -52,12 +52,11 @@ public class SeqsetUtils
       sqinfo.put("Description", seq.getDescription());
     }
 
-    Vector<SequenceFeature> sfeat = new Vector<SequenceFeature>();
-    List<SequenceFeature> sfs = seq.getFeatures().getAllFeatures();
-    sfeat.addAll(sfs);
-
     if (seq.getDatasetSequence() == null)
     {
+      Vector<SequenceFeature> sfeat = new Vector<>();
+      List<SequenceFeature> sfs = seq.getFeatures().getAllFeatures();
+      sfeat.addAll(sfs);
       sqinfo.put("SeqFeatures", sfeat);
       sqinfo.put("PdbId",
               (seq.getAllPDBEntries() != null) ? seq.getAllPDBEntries()
index c4098e2..15423b1 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.datamodel;
 
 import jalview.analysis.AlignmentUtils;
+import jalview.analysis.Conservation;
 import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
 import jalview.io.FastaFile;
 import jalview.util.Comparison;
@@ -71,6 +72,12 @@ public class Alignment implements AlignmentI, AutoCloseable
 
   private List<AlignedCodonFrame> codonFrameList;
 
+  private Conservation conservation;
+
+  private ProfilesI consensus;
+
+  private Hashtable[] codonConsensus, rnaStructureConsensus;
+
   private void initAlignment(SequenceI[] seqs)
   {
     groups = Collections.synchronizedList(new ArrayList<SequenceGroup>());
@@ -2032,4 +2039,55 @@ public class Alignment implements AlignmentI, AutoCloseable
     }
   }
 
+  @Override
+  public Hashtable[] getComplementConsensusHash()
+  {
+    return codonConsensus;
+  }
+
+  @Override
+  public Conservation getConservation()
+  {
+    return conservation;
+  }
+
+  @Override
+  public Hashtable[] getRnaStructureConsensusHash()
+  {
+    return rnaStructureConsensus;
+  }
+
+  @Override
+  public ProfilesI getSequenceConsensusHash()
+  {
+    return consensus;
+  }
+
+  @Override
+  public void setComplementConsensusHash(Hashtable[] hconsensus)
+  {
+    codonConsensus = hconsensus;
+
+  }
+
+  @Override
+  public void setConservation(Conservation cons)
+  {
+    conservation = cons;
+
+  }
+
+  @Override
+  public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
+  {
+    rnaStructureConsensus = hStrucConsensus;
+
+  }
+
+  @Override
+  public void setSequenceConsensusHash(ProfilesI hconsensus)
+  {
+    consensus = hconsensus;
+
+  }
 }
index 93a2456..012ae6b 100755 (executable)
@@ -20,6 +20,8 @@
  */
 package jalview.datamodel;
 
+import jalview.analysis.Conservation;
+
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
@@ -624,4 +626,12 @@ public interface AlignmentI extends AnnotatedCollectionI
   public HiddenColumns propagateInsertions(SequenceI profileseq,
           AlignmentView input);
 
+  void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus);
+
+  void setSequenceConsensusHash(ProfilesI hconsensus);
+
+  void setComplementConsensusHash(Hashtable[] hconsensus);
+
+  void setConservation(Conservation cons);
+
 }
index e2bb5a6..e86216f 100644 (file)
@@ -20,6 +20,9 @@
  */
 package jalview.datamodel;
 
+import jalview.analysis.Conservation;
+
+import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
@@ -83,4 +86,32 @@ public interface SequenceCollectionI
    * @return
    */
   boolean isNucleotide();
+
+  /**
+   * 
+   * @return the physicochemical property conservation for this sequence
+   *         collection (protein only)
+   */
+  Conservation getConservation();
+
+  /**
+   * 
+   * @return null or a valid Codon consensus object (protein only)
+   */
+  Hashtable[] getComplementConsensusHash();
+
+  /**
+   * 
+   * @return null or a valid RNA Structure base pair consensus object (nucleotide
+   *         only)
+   */
+  Hashtable[] getRnaStructureConsensusHash();
+
+  /**
+   * 
+   * @return null or the consensus profile for this collection if it has been
+   *         calculated
+   */
+  ProfilesI getSequenceConsensusHash();
+
 }
index 861595c..fbf39ac 100755 (executable)
@@ -31,6 +31,7 @@ import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeSupport;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
@@ -502,6 +503,7 @@ public class SequenceGroup implements AnnotatedCollectionI
    * 
    * @return DOCUMENT ME!
    */
+  @Override
   public Conservation getConservation()
   {
     return conserve;
@@ -674,6 +676,26 @@ public class SequenceGroup implements AnnotatedCollectionI
 
   public ProfilesI consensusData = null;
 
+  @Override
+  public ProfilesI getSequenceConsensusHash()
+  {
+    return consensusData;
+  }
+
+  @Override
+  public Hashtable[] getComplementConsensusHash()
+  {
+    // TODO: Groupwise CDS Consensus
+    return null;
+  }
+
+  @Override
+  public Hashtable[] getRnaStructureConsensusHash()
+  {
+    // TODO Groupwise RNA Consensus
+    return null;
+  }
+
   private void _updateConsensusRow(ProfilesI cnsns, long nseq)
   {
     if (consensus == null)
index 75cb45b..3691a69 100644 (file)
@@ -724,6 +724,7 @@ public abstract class AlignmentViewport
   @Override
   public void setConservation(Conservation cons)
   {
+    alignment.setConservation(cons);
     hconservation = cons;
   }
 
@@ -742,6 +743,7 @@ public abstract class AlignmentViewport
   @Override
   public void setSequenceConsensusHash(ProfilesI hconsensus)
   {
+    alignment.setSequenceConsensusHash(hconsensus);
     this.hconsensus = hconsensus;
   }
 
@@ -749,6 +751,7 @@ public abstract class AlignmentViewport
   public void setComplementConsensusHash(
           Hashtable<String, Object>[] hconsensus)
   {
+    alignment.setComplementConsensusHash(hconsensus);
     this.hcomplementConsensus = hconsensus;
   }
 
@@ -774,6 +777,7 @@ public abstract class AlignmentViewport
   public void setRnaStructureConsensusHash(
           Hashtable<String, Object>[] hStrucConsensus)
   {
+    alignment.setRnaStructureConsensusHash(hStrucConsensus);
     this.hStrucConsensus = hStrucConsensus;
 
   }
index 8f37f15..56361fa 100644 (file)
@@ -90,7 +90,9 @@ class AnnotationWorker extends AlignCalcWorker
           for (AlignmentAnnotation ann : anns)
           {
             AlignmentAnnotation theAnn = alignment.findOrCreateAnnotation(
-                    ann.label, ann.description, false, null, null);
+                    ann.label, ann.getCalcId(), ann.autoCalculated,
+                    ann.sequenceRef,
+                    ann.groupRef);
             theAnn.showAllColLabels = true;
             theAnn.graph = AlignmentAnnotation.BAR_GRAPH;
             theAnn.scaleColLabel = true;