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
}
}