From acf9118bba86938c8406e7041b4e5a507f4f37a3 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 24 May 2018 15:59:49 +0100 Subject: [PATCH] JAL-2997 additional tests --- src/jalview/io/ClustalFile.java | 4 +++- src/jalview/io/FeaturesFile.java | 14 ++++++-------- src/jalview/io/FileParse.java | 4 ++++ test/jalview/io/ClustalFileTest.java | 30 +++++++++++++++++++++++++++++- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/jalview/io/ClustalFile.java b/src/jalview/io/ClustalFile.java index a37afd9..afb2009 100755 --- a/src/jalview/io/ClustalFile.java +++ b/src/jalview/io/ClustalFile.java @@ -77,7 +77,9 @@ public class ClustalFile extends AlignFile { top = true; } - if (line.indexOf(" ") != 0) + boolean isConservation = line.startsWith(SPACE) + || line.startsWith(TAB); + if (!isConservation) { str = new StringTokenizer(line); diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index d2282b1..e0722c0 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -72,8 +72,6 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI private static final String NOTE = "Note"; - protected static final String TAB = "\t"; - protected static final String GFF_VERSION = "##gff-version"; private AlignmentI lastmatchedAl = null; @@ -180,11 +178,11 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI Map colours, boolean removeHTML, boolean relaxedIdmatching) { - Map gffProps = new HashMap(); + Map gffProps = new HashMap<>(); /* * keep track of any sequences we try to create from the data */ - List newseqs = new ArrayList(); + List newseqs = new ArrayList<>(); String line = null; try @@ -534,7 +532,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI * sort groups alphabetically, and ensure that features with a * null or empty group are output after those in named groups */ - List sortedGroups = new ArrayList(visibleFeatureGroups); + List sortedGroups = new ArrayList<>(visibleFeatureGroups); sortedGroups.remove(null); sortedGroups.remove(""); Collections.sort(sortedGroups); @@ -577,7 +575,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI for (int i = 0; i < sequences.length; i++) { String sequenceName = sequences[i].getName(); - List features = new ArrayList(); + List features = new ArrayList<>(); if (types.length > 0) { features.addAll(sequences[i].getFeatures().getFeaturesForGroup( @@ -688,7 +686,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI dataset = new Alignment(new SequenceI[] {}); } - Map featureColours = new HashMap(); + Map featureColours = new HashMap<>(); boolean parseResult = parse(dataset, featureColours, false, true); if (!parseResult) { @@ -748,7 +746,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI for (SequenceI seq : sequences) { - List features = new ArrayList(); + List features = new ArrayList<>(); if (includeNonPositionalFeatures) { features.addAll(seq.getFeatures().getNonPositionalFeatures()); diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index c0328d5..7117d0f 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -45,6 +45,10 @@ import java.util.zip.GZIPInputStream; */ public class FileParse { + protected static final String SPACE = " "; + + protected static final String TAB = "\t"; + /** * text specifying source of data. usually filename or url. */ diff --git a/test/jalview/io/ClustalFileTest.java b/test/jalview/io/ClustalFileTest.java index a912d96..1da2c75 100644 --- a/test/jalview/io/ClustalFileTest.java +++ b/test/jalview/io/ClustalFileTest.java @@ -25,7 +25,35 @@ public class ClustalFileTest + "FER_CAPAN/1-55 SYKVKLI 55\n" + "FER1_SOLLC/1-55 SYKVKLI 55\n" + "Q93XJ9_SOLTU/1-55 SYKVKLI 55\n" - + "FER1_PEA/1-60 SYKVKLV 60\n"; + + "FER1_PEA/1-60 SYKVKLV 60\n" + + " .* .:....*******..** ..........** ********...*:::* ...\n" + + "\t\t.:.::. *\n"; + //@formatter:on + ClustalFile cf = new ClustalFile(data, DataSourceType.PASTE); + cf.parse(); + SequenceI[] seqs = cf.getSeqsAsArray(); + assertEquals(seqs.length, 5); + assertEquals(seqs[0].getName(), "FER_CAPAA"); + assertEquals(seqs[0].getStart(), 1); + assertEquals(seqs[0].getEnd(), 8); + assertTrue(seqs[0].getSequenceAsString().endsWith("ASYKVKLI")); + } + + @Test(groups="Functional") + public void testParse_noNumbering() throws IOException + { + //@formatter:off + String data = "CLUSTAL\n\n" + + "FER_CAPAA/1-8 -----------------------------------------------------------A\n" + + "FER_CAPAN/1-55 MA------SVSATMISTSFMPRKPAVTSL-KPIPNVGE--ALFGLKS-A--NGGKVTCMA\n" + + "FER1_SOLLC/1-55 MA------SISGTMISTSFLPRKPAVTSL-KAISNVGE--ALFGLKS-G--RNGRITCMA\n" + + "Q93XJ9_SOLTU/1-55 MA------SISGTMISTSFLPRKPVVTSL-KAISNVGE--ALFGLKS-G--RNGRITCMA\n" + + "FER1_PEA/1-60 MATT---PALYGTAVSTSFLRTQPMPMSV-TTTKAFSN--GFLGLKT-SLKRGDLAVAMA\n\n" + + "FER_CAPAA/1-8 SYKVKLI\n" + + "FER_CAPAN/1-55 SYKVKLI\n" + + "FER1_SOLLC/1-55 SYKVKLI\n" + + "Q93XJ9_SOLTU/1-55 SYKVKLI\n" + + "FER1_PEA/1-60 SYKVKLV\n"; //@formatter:on ClustalFile cf = new ClustalFile(data, DataSourceType.PASTE); cf.parse(); -- 1.7.10.2