From: Jim Procter Date: Wed, 23 Feb 2022 12:47:31 +0000 (+0000) Subject: Merge branch 'features/JAL-3417_sdppred_calcs' into features/r2_11_2_JAL-3417_sdppred X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6abfeb94aa315e799cb9196c82cfcbe86221f428;hp=f1fa440f885429399436bb09ef6d0639c8acd991;p=jalview.git Merge branch 'features/JAL-3417_sdppred_calcs' into features/r2_11_2_JAL-3417_sdppred --- diff --git a/examples/groovy/sdppred_testing.groovy b/examples/groovy/sdppred_testing.groovy new file mode 100644 index 0000000..64199cc --- /dev/null +++ b/examples/groovy/sdppred_testing.groovy @@ -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-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) diff --git a/src/jalview/analysis/SeqsetUtils.java b/src/jalview/analysis/SeqsetUtils.java index fdca89d..a018dee 100755 --- a/src/jalview/analysis/SeqsetUtils.java +++ b/src/jalview/analysis/SeqsetUtils.java @@ -52,12 +52,11 @@ public class SeqsetUtils sqinfo.put("Description", seq.getDescription()); } - Vector sfeat = new Vector(); - List sfs = seq.getFeatures().getAllFeatures(); - sfeat.addAll(sfs); - if (seq.getDatasetSequence() == null) { + Vector sfeat = new Vector<>(); + List sfs = seq.getFeatures().getAllFeatures(); + sfeat.addAll(sfs); sqinfo.put("SeqFeatures", sfeat); sqinfo.put("PdbId", (seq.getAllPDBEntries() != null) ? seq.getAllPDBEntries() diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index c4098e2..15423b1 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -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 codonFrameList; + private Conservation conservation; + + private ProfilesI consensus; + + private Hashtable[] codonConsensus, rnaStructureConsensus; + private void initAlignment(SequenceI[] seqs) { groups = Collections.synchronizedList(new ArrayList()); @@ -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; + + } } diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 93a2456..012ae6b 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -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); + } diff --git a/src/jalview/datamodel/SequenceCollectionI.java b/src/jalview/datamodel/SequenceCollectionI.java index e2bb5a6..e86216f 100644 --- a/src/jalview/datamodel/SequenceCollectionI.java +++ b/src/jalview/datamodel/SequenceCollectionI.java @@ -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(); + } diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 861595c..fbf39ac 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -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) diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 75cb45b..3691a69 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -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[] hconsensus) { + alignment.setComplementConsensusHash(hconsensus); this.hcomplementConsensus = hconsensus; } @@ -774,6 +777,7 @@ public abstract class AlignmentViewport public void setRnaStructureConsensusHash( Hashtable[] hStrucConsensus) { + alignment.setRnaStructureConsensusHash(hStrucConsensus); this.hStrucConsensus = hStrucConsensus; } diff --git a/src/jalview/workers/AnnotationWorker.java b/src/jalview/workers/AnnotationWorker.java index 8f37f15..56361fa 100644 --- a/src/jalview/workers/AnnotationWorker.java +++ b/src/jalview/workers/AnnotationWorker.java @@ -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;