|
| 1 | +/* |
| 2 | + * BioJava development code |
| 3 | + * |
| 4 | + * This code may be freely distributed and modified under the |
| 5 | + * terms of the GNU Lesser General Public Licence. This should |
| 6 | + * be distributed with the code. If you do not have a copy, |
| 7 | + * see: |
| 8 | + * |
| 9 | + * http://www.gnu.org/copyleft/lesser.html |
| 10 | + * |
| 11 | + * Copyright for this code is held jointly by the individual |
| 12 | + * authors. These should be listed in @author doc comments. |
| 13 | + * |
| 14 | + * For more information on the BioJava project and its aims, |
| 15 | + * or to join the biojava-l mailing list, visit the home page |
| 16 | + * at: |
| 17 | + * |
| 18 | + * http://www.biojava.org/ |
| 19 | + * |
| 20 | + */ |
| 21 | +package org.biojava.nbio.core.sequence.location; |
| 22 | + |
| 23 | +import org.biojava.nbio.core.sequence.AccessionID; |
| 24 | +import org.biojava.nbio.core.sequence.Strand; |
| 25 | +import org.biojava.nbio.core.sequence.location.template.Location; |
| 26 | +import org.junit.Assert; |
| 27 | +import org.junit.Ignore; |
| 28 | +import org.junit.Test; |
| 29 | +import org.slf4j.Logger; |
| 30 | +import org.slf4j.LoggerFactory; |
| 31 | + |
| 32 | +/** |
| 33 | + * TODO: Temporary test is switched off. Currently results are messy: |
| 34 | + * |
| 35 | + * <code> |
| 36 | + * to test: complement(order(1,2..34,complement(34..45),A00001.5:34..45)) expected: 1..45(.) received: 1..45(.) |
| 37 | + * to test: 1 expected: 1..1(+) received: 1..1(+) |
| 38 | + * to test: 1..10 expected: 1..10(+) received: 1..10(+) |
| 39 | + * to test: 1^2 expected: 1^2(+) received: 1^2(+) |
| 40 | + * to test: complement(1..10) expected: 1..10(-) received: 1..10(-) |
| 41 | + * to test: join(1..2,7..8) expected: 1..8(+) received: 1..8(+) |
| 42 | + * to test: complement(join(1..2,7..8)) expected: 1..8(-) received: 1..8(-) |
| 43 | + * to test: join(complement(1..2),complement(7..8)) expected: 1..8(-) received: 1..8(-) |
| 44 | + * to test: join(1..2,join(4..5,complement(6..8)) expected: 1..8(.) received: 1..8(.) |
| 45 | + * to test: join(5..10,1..3) expected: 5..13(+ - circular) received: 1..10(+) |
| 46 | + * </code> |
| 47 | + * |
| 48 | + * Serialisation to string should be fixed as well. |
| 49 | + * |
| 50 | + * |
| 51 | + * @author Jacek Grzebyta |
| 52 | + */ |
| 53 | +public class LocationParserTest { |
| 54 | + |
| 55 | + public static final InsdcParser PARSER = new InsdcParser(); |
| 56 | + |
| 57 | + private Logger log = LoggerFactory.getLogger(getClass()); |
| 58 | + |
| 59 | + @Test |
| 60 | + @Ignore |
| 61 | + public void basicLocationTests() { |
| 62 | + assertInsdcLoc("1", new SimpleLocation(1, 1, Strand.POSITIVE)); |
| 63 | + |
| 64 | + assertInsdcLoc("1..10", new SimpleLocation(1, 10, Strand.POSITIVE)); |
| 65 | + assertInsdcLoc("1^2", new SimpleLocation( |
| 66 | + new SimplePoint(1), |
| 67 | + new SimplePoint(2), |
| 68 | + Strand.POSITIVE, false, true)); |
| 69 | + |
| 70 | + assertInsdcLoc("complement(1..10)", new SimpleLocation(1, 10, Strand.NEGATIVE)); |
| 71 | + |
| 72 | + assertInsdcLoc("join(1..2,7..8)", new InsdcLocations.GroupLocation( |
| 73 | + new SimplePoint(1), new SimplePoint(8), Strand.POSITIVE, |
| 74 | + new SimpleLocation(1, 2, Strand.POSITIVE), |
| 75 | + new SimpleLocation(7, 8, Strand.POSITIVE))); |
| 76 | + |
| 77 | + assertInsdcLoc("complement(join(1..2,7..8))", new InsdcLocations.GroupLocation( |
| 78 | + new SimplePoint(1), new SimplePoint(8), Strand.NEGATIVE, |
| 79 | + new SimpleLocation(1, 2, Strand.NEGATIVE), |
| 80 | + new SimpleLocation(7, 8, Strand.NEGATIVE))); |
| 81 | + |
| 82 | + //Reverse relationship |
| 83 | + assertInsdcLoc("join(complement(1..2),complement(7..8))", new InsdcLocations.GroupLocation( |
| 84 | + new SimplePoint(1), new SimplePoint(8), Strand.NEGATIVE, |
| 85 | + new SimpleLocation(1, 2, Strand.NEGATIVE), |
| 86 | + new SimpleLocation(7, 8, Strand.NEGATIVE))); |
| 87 | + |
| 88 | + //Complex sub relations |
| 89 | + //should tests be designed for both modes? |
| 90 | + //PARSER.setComplexFeaturesAppendMode(InsdcParser.complexFeaturesAppendEnum.HIERARCHICAL); |
| 91 | + assertInsdcLoc("join(1..2,join(4..5,complement(6..8))", new InsdcLocations.GroupLocation( |
| 92 | + new SimplePoint(1), new SimplePoint(8), Strand.UNDEFINED, |
| 93 | + new SimpleLocation(1, 2, Strand.POSITIVE), |
| 94 | + new SimpleLocation(4, 8, Strand.UNDEFINED, |
| 95 | + new SimpleLocation(4, 5, Strand.POSITIVE), |
| 96 | + new SimpleLocation(6, 8, Strand.NEGATIVE)))); |
| 97 | + |
| 98 | + assertInsdcLoc("join(5..10,1..3)", new InsdcLocations.GroupLocation( |
| 99 | + new SimplePoint(5), new SimplePoint(13), Strand.POSITIVE, |
| 100 | + true, //Circular genome |
| 101 | + new SimpleLocation(5, 10, Strand.POSITIVE), |
| 102 | + new SimpleLocation(1, 3, Strand.POSITIVE))); |
| 103 | + |
| 104 | + assertInsdcLoc("order(1..2,7..8)", new InsdcLocations.OrderLocation( |
| 105 | + new SimplePoint(1), new SimplePoint(8), Strand.POSITIVE, |
| 106 | + new SimpleLocation(1, 2, Strand.POSITIVE), |
| 107 | + new SimpleLocation(7, 8, Strand.POSITIVE))); |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + @Ignore |
| 112 | + public void moreComplex() { |
| 113 | + assertInsdcLoc("complement(order(1,2..34,complement(34..45),A00001.5:34..45))", |
| 114 | + new InsdcLocations.OrderLocation( |
| 115 | + new SimplePoint(1), new SimplePoint(45), Strand.UNDEFINED, |
| 116 | + new SimpleLocation(1, 1, Strand.NEGATIVE), |
| 117 | + new SimpleLocation(2, 34, Strand.NEGATIVE), |
| 118 | + new SimpleLocation(34, 45, Strand.POSITIVE), |
| 119 | + new SimpleLocation( |
| 120 | + new SimplePoint(34), new SimplePoint(45), |
| 121 | + Strand.NEGATIVE, |
| 122 | + new AccessionID("A00001.5", PARSER.getDataSource())))); |
| 123 | + } |
| 124 | + |
| 125 | + public void assertInsdcLoc(String stringLoc, Location expected) { |
| 126 | + Location actual = PARSER.parse(stringLoc); |
| 127 | + log.info("to test: {}\texpected: {}\treceived: {}", stringLoc, expected.toString(), actual.toString()); |
| 128 | + Assert.assertEquals("Asserting locations are the same", expected.toString(), actual.toString()); |
| 129 | + } |
| 130 | +} |
0 commit comments