From f1b00517fe5f888f3213d70270e27a83dffe1695 Mon Sep 17 00:00:00 2001 From: Renia Correya Date: Fri, 8 Mar 2024 14:31:51 +0000 Subject: [PATCH] JAL-4386 Added further checks for sequences that have no secondary structure. --- .../SecondaryStructureDistanceModel.java | 13 +++++--- src/jalview/gui/CalculationChooser.java | 32 +++++++++++++++++--- test/jalview/gui/CalculationChooserTest.java | 12 ++++---- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java b/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java index 7fcee35..0aac7fa 100644 --- a/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java +++ b/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java @@ -255,14 +255,19 @@ public class SecondaryStructureDistanceModel extends DistanceScoreModel int seqPosition = seq.findPosition(columnPosition); AlignmentAnnotation[] aa = seq.getRefSeq().getAnnotation("Secondary Structure"); if (aa != null) { + if (aa[0].getAnnotationForPosition(seqPosition) != null) { Annotation a = aa[0].getAnnotationForPosition(seqPosition); ss = a.secondaryStructure; if (ss == ' ') { - ss = 'C'; // In JalView, 'C' is represented as ' ' - } - if (ss != '\0') { // Check if ss is not the default null character - secondaryStructure.add(String.valueOf(ss)); + ss = 'C'; // In JalView, 'C' is represented as ' ' } + } + else { + ss = 'C'; + } + if (ss != '\0') { // Check if ss is not the default null character + secondaryStructure.add(String.valueOf(ss)); + } } return secondaryStructure; } diff --git a/src/jalview/gui/CalculationChooser.java b/src/jalview/gui/CalculationChooser.java index af41e58..25885d7 100644 --- a/src/jalview/gui/CalculationChooser.java +++ b/src/jalview/gui/CalculationChooser.java @@ -58,7 +58,9 @@ import jalview.analysis.scoremodels.SimilarityParams; import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.SimilarityParamsI; import jalview.bin.Cache; +import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; import jalview.util.MessageManager; /** @@ -430,8 +432,27 @@ public class CalculationChooser extends JPanel * select the score models applicable to the alignment type */ boolean nucleotide = af.getViewport().getAlignment().isNucleotide(); - List models = getApplicableScoreModels(nucleotide, - pca.isSelected()); + AlignmentAnnotation[] alignmentAnnotation = af.getViewport().getAlignment().getAlignmentAnnotation(); + + boolean ssPresent = false; + + for (AlignmentAnnotation aa : alignmentAnnotation) + + { + if(ssPresent) { + break; + } + + if (aa.label.equals("Secondary Structure")) + + { + ssPresent = true; + break; + } + } + + List models = getApplicableScoreModels(nucleotide, pca.isSelected(), + ssPresent); /* * now we can actually add entries to the combobox, @@ -483,14 +504,15 @@ public class CalculationChooser extends JPanel * @return */ protected static List getApplicableScoreModels( - boolean nucleotide, boolean forPca) + boolean nucleotide, boolean forPca, boolean ssPresent) { List filtered = new ArrayList<>(); ScoreModels scoreModels = ScoreModels.getInstance(); for (ScoreModelI sm : scoreModels.getModels()) { - if (!nucleotide && sm.isProtein() || nucleotide && sm.isDNA()) + if (!nucleotide && sm.isProtein() || nucleotide && sm.isDNA() + || ssPresent && sm.isSecondaryStructure()) { filtered.add(sm); } @@ -505,7 +527,7 @@ public class CalculationChooser extends JPanel { filtered.add(scoreModels.getBlosum62()); } - + return filtered; } diff --git a/test/jalview/gui/CalculationChooserTest.java b/test/jalview/gui/CalculationChooserTest.java index 9835189..5e6d57c 100644 --- a/test/jalview/gui/CalculationChooserTest.java +++ b/test/jalview/gui/CalculationChooserTest.java @@ -55,7 +55,7 @@ public class CalculationChooserTest * peptide models for PCA */ List filtered = CalculationChooser - .getApplicableScoreModels(false, true); + .getApplicableScoreModels(false, true, true); assertEquals(filtered.size(), 4); assertSame(filtered.get(0), blosum62); assertSame(filtered.get(1), pam250); @@ -65,7 +65,7 @@ public class CalculationChooserTest /* * peptide models for Tree are the same */ - filtered = CalculationChooser.getApplicableScoreModels(false, false); + filtered = CalculationChooser.getApplicableScoreModels(false, false, true); assertEquals(filtered.size(), 4); assertSame(filtered.get(0), blosum62); assertSame(filtered.get(1), pam250); @@ -75,7 +75,7 @@ public class CalculationChooserTest /* * nucleotide models for PCA */ - filtered = CalculationChooser.getApplicableScoreModels(true, true); + filtered = CalculationChooser.getApplicableScoreModels(true, true, true); assertEquals(filtered.size(), 3); assertSame(filtered.get(0), dna); assertEquals(filtered.get(1).getName(), "PID"); @@ -84,7 +84,7 @@ public class CalculationChooserTest /* * nucleotide models for Tree are the same */ - filtered = CalculationChooser.getApplicableScoreModels(true, false); + filtered = CalculationChooser.getApplicableScoreModels(true, false, true); assertEquals(filtered.size(), 3); assertSame(filtered.get(0), dna); assertEquals(filtered.get(1).getName(), "PID"); @@ -99,7 +99,7 @@ public class CalculationChooserTest /* * nucleotide models for Tree are unchanged */ - filtered = CalculationChooser.getApplicableScoreModels(true, false); + filtered = CalculationChooser.getApplicableScoreModels(true, false, true); assertEquals(filtered.size(), 3); assertSame(filtered.get(0), dna); assertEquals(filtered.get(1).getName(), "PID"); @@ -108,7 +108,7 @@ public class CalculationChooserTest /* * nucleotide models for PCA add BLOSUM62 as last option */ - filtered = CalculationChooser.getApplicableScoreModels(true, true); + filtered = CalculationChooser.getApplicableScoreModels(true, true, true); assertEquals(filtered.size(), 4); assertSame(filtered.get(0), dna); assertEquals(filtered.get(1).getName(), "PID"); -- 1.7.10.2