From 4222d402b5bd51649d38c3818e8429b786c230be Mon Sep 17 00:00:00 2001 From: James Procter Date: Mon, 30 Oct 2023 11:23:05 +0000 Subject: [PATCH] JAL-4315 identify feature settings file from its xml schema header --- src/jalview/io/FileFormat.java | 15 +++++++++++++++ src/jalview/io/IdentifyFile.java | 12 ++++++++++++ test/jalview/gui/FeatureSettingsTest.java | 12 ++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java index 43c6dcf..91ce527 100644 --- a/src/jalview/io/FileFormat.java +++ b/src/jalview/io/FileFormat.java @@ -308,6 +308,21 @@ public enum FileFormat implements FileFormatI return new FeaturesFile(); } }, + FeatureSettings("Jalview Feature Settings File","fc",false,false) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return null; + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return null; + } + }, ScoreMatrix("Substitution matrix", "", false, false) { @Override diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index ea87058..11d96a3 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -35,6 +35,8 @@ import jalview.bin.Console; public class IdentifyFile { + private static final String XMLHEADER = ""; + public FileFormatI identify(Object file, DataSourceType protocol) throws FileFormatException { @@ -134,6 +136,7 @@ public class IdentifyFile String data; int bytesRead = 0; int trimmedLength = 0; + boolean isXml = false; // set true if first line is XMLHEADER boolean lineswereskipped = false; boolean isBinary = false; // true if length is non-zero and non-printable // characters are encountered @@ -188,6 +191,10 @@ public class IdentifyFile reply = FileFormat.ScoreMatrix; break; } + if (data.startsWith(XMLHEADER) && !lineswereskipped) + { + isXml = true; + } if (data.startsWith("LOCUS")) { reply = FileFormat.GenBank; @@ -346,6 +353,11 @@ public class IdentifyFile reply = FileFormat.Rnaml; break; } + if (isXml && data.contains("")) + { + reply = FileFormat.FeatureSettings; + break; + } } if ((data.length() < 1) || (data.indexOf("#") == 0)) diff --git a/test/jalview/gui/FeatureSettingsTest.java b/test/jalview/gui/FeatureSettingsTest.java index 5ef693a..7cc4cc1 100644 --- a/test/jalview/gui/FeatureSettingsTest.java +++ b/test/jalview/gui/FeatureSettingsTest.java @@ -42,7 +42,10 @@ import jalview.datamodel.features.FeatureMatcher; import jalview.datamodel.features.FeatureMatcherSet; import jalview.datamodel.features.FeatureMatcherSetI; import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatI; import jalview.io.FileLoader; +import jalview.io.IdentifyFile; import jalview.schemes.FeatureColour; import jalview.schemes.FeatureColourTest; import jalview.util.matcher.Condition; @@ -278,4 +281,13 @@ public class FeatureSettingsTest "By Score (> 4.0)
" + simpleTooltip + "
"); } + String fsfile="",fsfile2="\n"; + @Test(groups="Functional") + public void testIdentifyFeatureSettingsFile() throws Exception + { + FileFormatI type = new IdentifyFile().identify(fsfile, DataSourceType.PASTE); + assertTrue(FileFormat.FeatureSettings==type,"Feature settings file was identified as "+type); + type = new IdentifyFile().identify(fsfile2, DataSourceType.PASTE); + assertTrue(FileFormat.FeatureSettings==type,"Feature settings file with newline was identified as "+type); + } } -- 1.7.10.2