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)
1  2 
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/viewmodel/AlignmentViewport.java

@@@ -21,6 -21,7 +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 +72,12 @@@ public class Alignment implements Align
  
    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>());
    {
      synchronized (sequences)
      {
 +    
        if (i > -1 && i < sequences.size())
        {
          return sequences.get(i);
      int i = 0;
      SequenceI sq = null;
      String sqname = null;
 +    int nseq = sequences.size();
      if (startAfter != null)
      {
        // try to find the sequence in the alignment
        boolean matched = false;
 -      while (i < sequences.size())
 +      while (i < nseq)
        {
          if (getSequenceAt(i++) == startAfter)
          {
          i = 0;
        }
      }
 -    while (i < sequences.size())
 +    while (i < nseq)
      {
        sq = getSequenceAt(i);
        sqname = sq.getName();
      int maxLength = -1;
  
      SequenceI current;
 -    for (int i = 0; i < sequences.size(); i++)
 +    int nseq = sequences.size();
 +    for (int i = 0; i < nseq; i++)
      {
        current = getSequenceAt(i);
        for (int j = current.getLength(); j > maxLength; j--)
      maxLength++;
  
      int cLength;
 -    for (int i = 0; i < sequences.size(); i++)
 +    for (int i = 0; i < nseq; i++)
      {
        current = getSequenceAt(i);
        cLength = current.getLength();
      }
    }
  
+   @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;
+   }
  }
@@@ -31,6 -31,7 +31,7 @@@ import java.beans.PropertyChangeListene
  import java.beans.PropertyChangeSupport;
  import java.util.ArrayList;
  import java.util.Arrays;
+ import java.util.Hashtable;
  import java.util.List;
  import java.util.Map;
  
@@@ -269,15 -270,16 +270,15 @@@ public class SequenceGroup implements A
      for (int i = 0, ipos = 0; i < inorder.length; i++)
      {
        SequenceI seq = inorder[i];
 -
 -      seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
 -      if (seqs[ipos] != null)
 +      SequenceI seqipos = seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
 +      if (seqipos != null)
        {
 -        seqs[ipos].setDescription(seq.getDescription());
 -        seqs[ipos].setDBRefs(seq.getDBRefs());
 -        seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
 +        seqipos.setDescription(seq.getDescription());
 +        seqipos.setDBRefs(seq.getDBRefs());
 +        seqipos.setSequenceFeatures(seq.getSequenceFeatures());
          if (seq.getDatasetSequence() != null)
          {
 -          seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
 +          seqipos.setDatasetSequence(seq.getDatasetSequence());
          }
  
          if (seq.getAnnotation() != null)
              if (alann != null)
              {
                boolean found = false;
 -              for (int pos = 0; pos < alann.length; pos++)
 +              for (int pos = 0, np = alann.length; pos < np; pos++)
                {
                  if (alann[pos] == tocopy)
                  {
              newannot.restrict(startRes, endRes);
              newannot.setSequenceRef(seqs[ipos]);
              newannot.adjustForAlignment();
 -            seqs[ipos].addAlignmentAnnotation(newannot);
 +            seqipos.addAlignmentAnnotation(newannot);
            }
          }
          ipos++;
     * 
     * @return DOCUMENT ME!
     */
+   @Override
    public Conservation getConservation()
    {
      return conserve;
  
    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)
@@@ -24,7 -24,6 +24,7 @@@ import jalview.analysis.AnnotationSorte
  import jalview.analysis.Conservation;
  import jalview.analysis.TreeModel;
  import jalview.api.AlignCalcManagerI;
 +import jalview.api.AlignExportSettingsI;
  import jalview.api.AlignViewportI;
  import jalview.api.AlignmentViewPanel;
  import jalview.api.FeaturesDisplayedI;
@@@ -32,7 -31,6 +32,7 @@@ import jalview.api.ViewStyleI
  import jalview.commands.CommandI;
  import jalview.datamodel.AlignedCodonFrame;
  import jalview.datamodel.AlignmentAnnotation;
 +import jalview.datamodel.AlignmentExportData;
  import jalview.datamodel.AlignmentI;
  import jalview.datamodel.AlignmentView;
  import jalview.datamodel.Annotation;
@@@ -711,19 -709,20 +711,20 @@@ public abstract class AlignmentViewpor
    /**
     * results of cDNA complement consensus visible portion of view
     */
 -  protected Hashtable[] hcomplementConsensus = null;
 +  protected Hashtable<String, Object>[] hcomplementConsensus = null;
  
    /**
     * results of secondary structure base pair consensus for visible portion of
     * view
     */
 -  protected Hashtable[] hStrucConsensus = null;
 +  protected Hashtable<String, Object>[] hStrucConsensus = null;
  
    protected Conservation hconservation = null;
  
    @Override
    public void setConservation(Conservation cons)
    {
+     alignment.setConservation(cons);
      hconservation = cons;
    }
  
    @Override
    public void setSequenceConsensusHash(ProfilesI hconsensus)
    {
+     alignment.setSequenceConsensusHash(hconsensus);
      this.hconsensus = hconsensus;
    }
  
    @Override
 -  public void setComplementConsensusHash(Hashtable[] hconsensus)
 +  public void setComplementConsensusHash(
 +          Hashtable<String, Object>[] hconsensus)
    {
+     alignment.setComplementConsensusHash(hconsensus);
      this.hcomplementConsensus = hconsensus;
    }
  
    }
  
    @Override
 -  public Hashtable[] getComplementConsensusHash()
 +  public Hashtable<String, Object>[] getComplementConsensusHash()
    {
      return hcomplementConsensus;
    }
  
    @Override
 -  public Hashtable[] getRnaStructureConsensusHash()
 +  public Hashtable<String, Object>[] getRnaStructureConsensusHash()
    {
      return hStrucConsensus;
    }
  
    @Override
 -  public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
 +  public void setRnaStructureConsensusHash(
 +          Hashtable<String, Object>[] hStrucConsensus)
    {
+     alignment.setRnaStructureConsensusHash(hStrucConsensus);
      this.hStrucConsensus = hStrucConsensus;
  
    }
      ranges = null;
      currentTree = null;
      selectionGroup = null;
 +    colSel = null;
      setAlignment(null);
    }
  
        }
      } while (end < max);
  
 -    int[][] startEnd = new int[regions.size()][2];
 +    // int[][] startEnd = new int[regions.size()][2];
  
      return regions;
    }
       * TODO reorder the annotation rows according to group/sequence ordering on
       * alignment
       */
 -    boolean sortg = true;
 +    // boolean sortg = true;
  
      // remove old automatic annotation
      // add any new annotation
    public void clearSequenceColours()
    {
      sequenceColours.clear();
 -  };
 +  }
  
    @Override
    public AlignViewportI getCodingComplement()
      return currentTree;
    }
  
 +  @Override
 +  public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
 +  {
 +    AlignmentI alignmentToExport = null;
 +    String[] omitHidden = null;
 +    alignmentToExport = null;
 +
 +    if (hasHiddenColumns() && !options.isExportHiddenColumns())
 +    {
 +      omitHidden = getViewAsString(false,
 +              options.isExportHiddenSequences());
 +    }
 +
 +    int[] alignmentStartEnd = new int[2];
 +    if (hasHiddenRows() && options.isExportHiddenSequences())
 +    {
 +      alignmentToExport = getAlignment().getHiddenSequences()
 +              .getFullAlignment();
 +    }
 +    else
 +    {
 +      alignmentToExport = getAlignment();
 +    }
 +    alignmentStartEnd = getAlignment().getHiddenColumns()
 +            .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
 +    AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
 +            omitHidden, alignmentStartEnd);
 +    return ed;
 +  }
 +  
    /**
     * flag set to indicate if structure views might be out of sync with sequences
     * in the alignment
        codingComplement.setUpdateStructures(needToUpdateStructureViews);
      }
    }
 +
 +  @Override
 +  public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
 +  {
 +    int start = 0;
 +    int end = 0;
 +    if (selectedRegionOnly && selectionGroup != null)
 +    {
 +      start = selectionGroup.getStartRes();
 +      end = selectionGroup.getEndRes() + 1;
 +    }
 +    else
 +    {
 +      end = alignment.getWidth();
 +    }
 +    return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
 +            false));
 +  }
  }