From: Renia Correya Date: Tue, 3 Sep 2024 18:16:24 +0000 (+0530) Subject: Merge branch 'develop' into feature/JAL-4386_calculate_tree_using_secondary_structure... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c52a3a6cdf7d0e05ff3ca5e11ab60e95038c73fe;p=jalview.git Merge branch 'develop' into feature/JAL-4386_calculate_tree_using_secondary_structure_annotation # Conflicts: # src/jalview/analysis/AAFrequency.java # src/jalview/analysis/AlignmentUtils.java # src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java # src/jalview/api/AlignViewportI.java # src/jalview/datamodel/Profile.java # src/jalview/datamodel/SequenceGroup.java # src/jalview/gui/AlignFrame.java # src/jalview/gui/AlignViewport.java # src/jalview/gui/PopupMenu.java # src/jalview/jbgui/GAlignFrame.java # src/jalview/project/Jalview2XML.java # src/jalview/renderer/AnnotationRenderer.java # src/jalview/renderer/ResidueShader.java # src/jalview/renderer/ResidueShaderI.java # src/jalview/util/Constants.java # src/jalview/viewmodel/AlignmentViewport.java # src/jalview/workers/SecondaryStructureConsensusThread.java # test/jalview/analysis/AlignmentUtilsTests.java --- c52a3a6cdf7d0e05ff3ca5e11ab60e95038c73fe diff --cc src/jalview/analysis/AAFrequency.java index 7278a80,0fa80b3..7ff77af --- a/src/jalview/analysis/AAFrequency.java +++ b/src/jalview/analysis/AAFrequency.java @@@ -192,15 -194,14 +192,14 @@@ public class AAFrequenc // jalview.bin.Console.outPrintln(elapsed); } - public static final ProfilesI calculateSS(List list, int start, - int end) + int end, String source) { - return calculateSS(list, start, end, false); + return calculateSS(list, start, end, false, source); } - + public static final ProfilesI calculateSS(List sequences, - int start, int end, boolean profile) + int start, int end, boolean profile, String source) { SequenceI[] seqs = new SequenceI[sequences.size()]; int width = 0; @@@ -226,15 -226,13 +225,15 @@@ return reply; } } - + public static final ProfilesI calculateSS(final SequenceI[] sequences, - int width, int start, int end, boolean saveFullProfile) + int width, int start, int end, boolean saveFullProfile, String source) { int seqCount = sequences.length; + + int seqWithSSCount = 0; - + ProfileI[] result = new ProfileI[width]; for (int column = start; column < end; column++) @@@ -252,42 -250,40 +251,42 @@@ "WARNING: Consensus skipping null sequence - possible race condition."); continue; } - + char c = sequences[row].getCharAt(column); - AlignmentAnnotation aa = AlignmentUtils - .getDisplayedAlignmentAnnotation(sequences[row]); - if (aa != null) - { - ssCount++; - } - - if (sequences[row].getLength() > column && !Comparison.isGap(c) - && aa != null) - { - - int seqPosition = sequences[row].findPosition(column); + - char ss = AlignmentUtils.findSSAnnotationForGivenSeqposition(aa, - seqPosition); - if (ss == '*') - { - continue; + List annots = AlignmentUtils.getAlignmentAnnotationForSource(sequences[row], source); + if(annots!=null) { + seqWithSSCount++; + for(AlignmentAnnotation aa:annots) { + if(aa!=null) { + ssCount++; + } + + if (sequences[row].getLength() > column && !Comparison.isGap(c) && aa !=null) + { + + int seqPosition = sequences[row].findPosition(column); + + char ss = AlignmentUtils.findSSAnnotationForGivenSeqposition( + aa, seqPosition); + if(ss == '*') { + continue; + } + ssCounts.add(ss); + } + else if(Comparison.isGap(c) && aa!=null) { + ssCounts.addGap(); + } } - ssCounts.add(ss); - } - else if (Comparison.isGap(c) && aa != null) - { - ssCounts.addGap(); } } int maxSSCount = ssCounts.getModalCount(); String maxSS = ssCounts.getSSForCount(maxSSCount); int gapCount = ssCounts.getGapCount(); - ProfileI profile = new Profile(maxSS, ssCount, gapCount, maxSSCount); + ProfileI profile = new Profile(maxSS, ssCount, gapCount, + maxSSCount, seqWithSSCount); - if (saveFullProfile) { profile.setSSCounts(ssCounts); @@@ -420,41 -415,32 +418,41 @@@ * happens if sequences calculated over were * shorter than alignment width */ - ssConsensus.annotations[i] = null; - return; - } - - final int dp = getPercentageDp(nseq); + ssConsensus.annotations[i] = null; + return; + } + + if(ssConsensus.getNoOfSequencesIncluded()<0) { + ssConsensus.setNoOfSequencesIncluded(profile.getSeqWithSSCount()); + } + + final int dp = getPercentageDp(nseq); - float value = profile.getSSPercentageIdentity(ignoreGaps); + float value = profile.getSSPercentageIdentity(ignoreGaps); - String description = getSSTooltip(profile, value, showSequenceLogo, - ignoreGaps, dp); + String description = getSSTooltip(profile, value, showSequenceLogo, + ignoreGaps, dp); - String modalSS = profile.getModalSS(); - if ("".equals(modalSS)) - { - modalSS = "-"; - } - else if (modalSS.length() > 1) - { - modalSS = "+"; - } - ssConsensus.annotations[i] = new Annotation(modalSS, description, ' ', - value); - } - // long elapsed = System.currentTimeMillis() - now; - // jalview.bin.Console.outPrintln(-elapsed); - } + String modalSS = profile.getModalSS(); + if ("".equals(modalSS)) + { + modalSS = "-"; + } + else if (modalSS.length() > 1) + { + modalSS = "+"; + } + ssConsensus.annotations[i] = new Annotation(modalSS, description, + ' ', value); + } + + //Hide consensus with no data to display + if(ssConsensus.getNoOfSequencesIncluded()<1) + ssConsensus.visible = false; + + // long elapsed = System.currentTimeMillis() - now; + // jalview.bin.Console.outPrintln(-elapsed); + } /** * Derive the gap count annotation row. diff --cc src/jalview/analysis/AlignmentUtils.java index d78bcdc,ba74f67..f103a8a --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@@ -2937,11 -2915,11 +2939,11 @@@ public class AlignmentUtil return Color.red; } - return Color.gray; + return Color.white; } - public static char findSSAnnotationForGivenSeqposition(AlignmentAnnotation aa, - int seqPosition) + public static char findSSAnnotationForGivenSeqposition( + AlignmentAnnotation aa, int seqPosition) { char ss = '*'; @@@ -3136,56 -3058,30 +3138,83 @@@ } + public static Map> getSequenceAssociatedAlignmentAnnotations( + AlignmentAnnotation[] alignAnnotList, String selectedSSSource) + { + + Map> ssAlignmentAnnotationForSequences + = new HashMap>(); + if (alignAnnotList == null || alignAnnotList.length == 0) + { + return ssAlignmentAnnotationForSequences; + } + + for (AlignmentAnnotation aa : alignAnnotList) + { + if (aa.sequenceRef == null) + { + continue; + } + + for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) + { + + if (label.equals(aa.label)) + { + + if (Constants.SS_ALL_PROVIDERS.equals(selectedSSSource)) + { + ssAlignmentAnnotationForSequences + .computeIfAbsent(aa.sequenceRef.getDatasetSequence(), + k -> new ArrayList<>()) + .add(aa); + break; + } + + String ssSource = AlignmentUtils + .extractSSSourceFromAnnotationDescription(aa); + if (ssSource != null && ssSource.equals(selectedSSSource)) + { + + ssAlignmentAnnotationForSequences + .computeIfAbsent(aa.sequenceRef.getDatasetSequence(), + k -> new ArrayList<>()) + .add(aa); + break; + } + } + } + } + + return ssAlignmentAnnotationForSequences; + + } - ++ ++ + // to do set priority for labels + public static AlignmentAnnotation getDisplayedAlignmentAnnotation( + SequenceI seq) + { + + for (String ssLabel : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) + { + + AlignmentAnnotation[] aa = seq.getAnnotation(ssLabel); + if (aa != null) + { + + for (AlignmentAnnotation annot : aa) + { + if (annot.visible) + { + return annot; + } + } + } + } + + return null; + + } + } diff --cc src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java index d7859f1,473abcf..3068b55 --- a/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java +++ b/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java @@@ -106,26 -109,30 +109,26 @@@ public class SecondaryStructureDistance @Override public MatrixI findDistances(AlignmentView seqData, SimilarityParamsI params) - { - + { + SeqCigar[] seqs = seqData.getSequences(); - int noseqs = seqs.length; // no of sequences - int cpwidth = 0; // = seqData.getWidth(); - double[][] similarities = new double[noseqs][noseqs]; // matrix to store - // similarity score - // secondary structure source parameter selected by the user from the drop - // down. - String ssSource = params.getSecondaryStructureSource(); - ssRateMatrix = ScoreModels.getInstance().getSecondaryStructureMatrix(); - - // defining the default value for secondary structure source as 3d - // structures - // or JPred if user selected JPred - String selectedSSSource = Constants.SS_ANNOTATION_LABEL; - if (ssSource.equals(Constants.SECONDARY_STRUCTURE_LABELS - .get(Constants.SS_ANNOTATION_FROM_JPRED_LABEL))) - { - selectedSSSource = Constants.SS_ANNOTATION_FROM_JPRED_LABEL; + int noseqs = seqs.length; //no of sequences + int cpwidth = 0; + double[][] similarities = new double[noseqs][noseqs]; //matrix to store similarity score + //secondary structure source parameter selected by the user from the drop down. + String ssSource = params.getSecondaryStructureSource(); + if(ssSource == null || ssSource == "") { + ssSource = Constants.SS_ALL_PROVIDERS; } - + ssRateMatrix = ScoreModels.getInstance().getSecondaryStructureMatrix(); + // need to get real position for view position int[] viscont = seqData.getVisibleContigs(); + + + AlignmentAnnotation[] alignAnnotList = fr.getViewport().getAlignment() + .getAlignmentAnnotation(); + /* * Add secondary structure annotations that are added to the annotation track @@@ -158,54 -193,62 +162,51 @@@ */ for (int i = 0; i < (noseqs - 1); i++) { - //Iterates for each sequences + // Iterates for each sequences for (int j = i + 1; j < noseqs; j++) { - SeqCigar sc1 = seqs[i]; - SeqCigar sc2 = seqs[j]; - - // check if ss is defined - boolean undefinedSS1 = seqsWithUndefinedSS.contains(sc1); - boolean undefinedSS2 = seqsWithUndefinedSS.contains(sc2); + + //check if ss is defined + boolean undefinedSS1 = ssAlignmentAnnotationForSequences.get(seqs[i].getRefSeq()) == null; + boolean undefinedSS2 = ssAlignmentAnnotationForSequences.get(seqs[j].getRefSeq()) == null; // Set similarity to max score if both SS are not defined - if (undefinedSS1 && undefinedSS2) { - similarities[i][j] += ssRateMatrix.getMaximumScore(); - continue; - } - - // Set similarity to minimum score if either one SS is not defined - else if(undefinedSS1 || undefinedSS2) { - similarities[i][j] += ssRateMatrix.getMinimumScore(); - continue; + if (undefinedSS1 && undefinedSS2) + { + similarities[i][j] += ssRateMatrix.getMaximumScore(); + continue; } - - // Set similarity to minimum score if either one SS is not defined - else if (undefinedSS1 || undefinedSS2) - { - similarities[i][j] += ssRateMatrix.getMinimumScore(); - continue; - } - - // check if the sequence contains gap in the current column - boolean gap1 = !seqsWithoutGapAtCol.contains(sc1); - boolean gap2 = !seqsWithoutGapAtCol.contains(sc2); - - // Variable to store secondary structure at the current column + + //check if the sequence contains gap in the current column + boolean gap1 = !seqsWithoutGapAtCol.contains(seqs[i]); + boolean gap2 = !seqsWithoutGapAtCol.contains(seqs[j]); + + //Variable to store secondary structure at the current column char ss1 = '*'; char ss2 = '*'; - - //secondary structure is fetched only if the current column is not - //gap for the sequence - if(!gap1 && !undefinedSS1) { - //fetch the position in sequence for the column and finds the - //corresponding secondary structure annotation - //TO DO - consider based on priority and displayed + + // secondary structure is fetched only if the current column is not + // gap for the sequence + if (!gap1 && !undefinedSS1) + { + // fetch the position in sequence for the column and finds the + // corresponding secondary structure annotation + // TO DO - consider based on priority and displayed int seqPosition = seqs[i].findPosition(cpos); - AlignmentAnnotation[] aa = seqs[i].getRefSeq() - .getAnnotation(selectedSSSource); - if (aa != null) - ss1 = AlignmentUtils.findSSAnnotationForGivenSeqposition( - aa[0], seqPosition); + AlignmentAnnotation aa = ssAlignmentAnnotationForSequences.get(seqs[i].getRefSeq()).get(0); + if(aa!=null) + ss1 = + AlignmentUtils.findSSAnnotationForGivenSeqposition(aa, seqPosition); } - - if(!gap2 && !undefinedSS2) { + + if (!gap2 && !undefinedSS2) + { int seqPosition = seqs[j].findPosition(cpos); - AlignmentAnnotation[] aa = seqs[j].getRefSeq() - .getAnnotation(selectedSSSource); - if (aa != null) - ss2 = AlignmentUtils.findSSAnnotationForGivenSeqposition( - aa[0], seqPosition); - } + AlignmentAnnotation aa = ssAlignmentAnnotationForSequences.get(seqs[j].getRefSeq()).get(0); + if(aa!=null) + ss2 = + AlignmentUtils.findSSAnnotationForGivenSeqposition(aa, seqPosition); + } if ((!gap1 && !gap2) || params.includeGaps()) { @@@ -264,7 -308,71 +266,6 @@@ return seqsWithoutGapAtCol; } - - /** - * Builds and returns a set containing sequences (SeqCigar) which are not - * considered for the similarity calculation. Following sequences are added: - * 1. Sequences without a defined secondary structure from the selected - * source. 2. Sequences whose secondary structure annotations are not added to - * the annotation track - * - * @param seqs - * @param ssAlignmentAnnotationForSequences - * @return - */ - private Set findSeqsWithUndefinedSS(SeqCigar[] seqs, - Map> ssAlignmentAnnotationForSequences) - { - Set seqsWithUndefinedSS = new HashSet<>(); - for (SeqCigar seq : seqs) - { - if (isSSUndefinedOrNotAdded(seq, ssAlignmentAnnotationForSequences)) - { - seqsWithUndefinedSS.add(seq); - } - } - return seqsWithUndefinedSS; - } - - /** - * Returns true if a sequence (SeqCigar) should not be considered for the - * similarity calculation. Following conditions are checked: 1. Sequence - * without a defined secondary structure from the selected source. 2. - * Sequences whose secondary structure annotations are not added to the - * annotation track - * - * @param seq - * @param ssAlignmentAnnotationForSequences - * @return - */ - private boolean isSSUndefinedOrNotAdded(SeqCigar seq, - Map> ssAlignmentAnnotationForSequences) - { - for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet()) - { - AlignmentAnnotation[] annotations = seq.getRefSeq() - .getAnnotation(label); - if (annotations != null) - { - for (AlignmentAnnotation annotation : annotations) - { - HashSet descriptionSet = ssAlignmentAnnotationForSequences - .get(annotation.sequenceRef.getName()); - if (descriptionSet != null) - { - if (descriptionSet.contains(annotation.description)) - { - // Secondary structure annotation is present and - // added to the track, no need to add seq - return false; - } - } - } - } - } - // Either annotations are undefined or not added to the track - return true; - } - @Override public String getName() { diff --cc src/jalview/api/AlignViewportI.java index 2cdb251,ef4a192..64e06ee --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@@ -129,10 -133,9 +129,9 @@@ public interface AlignViewportI extend * @return */ AlignmentAnnotation getAlignmentConsensusAnnotation(); - - AlignmentAnnotation getAlignmentSecondaryStructureConsensusAnnotation(); + + List getAlignmentSecondaryStructureConsensusAnnotation(); - /** * get the container for alignment gap annotation * @@@ -178,9 -181,8 +177,8 @@@ * @param hconsensus */ void setSequenceConsensusHash(ProfilesI hconsensus); - - void setSequenceSSConsensusHash(ProfilesI hSSConsensus); + + void setSequenceSSConsensusHash(Map hSSConsesnusProfileMap); - /** * Set the cDNA complement consensus for the viewport diff --cc src/jalview/datamodel/Profile.java index bc87204,2204de6..ae538f9 --- a/src/jalview/datamodel/Profile.java +++ b/src/jalview/datamodel/Profile.java @@@ -32,10 -32,8 +32,10 @@@ public class Profile implements Profile * an object holding counts of symbols in the profile */ private ResidueCount counts; - + private SecondaryStructureCount ssCounts; + + private int seqWithSSCount = -1; /* * the number of sequences (gapped or not) in the profile diff --cc src/jalview/datamodel/SequenceGroup.java index 38104e5,8cd92bc..571a369 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@@ -136,8 -132,9 +136,7 @@@ public class SequenceGroup implements A * consensus calculation property */ private boolean showSequenceLogo = false; - - private boolean showSequenceSSLogo = false; - /** * flag indicating if logo should be rendered normalised */ @@@ -154,19 -151,16 +153,18 @@@ private boolean hidecols = false; AlignmentAnnotation consensus = null; - - AlignmentAnnotation ssConsensus = null; + List ssConsensus = null; + + List secondaryStructureSources = null; AlignmentAnnotation conservation = null; private boolean showConsensusHistogram; - + - private boolean showSSConsensusHistogram; - private AnnotatedCollectionI context; + + public Map hSSConsensusProfileMap; /** * Creates a new SequenceGroup object. @@@ -633,38 -617,19 +631,36 @@@ cs.setConsensus(cnsns); upd = true; } + + hSSConsensusProfileMap = new HashMap(); + List ssSources = new ArrayList(); + AnnotatedCollectionI aa = this.getContext(); + + if(aa !=null ) + { + ssSources = AlignmentUtils.extractSSSourceInAlignmentAnnotation(aa.getAlignmentAnnotation()); + } + if(ssSources != null) { + ssSources.add(Constants.SS_ALL_PROVIDERS); - ProfilesI ssCnsns = AAFrequency.calculateSS(sequences, startRes, - endRes + 1, showSequenceLogo); + for(String ssSource : ssSources) { + ProfilesI hSSConsensus = AAFrequency.calculateSS(sequences, startRes, endRes + 1, showSequenceLogo, + ssSource); + hSSConsensusProfileMap.put(ssSource, hSSConsensus); + } + } + - if (ssConsensus != null) { - _updateSSConsensusRow(ssCnsns, sequences.size()); + _updateSSConsensusRow(hSSConsensusProfileMap, sequences.size()); upd = true; } + if (cs != null) { - cs.setSsConsensus(ssCnsns); + cs.setSSConsensusProfileMap(hSSConsensusProfileMap); upd = true; } - if ((conservation != null) || (cs != null && cs.conservationApplied())) @@@ -1429,7 -1329,19 +1425,7 @@@ } this.showSequenceLogo = showSequenceLogo; } - + - public void setshowSequenceSSLogo(boolean showSequenceSSLogo) - { - // TODO: decouple calculation from settings update - if (this.showSequenceSSLogo != showSequenceSSLogo - && ssConsensus != null) - { - this.showSequenceSSLogo = showSequenceSSLogo; - recalcConservation(); - } - this.showSequenceSSLogo = showSequenceSSLogo; - } - /** * * @param showConsHist @@@ -1447,6 -1359,17 +1443,7 @@@ this.showConsensusHistogram = showConsHist; } - public void setShowSSConsensusHistogram(boolean showSSConsHist) - { - - if (showSSConsensusHistogram != showSSConsHist && consensus != null) - { - this.showSSConsensusHistogram = showSSConsHist; - recalcConservation(); - } - this.showSSConsensusHistogram = showSSConsHist; - } + /** * @return the showConsensusHistogram */ diff --cc src/jalview/gui/AlignFrame.java index 7a06638,c81a5de..a624a66 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@@ -5911,11 -5830,19 +5911,10 @@@ public class AlignFrame extends GAlignF } - protected String getSelectedRadioButtonDisplayString( - ButtonGroup ssButtonGroup) + protected void showSSConsensus_actionPerformed(ActionEvent e) { - Enumeration buttons = ssButtonGroup.getElements(); - while (buttons.hasMoreElements()) - { - AbstractButton button = buttons.nextElement(); - if (button.isSelected()) - { - return button.getText(); - } - } - return null; // No radio button is selected + viewport.setShowSSConsensus(showSSConsensus.getState()); + alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); - } /* @@@ -5969,6 -5888,14 +5968,7 @@@ alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); } - @Override - protected void showSSConsensusHistogram_actionPerformed(ActionEvent e) - { - viewport.setShowSSConsensusHistogram( - showSSConsensusHistogram.getState()); - alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); - } + /* * (non-Javadoc) * diff --cc src/jalview/gui/PopupMenu.java index a47a0a1,f4dd579..403a52e --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@@ -1971,34 -1764,30 +1971,34 @@@ public class PopupMenu extends JPopupMe { final AlignmentI alignment = this.ap.getAlignment(); AlignmentUtils.addReferenceAnnotations(candidates, alignment, null); - - if (AlignmentUtils.isSSAnnotationPresent(candidates)) - { + + if(AlignmentUtils.isSSAnnotationPresent(candidates)) { + + restartSSConsensusWorker(); + ap.validateAnnotationDimensions(true); + ap.fontChanged(); + ap.av.alignmentChanged(ap); + ap.adjustAnnotationHeight(); restartSSConsensusWorker(); + //ap.alignFrame.getViewport().getCalcManager().restartWorkers(); } - - - refresh(); } - - - private void restartSSConsensusWorker() { - - List workers = ap.alignFrame.getViewport().getCalcManager() - .getRegisteredWorkersOfClass(SecondaryStructureConsensusThread.class); - if (!workers.isEmpty()) { - - ap.alignFrame.getViewport().getCalcManager().startWorker(workers.remove(0)); + + private void restartSSConsensusWorker() + { + + List workers = ap.alignFrame.getViewport() + .getCalcManager().getRegisteredWorkersOfClass( + SecondaryStructureConsensusThread.class); + if (!workers.isEmpty()) + { + + ap.alignFrame.getViewport().getCalcManager() + .startWorker(workers.remove(0)); } - + } - - protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent) { diff --cc src/jalview/jbgui/GAlignFrame.java index fa9626b,687c22b..e802646 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@@ -210,8 -207,10 +210,8 @@@ public class GAlignFrame extends JInter protected JCheckBoxMenuItem showGroupConservation = new JCheckBoxMenuItem(); - protected JCheckBoxMenuItem showConsensusHistogram = new JCheckBoxMenuItem(); + protected JCheckBoxMenuItem showConsensusHistogram = new JCheckBoxMenuItem(); - protected JCheckBoxMenuItem showSSConsensusHistogram = new JCheckBoxMenuItem(); - protected JCheckBoxMenuItem showSequenceLogo = new JCheckBoxMenuItem(); protected JCheckBoxMenuItem normaliseSequenceLogo = new JCheckBoxMenuItem(); @@@ -926,7 -889,19 +926,8 @@@ showConsensusHistogram_actionPerformed(e); } - }); - showSSConsensusHistogram.setText( - MessageManager.getString("label.show_ssconsensus_histogram")); - showSSConsensusHistogram.addActionListener(new ActionListener() - { + }); + - @Override - public void actionPerformed(ActionEvent e) - { - showConsensusHistogram_actionPerformed(e); - } - - }); showSequenceLogo .setText(MessageManager.getString("label.show_consensus_logo")); showSequenceLogo.addActionListener(new ActionListener() @@@ -1841,53 -1848,22 +1842,53 @@@ MessageManager.getString("label.autocalculated_annotation")); JMenu showSS = new JMenu( - MessageManager.getString("label.show_secondary_structure")); - - showSS.addMouseListener(new MouseAdapter() - { - + MessageManager.getString("label.show_secondary_structure")); + + JRadioButtonMenuItem radioButtonAllSS = new JRadioButtonMenuItem(MessageManager.getString("option.ss_providers_all")); + radioButtonAllSS.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + showOrHideSecondaryStructureForSource(MessageManager.getString("option.ss_providers_all"), true); + // Select all checkboxes if "All" is selected + Component[] components = showSS.getMenuComponents(); + for (Component component : components) { + if (component instanceof JCheckBoxMenuItem) { + ((JCheckBoxMenuItem) component).setSelected(true); + } + } + } + }); + ssButtonGroup.add(radioButtonAllSS); + showSS.add(radioButtonAllSS); + + JRadioButtonMenuItem radioButtonNoneSS = new JRadioButtonMenuItem(MessageManager.getString("option.ss_providers_none")); + radioButtonNoneSS.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + showOrHideSecondaryStructureForSource(MessageManager.getString("option.ss_providers_none"), false); + // Remove selection of all checkboxes if "None" is selected + Component[] components = showSS.getMenuComponents(); + for (Component component : components) { + if (component instanceof JCheckBoxMenuItem) { + ((JCheckBoxMenuItem) component).setSelected(false); + } + } + } + }); + ssButtonGroup.add(radioButtonNoneSS); + showSS.add(radioButtonNoneSS); + showSS.addSeparator(); + + annotationsMenu.addMouseListener(new MouseAdapter() { + @Override - public void mouseEntered(MouseEvent e) - { - - updateShowSSRadioButtons(showSS, ssButtonGroup); // Update radio buttons - // every time the menu - // is clicked + public void mouseEntered(MouseEvent e) { + updateShowSecondaryStructureMenu(showSS, ssButtonGroup); // Update radio buttons every time the menu is clicked + } }); - + JMenu exportImageMenu = new JMenu( MessageManager.getString("label.export_image")); JMenu fileMenu = new JMenu(MessageManager.getString("action.file")); @@@ -2947,16 -2880,15 +2948,16 @@@ return null; } - protected void updateShowSSRadioButtons(JMenu showSS, - ButtonGroup ssButtonGroup) + protected void showOrHideSecondaryStructureForSource(String ssSourceSelection, boolean visible) { // TODO Auto-generated method stub + } - protected void showSS_actionPerformed(String ssSourceSelection) + protected void updateShowSecondaryStructureMenu(JMenu showSS, + ButtonGroup ssButtonGroup) { // TODO Auto-generated method stub - + } } diff --cc src/jalview/project/Jalview2XML.java index 2a2225e,e2a5508..d2e369c --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@@ -5454,7 -5419,7 +5456,8 @@@ public class Jalview2XM viewport.getResidueShading() .setConsensus(viewport.getSequenceConsensusHash()); viewport.getResidueShading() - .setSsConsensus(viewport.getSequenceSSConsensusHash()); + .setSSConsensusProfileMap(viewport.getSequenceSSConsensusHash()); ++ if (safeBoolean(view.isConservationSelected()) && cs != null) { viewport.getResidueShading() diff --cc src/jalview/renderer/ResidueShader.java index 91f38c5,b9f3ee1..40c8a38 --- a/src/jalview/renderer/ResidueShader.java +++ b/src/jalview/renderer/ResidueShader.java @@@ -63,12 -61,21 +63,11 @@@ public class ResidueShader implements R * the consensus data for each column */ private ProfilesI consensus; - + /* - * the consensus data for each column - */ - private ProfilesI ssConsensus; - - public ProfilesI getSsConsensus() - { - return ssConsensus; - } - - public void setSsConsensus(ProfilesI ssConsensus) - { - this.ssConsensus = ssConsensus; - } + * the ss consensus data for each column for each source - */ - ++ */ + private Map ssConsensusProfileMap; /* * if true, apply shading of colour by conservation @@@ -303,9 -278,9 +302,9 @@@ return colour; } - + @Override - public Color findSSColour(char symbol, int position, SequenceI seq) + public Color findSSColour(char symbol, int position) { if (colourScheme == null) { diff --cc src/jalview/util/Constants.java index 27513ab,1321fb0..cefaa82 --- a/src/jalview/util/Constants.java +++ b/src/jalview/util/Constants.java @@@ -28,31 -28,25 +28,33 @@@ import java.util.Map */ public class Constants { - - //character used to represent secondary structures + + // character used to represent secondary structures public static final char HELIX = 'H'; + public static final char SHEET = 'E'; + public static final char COIL = 'C'; - //label in secondary structure annotation data model from 3d structures + // label in secondary structure annotation data model from 3d structures public static final String SS_ANNOTATION_LABEL = "Secondary Structure"; - - //label in secondary structure annotation data model from JPred - public static final String SS_ANNOTATION_FROM_JPRED_LABEL = "jnetpred"; - + + // label in secondary structure annotation data model from JPred + public static final String SS_ANNOTATION_FROM_JPRED_LABEL = "jnetpred"; + public static final Map SECONDARY_STRUCTURE_LABELS = new HashMap<>(); - static - { - SECONDARY_STRUCTURE_LABELS.put(SS_ANNOTATION_LABEL, "3D Structures"); - SECONDARY_STRUCTURE_LABELS.put(SS_ANNOTATION_FROM_JPRED_LABEL, "JPred"); - // Add other secondary structure labels here if needed - } + static { + SECONDARY_STRUCTURE_LABELS.put(SS_ANNOTATION_LABEL, "3D Structures"); + SECONDARY_STRUCTURE_LABELS.put(SS_ANNOTATION_FROM_JPRED_LABEL, "JPred"); + // Add other secondary structure labels here if needed + } + + public static final String SS_PROVIDER_PROPERTY = "SS_PROVIDER"; + + //generic secondary structure provider options + public static final String SS_ALL_PROVIDERS = "All"; + public static final String SS_NONE_PROVIDER = "None"; + + //Secondary structure consensus label + public static final String SECONDARY_STRUCTURE_CONSENSUS_LABEL = "Secondary Structure Consensus"; } diff --cc src/jalview/viewmodel/AlignmentViewport.java index 94a1424,ce4473b..8308992 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@@ -766,10 -722,8 +766,9 @@@ public abstract class AlignmentViewpor * results of alignment consensus analysis for visible portion of view */ protected ProfilesI hconsensus = null; - - protected ProfilesI hSSConsensus = null; + + protected Map hSSConsensusProfileMap = null; + - /** * results of cDNA complement consensus visible portion of view @@@ -833,13 -761,13 +832,13 @@@ { this.hconsensus = hconsensus; } - + @Override - public void setSequenceSSConsensusHash(ProfilesI hSSConsensus) + public void setSequenceSSConsensusHash(Map hSSConsensusProfileMap) { - this.hSSConsensus = hSSConsensus; + this.hSSConsensusProfileMap = hSSConsensusProfileMap; } - + @Override public void setComplementConsensusHash( Hashtable[] hconsensus) @@@ -898,9 -825,8 +897,8 @@@ return consensus; } - @Override - public AlignmentAnnotation getAlignmentSecondaryStructureConsensusAnnotation() + public List getAlignmentSecondaryStructureConsensusAnnotation() { return secondaryStructureConsensus; } @@@ -997,12 -922,9 +994,9 @@@ } } } - - - /** - * trigger update of consensus annotation + * trigger update of Secondary Structure consensus annotation */ public void updateSecondaryStructureConsensus(final AlignmentViewPanel ap) { @@@ -1011,43 -933,12 +1005,44 @@@ { return; } - if (calculator.getRegisteredWorkersOfClass( - SecondaryStructureConsensusThread.class) == null) + List ssSources = viewStyle.getSecondaryStructureSources(); + if (secondaryStructureConsensus.size() != ssSources.size()) { + + for(String source : ssSources) { + boolean ssConsensusForSourcePresent = false; + for(AlignmentAnnotation aa : secondaryStructureConsensus) { + if(aa.description.startsWith(source)) { + ssConsensusForSourcePresent = true; + break; + } + } + + if(!ssConsensusForSourcePresent) { + AlignmentAnnotation ssConsensus = new AlignmentAnnotation(MessageManager.getString("label.ssconsensus_label") + " "+source, + source + " " + MessageManager.getString("label.ssconsensus_descr"), + new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); + + ssConsensus.hasText = true; + ssConsensus.autoCalculated = true; + secondaryStructureConsensus.add(ssConsensus); + if (showSSConsensus) + { + ssConsensus.visible = true; + alignment.addAnnotation(ssConsensus); + + } + } + } + } + if (calculator + .getRegisteredWorkersOfClass(SecondaryStructureConsensusThread.class) == null) { - calculator.registerWorker(new SecondaryStructureConsensusThread(this, ap)); + calculator.registerWorker( + new SecondaryStructureConsensusThread(this, ap)); } + ap.adjustAnnotationHeight(); + + } // --------START Structure Conservation @@@ -1162,7 -1050,9 +1157,7 @@@ * should consensus profile be rendered by default */ protected boolean showSequenceLogo = false; - + - protected boolean showSequenceSSLogo = false; - /** * should consensus profile be rendered normalised to row height */ @@@ -1172,7 -1062,14 +1167,7 @@@ * should consensus histograms be rendered by default */ protected boolean showConsensusHistogram = true; - + - protected boolean showSSConsensusHistogram = true; - - public void setShowSSConsensusHistogram(boolean showSSConsensusHistogram) - { - this.showSSConsensusHistogram = showSSConsensusHistogram; - } - /** * @return the showConsensusProfile */ @@@ -1181,7 -1078,13 +1176,7 @@@ { return showSequenceLogo; } - + - @Override - public boolean isShowSequenceSSLogo() - { - return showSequenceSSLogo; - } - /** * @param showSequenceLogo * the new value @@@ -1196,14 -1099,23 +1191,14 @@@ calculator.updateAnnotationFor(ConsensusThread.class); calculator.updateAnnotationFor(ComplementConsensusThread.class); calculator.updateAnnotationFor(StrucConsensusThread.class); - } - this.showSequenceLogo = showSequenceLogo; - } + + //to do - public void setShowSequenceSSLogo(boolean showSequenceSSLogo) - { - if (showSequenceSSLogo != this.showSequenceSSLogo) - { - // TODO: decouple settings setting from calculation when refactoring - // annotation update method from alignframe to viewport - this.showSequenceSSLogo = showSequenceSSLogo; - calculator - .updateAnnotationFor(SecondaryStructureConsensusThread.class); + calculator.updateAnnotationFor(SecondaryStructureConsensusThread.class); } - this.showSequenceSSLogo = showSequenceSSLogo; + this.showSequenceLogo = showSequenceLogo; } - + /** * @param showConsensusHistogram * the showConsensusHistogram to set @@@ -1501,9 -1399,9 +1496,9 @@@ protected boolean showQuality = true; - protected boolean showConsensus = true; + protected boolean showConsensus = true; - protected boolean showSSConsensus = false; + protected boolean showSSConsensus = true; protected boolean showOccupancy = true; @@@ -2146,22 -2044,12 +2141,22 @@@ consensus = new AlignmentAnnotation("Consensus", MessageManager.getString("label.consensus_descr"), new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); - - secondaryStructureConsensus = new AlignmentAnnotation( - MessageManager.getString("label.ssconsensus_label"), - MessageManager.getString("label.ssconsensus_descr"), - new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); + setSecondaryStructureSources(alignment.getAlignmentAnnotation()); + List secondaryStructureSources = getSecondaryStructureSources(); + + if(secondaryStructureSources!=null) { + + secondaryStructureConsensus = new ArrayList(); + for (String ssSource : secondaryStructureSources) { + + AlignmentAnnotation ssConsensus = new AlignmentAnnotation(MessageManager.getString("label.ssconsensus_label") + " "+ssSource, + ssSource + " " + MessageManager.getString("label.ssconsensus_descr"), + new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH); + secondaryStructureConsensus.add(ssConsensus); + } + + } - + initConsensus(consensus); initSSConsensus(secondaryStructureConsensus); initGapCounts(); diff --cc src/jalview/workers/SecondaryStructureConsensusThread.java index 6629f27,945d99b..259d96b --- a/src/jalview/workers/SecondaryStructureConsensusThread.java +++ b/src/jalview/workers/SecondaryStructureConsensusThread.java @@@ -184,33 -167,11 +184,34 @@@ public class SecondaryStructureConsensu * * @return */ - protected AlignmentAnnotation getSSConsensusAnnotation() + protected List getSSConsensusAnnotation() { - return alignViewport.getAlignmentSecondaryStructureConsensusAnnotation(); + return alignViewport + .getAlignmentSecondaryStructureConsensusAnnotation(); } + + /** + * Get the Consensus annotation for the alignment + * + * @return + */ + protected void setSecondaryStructureSources() + { + List sources = null; + AlignmentAnnotation[] aa = alignViewport.getAlignment().getAlignmentAnnotation(); + if(aa!=null) { + sources = AlignmentUtils.extractSSSourceInAlignmentAnnotation(aa); + if(sources != null) { + sources.add(0, Constants.SS_ALL_PROVIDERS); + alignViewport.setSecondaryStructureSources(sources); + } + } + } + + protected List getSecondaryStructureSources() + { + return alignViewport.getSecondaryStructureSources(); + } /** * Get the Gap annotation for the alignment diff --cc test/jalview/analysis/AlignmentUtilsTests.java index 1cf9a80,67b9ad8..8946844 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@@ -2775,139 -2779,181 +2778,160 @@@ public class AlignmentUtilsTest && al.getAlignmentAnnotation().length == 2); } - - @Test(groups = "Functional", dataProvider = "SecondaryStructureAnnotations") - public void testSecondaryStructurePresentAndSources(AlignmentAnnotation[] annotations, boolean expectedSSPresent, ArrayList expectedSSSources) { - Assert.assertEquals(expectedSSPresent, AlignmentUtils.isSecondaryStructurePresent(annotations)); - } - @DataProvider(name = "SecondaryStructureAnnotations") - public static Object[][] provideSecondaryStructureAnnotations() { - AlignmentAnnotation ann1 = new AlignmentAnnotation("Secondary Structure", "Secondary Structure", new Annotation[]{}); - AlignmentAnnotation ann2 = new AlignmentAnnotation("jnetpred", "jnetpred", new Annotation[]{}); - AlignmentAnnotation ann3 = new AlignmentAnnotation("Temp", "Temp", new Annotation[]{}); - AlignmentAnnotation ann4 = new AlignmentAnnotation("Temp", "Temp", new Annotation[]{}); - - List ssSources1 = new ArrayList<>(Arrays.asList("3D Structures")); - List ssSources2 = new ArrayList<>(Arrays.asList("JPred")); - List ssSources3 = new ArrayList<>(Arrays.asList("3D Structures", "JPred")); - List ssSources4 = new ArrayList<>(); - - return new Object[][]{ - {new AlignmentAnnotation[]{ann1, ann3, ann4}, true, ssSources1}, - {new AlignmentAnnotation[]{ann2, ann3, ann4}, true, ssSources2}, - {new AlignmentAnnotation[]{ann3, ann4}, false, ssSources4}, - {new AlignmentAnnotation[]{}, false, ssSources4}, - {new AlignmentAnnotation[]{ann1, ann2, ann3, ann4}, true, ssSources3} - }; - } - - @Test(dataProvider = "SecondaryStructureAnnotationColours") - public void testSecondaryStructureAnnotationColour(char symbol, Color expectedColor) { - Color actualColor = AlignmentUtils.getSecondaryStructureAnnotationColour(symbol); - Assert.assertEquals(actualColor, expectedColor); - } - @Test( - groups = "Functional", - dataProvider = "SecondaryStructureAnnotations") - public void testSecondaryStructurePresentAndSources( - AlignmentAnnotation[] annotations, boolean expectedSSPresent, - ArrayList expectedSSSources) - { - Assert.assertEquals(expectedSSPresent, - AlignmentUtils.isSecondaryStructurePresent(annotations)); - Assert.assertEquals(expectedSSSources, - AlignmentUtils.getSecondaryStructureSources(annotations)); - } - @DataProvider(name = "SecondaryStructureAnnotationColours") - public static Object[][] provideSecondaryStructureAnnotationColours() { - return new Object[][]{ - {'C', Color.gray}, - {'E', Color.green}, - {'H', Color.red}, - {'-', Color.gray} - }; - } - - @Test(dataProvider = "SSAnnotationPresence") - public void testIsSSAnnotationPresent(Map> annotations, boolean expectedPresence) { - boolean actualPresence = AlignmentUtils.isSSAnnotationPresent(annotations); - Assert.assertEquals(actualPresence, expectedPresence); - } + @DataProvider(name = "SecondaryStructureAnnotations") + public static Object[][] provideSecondaryStructureAnnotations() + { + AlignmentAnnotation ann1 = new AlignmentAnnotation( + "Secondary Structure", "Secondary Structure", + new Annotation[] {}); + AlignmentAnnotation ann2 = new AlignmentAnnotation("jnetpred", + "jnetpred", new Annotation[] {}); + AlignmentAnnotation ann3 = new AlignmentAnnotation("Temp", "Temp", + new Annotation[] {}); + AlignmentAnnotation ann4 = new AlignmentAnnotation("Temp", "Temp", + new Annotation[] {}); - @DataProvider(name = "SSAnnotationPresence") - public static Object[][] provideSSAnnotationPresence() { - Map> annotations1 = new HashMap<>(); - SequenceI seq1 = new Sequence("Seq1", "ASD---ASD---ASD", 37, 45); - List annotationsList1 = new ArrayList<>(); - annotationsList1.add(new AlignmentAnnotation("Secondary Structure", "Secondary Structure", new Annotation[]{})); - annotations1.put(seq1, annotationsList1); // Annotation present secondary structure for seq1 - - Map> annotations2 = new HashMap<>(); - SequenceI seq2 = new Sequence("Seq2", "ASD---ASD------", 37, 42); - List annotationsList2 = new ArrayList<>(); - annotationsList2.add(new AlignmentAnnotation("Other Annotation", "Other Annotation", new Annotation[]{})); - annotations2.put(seq2, annotationsList2); // Annotation not related to any of secondary structure for seq2 - - Map> annotations3 = new HashMap<>(); - // Empty annotation map - - Map> annotations4 = new HashMap<>(); - SequenceI seq4 = new Sequence("Seq4", "ASD---ASD---AS-", 37, 44); - List annotationsList4 = new ArrayList<>(); - annotationsList4.add(new AlignmentAnnotation("jnetpred", "jnetpred", new Annotation[]{})); - annotations4.put(seq4, annotationsList4); // Annotation present from JPred for seq4 - - - return new Object[][]{ - {annotations1, true}, // Annotations present secondary structure present - {annotations2, false}, // No annotations related to any of the secondary structure present - {annotations3, false}, // Empty annotation map - {annotations4, true}, // Annotations present from JPred secondary structure present - }; - } - - @Test - public void testGetSSSourceFromAnnotationDescription(AlignmentAnnotation[] annotations, String expectedSSSource) { - List actualSSSource = AlignmentUtils.extractSSSourceInAlignmentAnnotation(annotations); - Assert.assertEquals(actualSSSource, expectedSSSource); - } - - @DataProvider(name = "SSSourceFromAnnotationDescription") - public static Object[][] provideSSSourceFromAnnotationDescription() { - Map> annotations1 = new HashMap<>(); - SequenceI seq1 = new Sequence("Seq1", "ASD---ASD---ASD", 37, 45); - List annotationsList1 = new ArrayList<>(); - annotationsList1.add(new AlignmentAnnotation("jnetpred", "JPred Output", new Annotation[]{})); - annotations1.put(seq1, annotationsList1); // Annotation present from JPred for seq1 - - Map> annotations2 = new HashMap<>(); - SequenceI seq2 = new Sequence("Seq2", "ASD---ASD------", 37, 42); - List annotationsList2 = new ArrayList<>(); - annotationsList2.add(new AlignmentAnnotation("Secondary Structure", - "Secondary Structure for af-q43517-f1A", new Annotation[]{})); - annotations2.put(seq2, annotationsList2); // Annotation present secondary structure from Alphafold for seq2 - - Map> annotations3 = new HashMap<>(); - // Empty annotation map - - Map> annotations4 = new HashMap<>(); - SequenceI seq4 = new Sequence("Seq4", "ASD---ASD---AS-", 37, 44); - List annotationsList4 = new ArrayList<>(); - annotationsList4.add(new AlignmentAnnotation("Secondary Structure", - "Secondary Structure for 4zhpA", new Annotation[]{})); - annotations4.put(seq4, annotationsList4); // Annotation present secondary structure from pdb for seq4 - - Map> annotations5 = new HashMap<>(); - SequenceI seq5 = new Sequence("Seq5", "ASD---ASD---AS-", 37, 44); - List annotationsList5 = new ArrayList<>(); - annotationsList5.add(new AlignmentAnnotation("Secondary Structure", - "Secondary Structure for p09911_54-147__3a7wzn.1.p3502557454997462030P", - new Annotation[]{})); - annotations5.put(seq5, annotationsList5); // Annotation present secondary structure from Swiss model for seq5 - - - //JPred Output - JPred - //Secondary Structure for af-q43517-f1A - Alphafold - //Secondary Structure for 4zhpA - Experimental - //Secondary Structure for p09911_54-147__3a7wzn.1.p3502557454997462030P - Swiss Model - - return new Object[][]{ - {annotations1, "JPred"}, - {annotations2, "Alphafold"}, - {annotations3, null}, - {annotations4, "PDB"}, - {annotations5, "Swiss Model"} - }; - } + List ssSources1 = new ArrayList<>( + Arrays.asList("3D Structures")); + List ssSources2 = new ArrayList<>(Arrays.asList("JPred")); + List ssSources3 = new ArrayList<>( + Arrays.asList("3D Structures", "JPred")); + List ssSources4 = new ArrayList<>(); + + return new Object[][] { + { new AlignmentAnnotation[] + { ann1, ann3, ann4 }, true, ssSources1 }, + { new AlignmentAnnotation[] + { ann2, ann3, ann4 }, true, ssSources2 }, + { new AlignmentAnnotation[] + { ann3, ann4 }, false, ssSources4 }, + { new AlignmentAnnotation[] {}, false, ssSources4 }, + { new AlignmentAnnotation[] + { ann1, ann2, ann3, ann4 }, true, ssSources3 } }; + } + + @Test(dataProvider = "SecondaryStructureAnnotationColours") + public void testSecondaryStructureAnnotationColour(char symbol, + Color expectedColor) + { + Color actualColor = AlignmentUtils + .getSecondaryStructureAnnotationColour(symbol); + Assert.assertEquals(actualColor, expectedColor); + } + + @DataProvider(name = "SecondaryStructureAnnotationColours") + public static Object[][] provideSecondaryStructureAnnotationColours() + { + return new Object[][] { { 'C', Color.gray }, { 'E', Color.green }, + { 'H', Color.red }, - { '-', Color.gray } }; ++ { '-', Color.white } }; + } + + @Test(dataProvider = "SSAnnotationPresence") + public void testIsSSAnnotationPresent( + Map> annotations, + boolean expectedPresence) + { + boolean actualPresence = AlignmentUtils + .isSSAnnotationPresent(annotations); + Assert.assertEquals(actualPresence, expectedPresence); + } + + @DataProvider(name = "SSAnnotationPresence") + public static Object[][] provideSSAnnotationPresence() + { + Map> annotations1 = new HashMap<>(); + SequenceI seq1 = new Sequence("Seq1", "ASD---ASD---ASD", 37, 45); + List annotationsList1 = new ArrayList<>(); + annotationsList1.add(new AlignmentAnnotation("Secondary Structure", + "Secondary Structure", new Annotation[] {})); + annotations1.put(seq1, annotationsList1); // Annotation present secondary + // structure for seq1 + + Map> annotations2 = new HashMap<>(); + SequenceI seq2 = new Sequence("Seq2", "ASD---ASD------", 37, 42); + List annotationsList2 = new ArrayList<>(); + annotationsList2.add(new AlignmentAnnotation("Other Annotation", + "Other Annotation", new Annotation[] {})); + annotations2.put(seq2, annotationsList2); // Annotation not related to any + // of secondary structure for seq2 + + Map> annotations3 = new HashMap<>(); + // Empty annotation map + + Map> annotations4 = new HashMap<>(); + SequenceI seq4 = new Sequence("Seq4", "ASD---ASD---AS-", 37, 44); + List annotationsList4 = new ArrayList<>(); + annotationsList4.add(new AlignmentAnnotation("jnetpred", "jnetpred", + new Annotation[] {})); + annotations4.put(seq4, annotationsList4); // Annotation present from JPred + // for seq4 + + return new Object[][] { { annotations1, true }, // Annotations present + // secondary structure + // present + { annotations2, false }, // No annotations related to any of the + // secondary structure present + { annotations3, false }, // Empty annotation map + { annotations4, true }, // Annotations present from JPred secondary + // structure present + }; + } + - @Test - public void testGetSSSourceFromAnnotationDescription( - AlignmentAnnotation[] annotations, String expectedSSSource) - { - List actualSSSource = AlignmentUtils - .extractSSSourceInAlignmentAnnotation(annotations); - Assert.assertEquals(actualSSSource, expectedSSSource); - } - + @DataProvider(name = "SSSourceFromAnnotationDescription") + public static Object[][] provideSSSourceFromAnnotationDescription() + { + Map> annotations1 = new HashMap<>(); + SequenceI seq1 = new Sequence("Seq1", "ASD---ASD---ASD", 37, 45); + List annotationsList1 = new ArrayList<>(); + annotationsList1.add(new AlignmentAnnotation("jnetpred", "JPred Output", + new Annotation[] {})); + annotations1.put(seq1, annotationsList1); // Annotation present from JPred + // for seq1 + + Map> annotations2 = new HashMap<>(); + SequenceI seq2 = new Sequence("Seq2", "ASD---ASD------", 37, 42); + List annotationsList2 = new ArrayList<>(); + annotationsList2.add(new AlignmentAnnotation("Secondary Structure", + "Secondary Structure for af-q43517-f1A", new Annotation[] {})); + annotations2.put(seq2, annotationsList2); // Annotation present secondary + // structure from Alphafold for + // seq2 + + Map> annotations3 = new HashMap<>(); + // Empty annotation map + + Map> annotations4 = new HashMap<>(); + SequenceI seq4 = new Sequence("Seq4", "ASD---ASD---AS-", 37, 44); + List annotationsList4 = new ArrayList<>(); + annotationsList4.add(new AlignmentAnnotation("Secondary Structure", + "Secondary Structure for 4zhpA", new Annotation[] {})); + annotations4.put(seq4, annotationsList4); // Annotation present secondary + // structure from pdb for seq4 + + Map> annotations5 = new HashMap<>(); + SequenceI seq5 = new Sequence("Seq5", "ASD---ASD---AS-", 37, 44); + List annotationsList5 = new ArrayList<>(); + annotationsList5.add(new AlignmentAnnotation("Secondary Structure", + "Secondary Structure for p09911_54-147__3a7wzn.1.p3502557454997462030P", + new Annotation[] {})); + annotations5.put(seq5, annotationsList5); // Annotation present secondary + // structure from Swiss model for + // seq5 + + // JPred Output - JPred + // Secondary Structure for af-q43517-f1A - Alphafold + // Secondary Structure for 4zhpA - Experimental + // Secondary Structure for p09911_54-147__3a7wzn.1.p3502557454997462030P - + // Swiss Model + + return new Object[][] { { annotations1, "JPred" }, + { annotations2, "Alphafold" }, + { annotations3, null }, + { annotations4, "PDB" }, + { annotations5, "Swiss Model" } }; + } }