From: Jim Procter Date: Thu, 4 Jul 2024 16:27:11 +0000 (+0100) Subject: Merge branch 'feature/JAL-4386_calculate_tree_using_secondary_structure_annotation... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6d4a9ad85f539652408a58ee43f86ce99f0112bd;p=jalview.git Merge branch 'feature/JAL-4386_calculate_tree_using_secondary_structure_annotation' into spike/JAL-4386_generate_multiple_leaves_for_ss_sources Conflicts: src/jalview/analysis/AlignmentUtils.java --- 6d4a9ad85f539652408a58ee43f86ce99f0112bd diff --cc src/jalview/analysis/AlignmentUtils.java index c2a4c45,99d3d6e..2cefaa7 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.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; } } } diff --cc src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java index dc35efb,d7859f1..ceccec0 --- a/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java +++ b/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java @@@ -90,71 -88,6 +90,71 @@@ public class SecondaryStructureDistance return true; } + ArrayList ssForSeqs = null; + + @Override + public SequenceI[] expandSeqData(SequenceI[] sequences, + AlignmentView seqData, SimilarityParamsI scoreParams,List labels) + { + ssForSeqs = new ArrayList(); + List newSequences = new ArrayList(); + List newCigs = new ArrayList(); + 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> 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 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). @@@ -301,7 -233,7 +301,7 @@@ similarities[j][i] = similarities[i][j]; } } -- return ssRateMatrix.similarityToDistance(new Matrix(similarities)); ++ return SimilarityScoreModel.similarityToDistance(new Matrix(similarities)); }