From 57d5410a932ce5caba3b913c2a27e1a24e012220 Mon Sep 17 00:00:00 2001 From: James Procter Date: Thu, 30 Nov 2023 15:39:14 +0000 Subject: [PATCH] JAL-4342 test and patch checking annotation csv export contains the annotations on the alignment or a specific exported annotation --- src/jalview/gui/AnnotationExporter.java | 18 +++++-- test/jalview/io/AnnotationExporterTest.java | 77 +++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 test/jalview/io/AnnotationExporterTest.java diff --git a/src/jalview/gui/AnnotationExporter.java b/src/jalview/gui/AnnotationExporter.java index 894db79..a23496d 100644 --- a/src/jalview/gui/AnnotationExporter.java +++ b/src/jalview/gui/AnnotationExporter.java @@ -163,6 +163,14 @@ public class AnnotationExporter extends JPanel frame.setTitle(MessageManager.getString("label.export_annotations")); } + public void setExportAsCSV() + { + if (CSVFormat != null) + { + CSVFormat.setSelected(true); + } + } + private void toFile_actionPerformed() { // TODO: JAL-3048 JalviewFileChooser - Save option @@ -202,7 +210,7 @@ public class AnnotationExporter extends JPanel * * @return */ - private String getText() + public String getText() { return exportFeatures ? getFeaturesText() : getAnnotationsText(); } @@ -213,12 +221,14 @@ public class AnnotationExporter extends JPanel * * @return */ - private String getAnnotationsText() + public String getAnnotationsText() { String text; if (CSVFormat.isSelected()) { - text = new AnnotationFile().printCSVAnnotations(annotations); + text = new AnnotationFile().printCSVAnnotations( + wholeView ? ap.av.getAlignment().getAlignmentAnnotation() + : annotations); } else { @@ -241,7 +251,7 @@ public class AnnotationExporter extends JPanel * * @return */ - private String getFeaturesText() + public String getFeaturesText() { String text; SequenceI[] sequences = ap.av.getAlignment().getSequencesArray(); diff --git a/test/jalview/io/AnnotationExporterTest.java b/test/jalview/io/AnnotationExporterTest.java new file mode 100644 index 0000000..6a627d8 --- /dev/null +++ b/test/jalview/io/AnnotationExporterTest.java @@ -0,0 +1,77 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.io; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; +import static org.testng.AssertJUnit.assertNotNull; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import jalview.datamodel.AlignmentAnnotation; +import jalview.gui.AlignFrame; +import jalview.gui.AnnotationExporter; +import jalview.gui.JvOptionPane; + +public class AnnotationExporterTest +{ + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + + @Test(groups = "Functional") + public void testAnnotationExportAsCSV() + { + /* + * JAL-4342 test that export all alignment annotation as CSV or as an annotations file DOES NOT produce empty text box/file + */ + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( + ">Seq1\nQRSIL\n>Seq2\nFTHND\n>Seq3\nRPVSL\n", + DataSourceType.PASTE); + AlignmentAnnotation[] annots = af.alignPanel.getAlignment() + .getAlignmentAnnotation(); + + assertTrue(annots.length > 1); + // set up exporter + AnnotationExporter ae = new AnnotationExporter(af.alignPanel); + ae.exportAnnotations(); + ae.setExportAsCSV(); + + String exported; + exported = ae.getAnnotationsText(); + assertNotNull(exported); + assertTrue(exported.contains(annots[0].label)); + assertTrue(exported.contains(annots[1].label)); + + // just one annotation row + ae.exportAnnotation(annots[1]); + exported = ae.getAnnotationsText(); + assertNotNull(exported); + assertFalse(exported.contains(annots[0].label)); + assertTrue(exported.contains(annots[1].label)); + + } +} -- 1.7.10.2