From: tcofoegbu Date: Tue, 21 Jul 2015 16:59:01 +0000 (+0100) Subject: JAL-1443 bugfix to prevent loading of unidentifiable gibberish data X-Git-Tag: Release_2_10_0~570 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=72738726bce0733f652a5dbcc9db7c5a13bc2d80;p=jalview.git JAL-1443 bugfix to prevent loading of unidentifiable gibberish data --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index b2bf58b..b4c2d04 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1245,3 +1245,7 @@ info.enter_search_text_to_enable = Enter Search Text to Enable info.search_in_annotation_label = Search in {0} Label info.search_in_annotation_description = Search in {0} Description info.change_threshold_mode_to_enable = Change Threshold Mode to Enable +label.null_or_unidentifiable_data = Null or unidentifiable data content pasted! +label.unidentifiable_data = Unidentifiable Data +label.null_or_invalid_alignment = Null or invalid alignment data! +label.unable_to_create_alignment = Unable to create alignment \ No newline at end of file diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 81046f1..15df67b 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -20,6 +20,10 @@ */ package jalview.datamodel; +import jalview.analysis.AlignmentUtils; +import jalview.io.FastaFile; +import jalview.util.MessageManager; + import java.util.ArrayList; import java.util.Enumeration; import java.util.HashSet; @@ -30,10 +34,6 @@ import java.util.Map; import java.util.Set; import java.util.Vector; -import jalview.analysis.AlignmentUtils; -import jalview.io.FastaFile; -import jalview.util.MessageManager; - /** * Data structure to hold and manipulate a multiple sequence alignment */ @@ -1734,4 +1734,19 @@ public class Alignment implements AlignmentI } return names; } + + @Override + public boolean hasValidSequence() + { + boolean hasValidSeq = false; + for (SequenceI seq : getSequences()) + { + if (seq.getSequenceAsString().matches("(-*[a-zA-Z]-*){1}[a-zA-Z-]*")) + { + hasValidSeq = true; + break; + } + } + return hasValidSeq; + } } diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 67e5743..8194bf0 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -517,4 +517,12 @@ public interface AlignmentI extends AnnotatedCollectionI * @return */ Set getSequenceNames(); + + /** + * Checks if the alignment has at least one sequence with one non-gaped + * residue + * + * @return + */ + public boolean hasValidSequence(); } diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index 979d1aa..e08bfcd 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -24,6 +24,7 @@ import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.ComplexAlignFile; import jalview.api.FeaturesDisplayedI; +import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SequenceI; @@ -202,6 +203,21 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer } String format = new IdentifyFile().Identify(text, "Paste"); + if (format == null || format.equalsIgnoreCase("EMPTY DATA FILE")) + { + System.err.println(MessageManager + .getString("label.null_or_unidentifiable_data")); + if (!Jalview.isHeadlessMode()) + { + JOptionPane.showMessageDialog(null, + MessageManager + .getString("label.null_or_unidentifiable_data"), + MessageManager.getString("label.unidentifiable_data"), + JOptionPane.ERROR_MESSAGE); + } + return; + } + // TODO: identify feature, annotation or tree file and parse appropriately. AlignmentI al = null; @@ -224,7 +240,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer } } - if (al != null) + if (al != null && al.hasValidSequence()) { String title = MessageManager.formatMessage( "label.input_cut_paste_params", new String[] @@ -276,6 +292,22 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer } } } + else + { + System.err.println(MessageManager + .getString("label.null_or_invalid_alignment")); + if (!Jalview.isHeadlessMode()) + { + JOptionPane + .showMessageDialog( + null, + MessageManager + .getString("label.null_or_invalid_alignment"), + MessageManager + .getString("label.unable_to_create_alignment"), + JOptionPane.ERROR_MESSAGE); + } + } } diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 90400f4..02de02e 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -205,6 +205,10 @@ public class AppletFormatAdapter public static final boolean isValidFormat(String format, boolean forwriting) { + if (format == null) + { + return false; + } boolean valid = false; String[] format_list = (forwriting) ? WRITEABLE_FORMATS : READABLE_FORMATS; diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 3aded05..73c10df 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -265,11 +265,12 @@ public class FileLoader implements Runnable { Desktop.instance.stopLoading(); System.err.println("The input file \"" + file - + "\" has no data content!"); + + "\" has null or unidentifiable data content!"); if (!Jalview.isHeadlessMode()) { - JOptionPane.showMessageDialog(null, "The input file \"" - + file + "\" has no data content!", "Empty data file", + JOptionPane.showMessageDialog(null, "The input file \"" + file + + "\" has null or unidentifiable data content!", + "Empty data file", JOptionPane.ERROR_MESSAGE); } return; diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index dae8f82..17ba32e 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -84,7 +84,7 @@ public class IdentifyFile */ public String Identify(FileParse source, boolean closeSource) { - String reply = "PFAM"; + String reply = null; String data; int length = 0; boolean lineswereskipped = false;