/* * 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.gff; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertTrue; import java.util.Arrays; import java.util.List; import java.util.Map; import org.testng.annotations.Test; public class GffHelperBaseTest { /** * Test the method that parses lines like
* ID=2345;Name=Something,Another thing;Notes=Hello;Notes=World */ @Test(groups = { "Functional" }) public void testParseNameValuePairs() { assertTrue(GffHelperBase.parseNameValuePairs(null, ";", ' ', ",") .isEmpty()); assertTrue(GffHelperBase.parseNameValuePairs("", ";", ' ', ",") .isEmpty()); assertTrue(GffHelperBase.parseNameValuePairs("hello=world", ";", ' ', ",").isEmpty()); Map> map = GffHelperBase.parseNameValuePairs( "hello world", ";", ' ', ", "); assertEquals(1, map.size()); assertEquals(1, map.get("hello").size()); assertEquals("world", map.get("hello").get(0)); map = GffHelperBase .parseNameValuePairs( "Method= manual curation ;nothing; Notes=F2 S ; Notes=Metal,Shiny; Type=", ";", '=', ","); // Type is ignored as no value was supplied assertEquals(2, map.size()); assertEquals(1, map.get("Method").size()); assertEquals("manual curation", map.get("Method").get(0)); // trimmed assertEquals(3, map.get("Notes").size()); assertEquals("F2 S", map.get("Notes").get(0)); assertEquals("Metal", map.get("Notes").get(1)); assertEquals("Shiny", map.get("Notes").get(2)); } /** * Test for the method that tries to trim mappings to equivalent lengths */ @Test(groups = "Functional") public void testTrimMapping() { int[] from = { 1, 12 }; int[] to = { 20, 31 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); assertEquals("[1, 12]", Arrays.toString(from)); // unchanged assertEquals("[20, 31]", Arrays.toString(to)); // unchanged // from too long: from = new int[] { 1, 13 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); assertEquals("[1, 12]", Arrays.toString(from)); // trimmed assertEquals("[20, 31]", Arrays.toString(to)); // unchanged // to too long: to = new int[] { 20, 33 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); assertEquals("[1, 12]", Arrays.toString(from)); // unchanged assertEquals("[20, 31]", Arrays.toString(to)); // trimmed // from reversed: from = new int[] { 12, 1 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); assertEquals("[12, 1]", Arrays.toString(from)); // unchanged assertEquals("[20, 31]", Arrays.toString(to)); // unchanged // to reversed: to = new int[] { 31, 20 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); assertEquals("[12, 1]", Arrays.toString(from)); // unchanged assertEquals("[31, 20]", Arrays.toString(to)); // unchanged // from reversed and too long: from = new int[] { 14, 1 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); assertEquals("[14, 3]", Arrays.toString(from)); // end trimmed assertEquals("[31, 20]", Arrays.toString(to)); // unchanged // to reversed and too long: to = new int[] { 31, 10 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); assertEquals("[14, 3]", Arrays.toString(from)); // unchanged assertEquals("[31, 20]", Arrays.toString(to)); // end trimmed // cdna to peptide (matching) from = new int[] { 1, 18 }; to = new int[] { 4, 9 }; assertTrue(GffHelperBase.trimMapping(from, to, 3, 1)); assertEquals("[1, 18]", Arrays.toString(from)); // unchanged assertEquals("[4, 9]", Arrays.toString(to)); // unchanged // overlong cdna to peptide from = new int[] { 1, 20 }; assertTrue(GffHelperBase.trimMapping(from, to, 3, 1)); assertEquals("[1, 18]", Arrays.toString(from)); // end trimmed assertEquals("[4, 9]", Arrays.toString(to)); // unchanged // overlong cdna (reversed) to peptide from = new int[] { 20, 1 }; assertTrue(GffHelperBase.trimMapping(from, to, 3, 1)); assertEquals("[20, 3]", Arrays.toString(from)); // end trimmed assertEquals("[4, 9]", Arrays.toString(to)); // unchanged // overlong cdna (reversed) to peptide (reversed) from = new int[] { 20, 1 }; to = new int[] { 9, 4 }; assertTrue(GffHelperBase.trimMapping(from, to, 3, 1)); assertEquals("[20, 3]", Arrays.toString(from)); // end trimmed assertEquals("[9, 4]", Arrays.toString(to)); // unchanged // peptide to cdna (matching) from = new int[] { 4, 9 }; to = new int[] { 1, 18 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 3)); assertEquals("[4, 9]", Arrays.toString(from)); // unchanged assertEquals("[1, 18]", Arrays.toString(to)); // unchanged // peptide to overlong cdna to = new int[] { 1, 20 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 3)); assertEquals("[4, 9]", Arrays.toString(from)); // unchanged assertEquals("[1, 18]", Arrays.toString(to)); // end trimmed // peptide to overlong cdna (reversed) to = new int[] { 20, 1 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 3)); assertEquals("[4, 9]", Arrays.toString(from)); // unchanged assertEquals("[20, 3]", Arrays.toString(to)); // end trimmed // peptide (reversed) to overlong cdna (reversed) from = new int[] { 9, 4 }; to = new int[] { 20, 1 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 3)); assertEquals("[9, 4]", Arrays.toString(from)); // unchanged assertEquals("[20, 3]", Arrays.toString(to)); // end trimmed // overlong peptide to word-length cdna from = new int[] { 4, 10 }; to = new int[] { 1, 18 }; assertTrue(GffHelperBase.trimMapping(from, to, 1, 3)); assertEquals("[4, 9]", Arrays.toString(from)); // end trimmed assertEquals("[1, 18]", Arrays.toString(to)); // unchanged // overlong peptide to non-word-length cdna from = new int[] { 4, 10 }; to = new int[] { 1, 19 }; assertFalse(GffHelperBase.trimMapping(from, to, 1, 3)); assertEquals("[4, 10]", Arrays.toString(from)); // unchanged assertEquals("[1, 19]", Arrays.toString(to)); // unchanged } }