Merge branch 'develop' into features/JAL-3982_JAL-3960_mouseover_genome_to_3dstructur... features/JAL-3982_JAL-3960_mouseover_genome_to_3dstructure_for_2_11_3
authorJames Procter <j.procter@dundee.ac.uk>
Tue, 23 Jan 2024 17:28:31 +0000 (17:28 +0000)
committerJames Procter <j.procter@dundee.ac.uk>
Tue, 23 Jan 2024 17:28:31 +0000 (17:28 +0000)
1  2 
src/jalview/structure/StructureSelectionManager.java

@@@ -34,6 -34,7 +34,7 @@@ import java.util.Vector
  
  import jalview.analysis.AlignSeq;
  import jalview.api.StructureSelectionManagerProvider;
+ import jalview.bin.Cache;
  import jalview.bin.Console;
  import jalview.commands.CommandI;
  import jalview.commands.EditCommand;
@@@ -45,12 -46,12 +46,13 @@@ import jalview.datamodel.Annotation
  import jalview.datamodel.ContiguousI;
  import jalview.datamodel.HiddenColumns;
  import jalview.datamodel.PDBEntry;
 +import jalview.datamodel.SearchResultMatchI;
  import jalview.datamodel.SearchResults;
  import jalview.datamodel.SearchResultsI;
  import jalview.datamodel.SequenceI;
  import jalview.ext.jmol.JmolParser;
  import jalview.gui.IProgressIndicator;
+ import jalview.gui.Preferences;
  import jalview.io.AppletFormatAdapter;
  import jalview.io.DataSourceType;
  import jalview.io.StructureFile;
@@@ -1100,19 -1101,6 +1102,19 @@@ public class StructureSelectionManage
      {
        seqPos = seq.findPosition(indexpos);
      }
 +    
 +    // precompute so we can also relay structure highlights
 +    if (results == null)
 +    {
 +      results = MappingUtils.buildSearchResults(seq, seqPos,
 +              seqmappings);
 +    }
 +    if (handlingVamsasMo)
 +    {
 +      results.addResult(seq, seqPos, seqPos);
 +
 +    }
 +
      for (int i = 0; i < listeners.size(); i++)
      {
        Object listener = listeners.elementAt(i);
        }
        if (listener instanceof StructureListener)
        {
 -        highlightStructure((StructureListener) listener, seq, seqPos);
 +        StructureListener sl = (StructureListener) listener;
 +        // TODO: consider merging highlightStructure variants second call
 +        // functionally same as first if seq/seqPos is part of the searchResults
 +        if (highlightStructure(sl, seq, seqPos)==0 && relaySeqMappings)
 +        {
 +          // structure highlights for mapped sequences
 +          highlightStructure(sl,results);
 +        }
        }
        else
        {
            {
              if (relaySeqMappings)
              {
 -              if (results == null)
 -              {
 -                results = MappingUtils.buildSearchResults(seq, seqPos,
 -                        seqmappings);
 -              }
 -              if (handlingVamsasMo)
 -              {
 -                results.addResult(seq, seqPos, seqPos);
 -
 -              }
                if (!results.isEmpty())
                {
                  seqListener.highlightSequence(results);
    }
  
    /**
 +   * highlights positions in a structure viewer corresponding to one or more positions on sequences
 +   * @param sl
 +   * @param searchResults
 +   * @return 0 or number of structure regions highlighted
 +   */
 +  public int highlightStructure(StructureListener sl, SearchResultsI searchResults)
 +  {
 +    int atomNo;
 +    List<AtomSpec> atoms = new ArrayList<>();
 +
 +    for (SearchResultMatchI sr: searchResults.getResults())
 +    {
 +      SequenceI seq = sr.getSequence();
 +      for (StructureMapping sm : mappings)
 +      {
 +        if (sm.sequence == seq || sm.sequence == seq.getDatasetSequence()
 +                || (sm.sequence.getDatasetSequence() != null
 +                        && (sm.sequence.getDatasetSequence() == seq
 +                                || sm.sequence.getDatasetSequence() == seq
 +                                        .getDatasetSequence())))
 +        {
 +          for (int index=sr.getStart();index<=sr.getEnd();index++)
 +          {
 +            atomNo = sm.getAtomNum(index);
 +
 +            if (atomNo > 0)
 +            {
 +              atoms.add(new AtomSpec(sm.pdbfile, sm.pdbchain,
 +                      sm.getPDBResNum(index), atomNo));
 +            }
 +          }
 +        }
 +      }
 +    }
 +    sl.highlightAtoms(atoms);
 +    return atoms.size();
 +  }
 +  /**
     * Send suitable messages to a StructureListener to highlight atoms
     * corresponding to the given sequence position(s)
     * 
     * @param sl
     * @param seq
     * @param positions
 +   * @return 0 if no atoms identified for position(s)
     */
 -  public void highlightStructure(StructureListener sl, SequenceI seq,
 +  public int highlightStructure(StructureListener sl, SequenceI seq,
            int... positions)
    {
      if (!sl.isListeningFor(seq))
      {
 -      return;
 +      return 0;
      }
      int atomNo;
      List<AtomSpec> atoms = new ArrayList<>();
        }
      }
      sl.highlightAtoms(atoms);
 +    return atoms.size();
    }
  
    public void highlightStructureRegionsFor(StructureListener sl,
      return pdbIdFileName;
    }
  
+   public static void doConfigureStructurePrefs(
+           StructureSelectionManager ssm)
+   {
+     doConfigureStructurePrefs(ssm,
+             Cache.getDefault(Preferences.ADD_SS_ANN, true),
+             Cache.getDefault(Preferences.ADD_TEMPFACT_ANN, true),
+             Cache.getDefault(Preferences.STRUCT_FROM_PDB, true),
+             Cache.getDefault(Preferences.USE_RNAVIEW, false));
+   }
+   public static void doConfigureStructurePrefs(
+           StructureSelectionManager ssm, boolean add_ss_ann,
+           boolean add_tempfact_ann, boolean struct_from_pdb,
+           boolean use_rnaview)
+   {
+     if (add_ss_ann)
+     {
+       ssm.setAddTempFacAnnot(add_tempfact_ann);
+       ssm.setProcessSecondaryStructure(struct_from_pdb);
+       // JAL-3915 - RNAView is no longer an option so this has no effect
+       ssm.setSecStructServices(use_rnaview);
+     }
+     else
+     {
+       ssm.setAddTempFacAnnot(false);
+       ssm.setProcessSecondaryStructure(false);
+       ssm.setSecStructServices(false);
+     }
+   }
  }