substitution matrix. Some code refactoring.
import java.util.SortedMap;
import java.util.TreeMap;
+import jalview.api.AlignCalcWorkerI;
import jalview.bin.Console;
import jalview.commands.RemoveGapColCommand;
import jalview.datamodel.AlignedCodon;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.datamodel.features.SequenceFeatures;
+import jalview.gui.AlignmentPanel;
import jalview.io.gff.SequenceOntologyI;
import jalview.schemes.ResidueProperties;
import jalview.util.Comparison;
import jalview.util.IntRangeComparator;
import jalview.util.MapList;
import jalview.util.MappingUtils;
+import jalview.workers.SecondaryStructureConsensusThread;
/**
* grab bag of useful alignment manipulation operations Expect these to be
private static final String SEQUENCE_VARIANT = "sequence_variant:";
+
+ private static final Map<String, String> SECONDARY_STRUCTURE_LABELS = new HashMap<>();
+
+ static {
+ SECONDARY_STRUCTURE_LABELS.put("Secondary Structure", "3D Structures");
+ SECONDARY_STRUCTURE_LABELS.put("jnetpred", "JPred");
+ // Add other secondary structure labels here if needed
+ }
+
+ private static final String SS_ANNOTATION_LABEL = "Secondary Structure";
+
/*
* the 'id' attribute is provided for variant features fetched from
* Ensembl using its REST service with JSON format
}
}
}
+
+
+ public static boolean isSSAnnotationPresent( Map<SequenceI, List<AlignmentAnnotation>> annotations) {
+
+ for (SequenceI seq : annotations.keySet())
+ {
+ for (AlignmentAnnotation ann : annotations.get(seq))
+ {
+ if(ann.getDescription(false).startsWith(SS_ANNOTATION_LABEL)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
/**
* Make a copy of a reference annotation {@code ann} and add it to an
}
return true;
}
+
+
+ public static List<String> getSecondaryStructureSources(AlignmentAnnotation[] annotations) {
+
+ List<String> ssSources = new ArrayList<>();
+ Set<String> addedLabels = new HashSet<>(); // to keep track of added labels
+
+ for (AlignmentAnnotation annotation : annotations) {
+ String label = annotation.label;
+ if (SECONDARY_STRUCTURE_LABELS.containsKey(label) && !addedLabels.contains(label)) {
+ ssSources.add(SECONDARY_STRUCTURE_LABELS.get(label));
+ addedLabels.add(label); // Add the label to the set
+ }
+ }
+
+ return ssSources;
+ }
+
+ public static boolean isSecondaryStructurePresent(AlignmentAnnotation[] annotations)
+ {
+ boolean ssPresent = false;
+
+ for (AlignmentAnnotation aa : annotations)
+ {
+ if(ssPresent) {
+ break;
+ }
+
+ if (SECONDARY_STRUCTURE_LABELS.containsKey(aa.label)) {
+ ssPresent = true;
+ break;
+ }
+ }
+
+ return ssPresent;
+
+ }
}
return similarities;
}
+
}
public boolean isProtein()
{
return true;
- }
-
- @Override
- public boolean isSecondaryStructure()
- {
- return false;
- }
-
+ }
@Override
public String toString()
{
return true;
}
-
- @Override
- public boolean isSecondaryStructure()
- {
- return false;
- }
/**
* Answers 1 if c and d are the same residue (ignoring case), and not gap
{
return peptide;
}
-
- @Override
- public boolean isSecondaryStructure()
- {
- return false;
- }
/**
* Returns a copy of the score matrix as used in getPairwiseScore. If using
int noseqs = seqs.length; //no of sequences
int cpwidth = 0; // = seqData.getWidth();
double[][] distances = new double[noseqs][noseqs]; //matrix to store distance score
+ double[][] substitutionMatrix = getSubstitutionMatrix();
//secondary structure source parameter selected by the user from the drop down.
String ssSource = params.getSecondaryStructureSource();
boolean gap2 = !seqsWithoutGapAtCol.contains(sc2);
//Variable to store secondary structure at the current column
- Set<String> secondaryStructure1 = new HashSet<String>();
- Set<String> secondaryStructure2 = new HashSet<String>();
+ char ss1 = 'G', ss2 = 'G';
//secondary structure is fetched only if the current column is not
//gap for the sequence
if(!gap1 && !undefinedSS1) {
- secondaryStructure1.addAll(
- findSSAnnotationForGivenSeqAndCol(seqs[i], cpos));
+ ss1 =
+ findSSAnnotationForGivenSeqAndCol(seqs[i], cpos);
}
if(!gap2 && !undefinedSS2) {
- secondaryStructure2.addAll(
- findSSAnnotationForGivenSeqAndCol(seqs[j], cpos));
+ ss2 =
+ findSSAnnotationForGivenSeqAndCol(seqs[j], cpos);
}
/*
- * gap-gap always scores zero
- * ss-ss is always scored
- * include gap-ss scores 1 if params say to do so
+ * gap-gap scores zero
+ * similar ss-ss scores zero
+ * different ss-ss scores 1
+ * gap-ss scores 1 if params say to do so
*/
if ((!gap1 && !gap2) || params.includeGaps())
{
- int seqDistance = SetUtils.countDisjunction(
- secondaryStructure1, secondaryStructure2);
+ // Calculate distance score based on the substitution matrix
+ double seqDistance = substitutionMatrix[getSubstitutionMatrixIndex(ss1)][getSubstitutionMatrixIndex(ss2)];
distances[i][j] += seqDistance;
}
}
* (0..)
* @return
*/
- private Set<String> findSSAnnotationForGivenSeqAndCol(
+ private char findSSAnnotationForGivenSeqAndCol(
SeqCigar seq, int columnPosition)
- {
- Set<String> secondaryStructure = new HashSet<String>();
-
- char ss;
+ {
+ char ss = 'G';
//fetch the position in sequence for the column and finds the
//corresponding secondary structure annotation
else {
ss = COIL;
}
- secondaryStructure.add(String.valueOf(ss));
+
}
- return secondaryStructure;
+ return ss;
+ }
+
+ /**
+ * Retrieve the substitution matrix.
+ *
+ * @return The substitution matrix.
+ */
+ private double[][] getSubstitutionMatrix() {
+ // Defining the substitution matrix
+ // This matrix map distance scores between secondary structure symbols
+
+ return new double[][]{
+ // C E H G
+ {0.0, 1.0, 1.0, 1.0}, // C - COIL
+ {1.0, 0.0, 1.0, 1.0}, // E - SHEET
+ {1.0, 1.0, 0.0, 1.0}, // H - HELIX
+ {1.0, 1.0, 1.0, 0.0} // G - GAP
+
+ };
}
+ private int getSubstitutionMatrixIndex(char ss) {
+ switch (ss) {
+ case 'C':
+ return 0;
+ case 'E':
+ return 1;
+ case 'H':
+ return 2;
+ case 'G':
+ return 3;
+ default:
+ throw new IllegalArgumentException("Invalid secondary structure character: " + ss);
+ }
+ }
@Override
public String getName()
{
return true;
}
-
- @Override
- public boolean isSecondaryStructure()
- {
- return false;
- }
@Override
public String getDescription()
// TODO getName, isDNA, isProtein can be static methods in Java 8
- boolean isSecondaryStructure();
+ default public boolean isSecondaryStructure()
+ {
+ return false;
+ }
/**
+ * Answers false by default
* Answers true if the data has secondary structure (so should be
* shown in menus in that context)
*
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
+import jalview.analysis.AlignmentUtils;
import jalview.analysis.TreeBuilder;
import jalview.analysis.scoremodels.ScoreModels;
import jalview.analysis.scoremodels.SimilarityParams;
private static final int MIN_PCA_SELECTION = 4;
- private static final String SS_ANNOTATION_LABEL = "Secondary Structure";
+ private String secondaryStructureModelName;
- private static final String SS_ANNOTATION_FROM_JPRED_LABEL = "jnetpred";
+ private void getSecondaryStructureModelName() {
+
+ ScoreModels scoreModels = ScoreModels.getInstance();
+ for (ScoreModelI sm : scoreModels.getModels())
+ {
+ if (sm.isSecondaryStructure())
+ {
+ secondaryStructureModelName = sm.getName();
+ }
+ }
+
+ }
AlignFrame af;
this.af = alignFrame;
init();
af.alignPanel.setCalculationDialog(this);
+
}
/**
*/
void init()
{
+ getSecondaryStructureModelName();
setLayout(new BorderLayout());
frame = new JInternalFrame();
frame.setFrameIcon(null);
* score models drop-down - with added tooltips!
*/
modelNames = buildModelOptionsList();
+
// Step 3: Show or Hide Dropdown Based on Selection
modelNames.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String selectedModel = modelNames.getSelectedItem().toString();
- if (selectedModel.equals("Secondary Structure Similarity")) {
+
+ if (selectedModel.equals(secondaryStructureModelName)) {
ssSourceDropdown.setVisible(true);
} else {
ssSourceDropdown.setVisible(false);
}
});
+
JPanel scoreModelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
scoreModelPanel.setOpaque(false);
scoreModelPanel.add(modelNames);
* select the score models applicable to the alignment type
*/
boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
- AlignmentAnnotation[] alignmentAnnotation = af.getViewport().getAlignment().getAlignmentAnnotation();
-
- boolean ssPresent = false;
+ AlignmentAnnotation[] alignmentAnnotations = af.getViewport().getAlignment().getAlignmentAnnotation();
- for (AlignmentAnnotation aa : alignmentAnnotation)
-
- {
- if(ssPresent) {
- break;
- }
-
- if (aa.label.equals("Secondary Structure") || aa.label.equals("jnetpred"))
-
- {
- ssPresent = true;
- break;
- }
- }
+ boolean ssPresent = AlignmentUtils.isSecondaryStructurePresent(alignmentAnnotations);
List<ScoreModelI> models = getApplicableScoreModels(nucleotide, pca.isSelected(),
ssPresent);
}
// finally, update the model
comboBox.setModel(model);
+
}
/**
protected List<String> getApplicableSecondaryStructureSources()
{
- List<String> ssSources = new ArrayList<>();
-
AlignmentAnnotation[] annotations = af.getViewport().getAlignment().getAlignmentAnnotation();
- boolean has3DStructure = false, hasJPred = false;
- if(annotations.length > 0) {
-
- for (AlignmentAnnotation annotation : annotations) {
- has3DStructure |= SS_ANNOTATION_LABEL.equals(annotation.label);
- hasJPred |= SS_ANNOTATION_FROM_JPRED_LABEL.equals(annotation.label);
-
- if (has3DStructure && hasJPred)
- break;
- }
- }
- if(has3DStructure)
- ssSources.add("3D Structures");
- if(hasJPred)
- ssSources.add("JPred");
+
+ List<String> ssSources = AlignmentUtils.getSecondaryStructureSources(annotations);
return ssSources;
}
*/
SimilarityParamsI params = new SimilarityParams(false, true, true, true);
+ params.setSecondaryStructureSource("3D Structures");
MatrixI distances = sm.findDistances(view, params);
assertEquals(distances.getValue(0, 0), 0d);
assertEquals(distances.getValue(1, 1), 0d);
* score = 0 + 0 + 2 + 2 = 4/4
*/
SimilarityParamsI params = new SimilarityParams(false, true, true, true);
+ params.setSecondaryStructureSource("3D Structures");
MatrixI distances = sm.findDistances(view, params);
assertEquals(distances.getValue(0, 0), 0d);
assertEquals(distances.getValue(1, 1), 0d);
* score = 2 + 2 + 2 + 2 = 8/4
*/
SimilarityParamsI params = new SimilarityParams(false, true, true, true);
+ params.setSecondaryStructureSource("3D Structures");
MatrixI distances = sm.findDistances(view, params);
assertEquals(distances.getValue(0, 0), 0d);
assertEquals(distances.getValue(1, 1), 0d);
* score = 2 + 2 + 2 + 2 = 8/4
*/
SimilarityParamsI params = new SimilarityParams(false, true, true, true);
+ params.setSecondaryStructureSource("3D Structures");
MatrixI distances = sm.findDistances(view, params);
assertEquals(distances.getValue(0, 0), 0d);
assertEquals(distances.getValue(1, 1), 0d);
* score = 0 + 0 + 1 + 0 = 1/4
*/
SimilarityParamsI params = new SimilarityParams(false, true, true, true);
+ params.setSecondaryStructureSource("3D Structures");
MatrixI distances = sm.findDistances(view, params);
assertEquals(distances.getValue(0, 0), 0d);
assertEquals(distances.getValue(1, 1), 0d);
* score = 0 + 0 + 2 + 2 = 2/4
*/
SimilarityParamsI params = new SimilarityParams(false, true, true, true);
+ params.setSecondaryStructureSource("3D Structures");
MatrixI distances = sm.findDistances(view, params);
assertEquals(distances.getValue(0, 0), 0d);
assertEquals(distances.getValue(1, 1), 0d);
*/
SimilarityParamsI params2 = new SimilarityParams(false, true, false, true);
+ params2.setSecondaryStructureSource("3D Structures");
MatrixI distances2 = sm.findDistances(view, params2);
assertEquals(distances2.getValue(0, 1), 2d);
assertEquals(distances2.getValue(1, 0), 2d);
* score = 0 + 0 + 2 + 2 = 2/4
*/
SimilarityParamsI params = new SimilarityParams(false, true, true, true);
+ params.setSecondaryStructureSource("3D Structures");
MatrixI distances = sm.findDistances(view, params);
assertEquals(distances.getValue(0, 0), 0d);
assertEquals(distances.getValue(1, 1), 0d);
*/
SimilarityParamsI params2 = new SimilarityParams(false, true, false, true);
+ params2.setSecondaryStructureSource("3D Structures");
MatrixI distances2 = sm.findDistances(view, params2);
assertEquals(distances2.getValue(0, 1), 0d);
assertEquals(distances2.getValue(1, 0), 0d);