Merge branch 'feature/JAL-4386_calculate_tree_using_secondary_structure_annotation...
authorJim Procter <jprocter@dundee.ac.uk>
Thu, 4 Jul 2024 16:27:11 +0000 (17:27 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Thu, 4 Jul 2024 16:27:11 +0000 (17:27 +0100)
 Conflicts:
src/jalview/analysis/AlignmentUtils.java

1  2 
src/jalview/analysis/AlignmentUtils.java
src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java

@@@ -3125,41 -3126,33 +3125,39 @@@ public class AlignmentUtil
        {
          continue;
        }
 -      
 -      for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet())
 +
 +      if (isSecondaryStructureFrom(selectedSSSource, aa))
        {
 +        ssAlignmentAnnotationForSequences
 +                .computeIfAbsent(aa.sequenceRef.getDatasetSequence(),
 +                        k -> new ArrayList<>())
 +                .add(aa);
 +      }
 +    }
  
 -        if (label.equals(aa.label))
 -        {
 +    return ssAlignmentAnnotationForSequences;
  
 -          if (selectedSSSource.equals(Constants.SS_ALL_PROVIDERS))
 -          {
 -            ssAlignmentAnnotationForSequences
 -                    .computeIfAbsent(aa.sequenceRef.getDatasetSequence(),
 -                            k -> new ArrayList<>())
 -                    .add(aa);
 -            break;
 -          }
 +  }
  
 -          String ssSource = AlignmentUtils
 -                  .extractSSSourceFromAnnotationDescription(aa);
 -          if (ssSource != null && ssSource.equals(selectedSSSource))
 -          {
 +  public static boolean isSecondaryStructureFrom(String selectedSSSource,
 +          AlignmentAnnotation aa)
 +  {
  
 -            ssAlignmentAnnotationForSequences
 -                    .computeIfAbsent(aa.sequenceRef.getDatasetSequence(),
 -                            k -> new ArrayList<>())
 -                    .add(aa);
 -            break;
 -          }
 +    for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet())
 +    {
 +
 +      if (label.equals(aa.label))
 +      {
 +
-         if (selectedSSSource.equals(
-                 MessageManager.getString("option.ss_providers_all")))
++        if (selectedSSSource.equals(Constants.SS_ALL_PROVIDERS))
 +        {
 +          return true;
 +        }
 +        String ssSource = AlignmentUtils
 +                .extractSSSourceFromAnnotationDescription(aa);
 +        if (ssSource != null && ssSource.equals(selectedSSSource))
 +        {
 +          return true;
          }
        }
      }
@@@ -90,71 -88,6 +90,71 @@@ public class SecondaryStructureDistance
      return true;
    }
    
 +  ArrayList<AlignmentAnnotation> ssForSeqs = null;
 +
 +  @Override
 +  public SequenceI[] expandSeqData(SequenceI[] sequences,
 +          AlignmentView seqData, SimilarityParamsI scoreParams,List<String> labels)
 +  {
 +    ssForSeqs = new ArrayList<AlignmentAnnotation>();
 +    List<SequenceI> newSequences = new ArrayList<SequenceI>();
 +    List<SeqCigar> newCigs = new ArrayList<SeqCigar>();
 +    int sq = 0;
 +    
 +    
 +
 +    AlignmentAnnotation[] alignAnnotList = fr.getViewport().getAlignment()
 +            .getAlignmentAnnotation();   
 +    
 +    String ssSource = scoreParams.getSecondaryStructureSource(); 
 +    if(ssSource == null || ssSource == "") {
-       ssSource = MessageManager.getString("option.ss_providers_all");
++      ssSource = Constants.SS_ALL_PROVIDERS;
 +    }
 +    
 +    /*
 +     * Add secondary structure annotations that are added to the annotation track
 +     * to the map
 +     */
 +    Map<SequenceI, ArrayList<AlignmentAnnotation>> ssAlignmentAnnotationForSequences 
 +      = AlignmentUtils.getSequenceAssociatedAlignmentAnnotations(alignAnnotList, ssSource);
 +    
 +    for (SeqCigar scig : seqData.getSequences())
 +    {
 +      // get the next sequence that should be bound to this scig: may be null
 +      SequenceI alSeq = sequences[sq++];
 +      List<AlignmentAnnotation> ssec = ssAlignmentAnnotationForSequences.get(scig.getRefSeq());
 +      if (ssec == null)
 +      {
 +        // not defined
 +        newSequences.add(alSeq);
 +        if (alSeq!=null) {
 +          labels.add("No Secondary Structure");
 +        }
 +        SeqCigar newSeqCigar = scig; //new SeqCigar(scig);
 +        newCigs.add(newSeqCigar);
 +        ssForSeqs.add(null);
 +      } else {
 +        for (int i = 0; i < ssec.size(); i++)
 +        {
 +          if (alSeq != null)
 +          {
 +            labels.add(AlignmentUtils
 +                    .extractSSSourceFromAnnotationDescription(ssec.get(i)));
 +          }
 +          //newSequences.add(seq);
 +          newSequences.add(alSeq);
 +          SeqCigar newSeqCigar = scig; // new SeqCigar(scig);
 +          newCigs.add(newSeqCigar);
 +          ssForSeqs.add(ssec.get(i));
 +        }
 +      }
 +    }
 +
 +    seqData.setSequences(newCigs.toArray(new SeqCigar[0]));
 +    return newSequences.toArray(new SequenceI[0]);
 +
 +  }
 +
    /**
     * Calculates distance score [i][j] between each pair of protein sequences 
     * based on their secondary structure annotations (H, E, C). 
          similarities[j][i] = similarities[i][j];
        }
      }
--    return ssRateMatrix.similarityToDistance(new Matrix(similarities));
++    return SimilarityScoreModel.similarityToDistance(new Matrix(similarities));
      
    }