Skip to content

Commit f5358bb

Browse files
committed
revoke deleted tests
1 parent 2498254 commit f5358bb

File tree

3 files changed

+365
-0
lines changed

3 files changed

+365
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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.exceptions.CompoundNotFoundException;
24+
import org.biojava.nbio.core.sequence.DNASequence;
25+
import org.biojava.nbio.core.sequence.Strand;
26+
import org.biojava.nbio.core.sequence.compound.NucleotideCompound;
27+
import org.biojava.nbio.core.sequence.location.template.Location;
28+
import org.biojava.nbio.core.sequence.template.Sequence;
29+
import org.junit.Test;
30+
31+
import java.util.Arrays;
32+
import java.util.List;
33+
34+
import static org.biojava.nbio.core.sequence.Strand.UNDEFINED;
35+
import static org.junit.Assert.assertEquals;
36+
37+
public class LocationTest {
38+
39+
@Test
40+
public void testSubLocations() throws CompoundNotFoundException {
41+
List<SimpleLocation> expected = Arrays.asList(
42+
new SimpleLocation(1, 2, Strand.UNDEFINED),
43+
new SimpleLocation(3, 6, Strand.UNDEFINED),
44+
new SimpleLocation(7, 10, Strand.UNDEFINED),
45+
new SimpleLocation(11, 20, UNDEFINED));
46+
47+
Location location = new SimpleLocation(1, 20, UNDEFINED,
48+
new SimpleLocation(1, 10, UNDEFINED,
49+
new SimpleLocation(1, 6, UNDEFINED,
50+
new SimpleLocation(1, 2, UNDEFINED), new SimpleLocation(3, 6, UNDEFINED)),
51+
new SimpleLocation(7, 10, UNDEFINED)),
52+
new SimpleLocation(11, 20, UNDEFINED));
53+
54+
List<Location> actual = location.getRelevantSubLocations();
55+
56+
assertEquals("Checking sublocations iterate as expected", toStr(expected), toStr(actual));
57+
58+
String expectedDna = "AACCCCTTTTGGGGGGGGGG";
59+
Sequence<NucleotideCompound> s = new DNASequence(expectedDna + "CC");
60+
Sequence<NucleotideCompound> subSeq = location.getSubSequence(s);
61+
assertEquals("Checking subseq as expected", expectedDna, subSeq.getSequenceAsString());
62+
}
63+
64+
@Test
65+
public void testBasicCircularLocation() throws CompoundNotFoundException {
66+
Location circularLocation = new SimpleLocation(
67+
new SimplePoint(3), new SimplePoint(52), Strand.POSITIVE, true,
68+
new SimpleLocation(3, 20, Strand.POSITIVE),
69+
new SimpleLocation(1, 20, Strand.POSITIVE),
70+
new SimpleLocation(1, 12, Strand.POSITIVE));
71+
assertEquals("Checking length as expected", circularLocation.getLength(), 50);
72+
73+
String expectedDna = "CCCCTTTTGGGGGGGGGGAACCCCTTTTGGGGGGGGGGAACCCCTTTTGG";
74+
DNASequence s = new DNASequence("AACCCCTTTTGGGGGGGGGG");
75+
Sequence<NucleotideCompound> subSeq = circularLocation.getSubSequence(s);
76+
assertEquals("Checking subseq as expected", expectedDna, subSeq.getSequenceAsString());
77+
78+
79+
Location newCircularLocation = Location.Tools.circularLocation(
80+
3, 52, Strand.POSITIVE, 20);
81+
//Check this is the right set of coords even to use!
82+
Location negativeCoordsCircularLocation = Location.Tools.circularLocation(
83+
58,9, Strand.POSITIVE, 20);
84+
85+
assertEquals("location objects should be equivalent", circularLocation, newCircularLocation);
86+
assertEquals("location objects should be equivalent even if they are on the wrong coord system", circularLocation.getSubLocations(), negativeCoordsCircularLocation.getSubLocations());
87+
assertEquals("Checking subseq as expected", expectedDna,
88+
newCircularLocation.getSubSequence(s).getSequenceAsString());
89+
}
90+
91+
@Test
92+
public void testWithStrandSwitch() throws CompoundNotFoundException {
93+
DNASequence s = new DNASequence("AAAAAAAAAATTTTTTTTTTCCCCCCCCCCGGGGGGGGGGAAATTTCCCG");
94+
Location location = new SimpleLocation(1, 50, Strand.UNDEFINED,
95+
new SimpleLocation(1, 10, Strand.POSITIVE), //AAAAAAAAAA
96+
new SimpleLocation(19, 23, Strand.NEGATIVE), //GGGAA
97+
new SimpleLocation(45, 50, Strand.POSITIVE)); //TTCCCG
98+
String expectedDna = "AAAAAAAAAAGGGAATTCCCG";
99+
Sequence<NucleotideCompound> subSeq = location.getRelevantSubSequence(s);
100+
assertEquals("Checking subseq as expected", expectedDna, subSeq.getSequenceAsString());
101+
}
102+
103+
@Test
104+
public void testStrandFlip() {
105+
Location l = new SimpleLocation(3,17,Strand.POSITIVE);
106+
Location r = Location.Tools.location(18, 4, Strand.POSITIVE, 20);
107+
assertEquals("Locations should be the same even though they were expressed differently", l, r);
108+
}
109+
110+
@Test(expected = IllegalStateException.class)
111+
public void badLocations() {
112+
new SimpleLocation(10, 1, Strand.UNDEFINED);
113+
}
114+
115+
@Test
116+
public void modulateCircular() {
117+
int length = 20;
118+
assertEquals("Checking modulation", 12, Location.Tools.modulateCircularIndex(52, length));
119+
assertEquals("Checking modulation", 1, Location.Tools.modulateCircularIndex(21, length));
120+
assertEquals("Checking modulation", 3, Location.Tools.modulateCircularIndex(3, length));
121+
}
122+
123+
@Test
124+
public void completePasses() {
125+
assertEquals("Checking passes", 4, Location.Tools.completeCircularPasses(52, 10));
126+
assertEquals("Checking passes", 2, Location.Tools.completeCircularPasses(36, 10));
127+
}
128+
129+
private <L extends Location> String toStr(List<L> locations) {
130+
StringBuilder sb = new StringBuilder();
131+
for (L l : locations) {
132+
sb.append(l).append("|");
133+
}
134+
return sb.toString();
135+
}
136+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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.DataSource;
24+
import org.biojava.nbio.core.sequence.compound.AminoAcidCompoundSet;
25+
import org.biojava.nbio.core.sequence.compound.DNACompoundSet;
26+
import org.biojava.nbio.core.sequence.location.template.Location;
27+
import org.biojava.nbio.core.sequence.template.CompoundSet;
28+
import org.junit.Assert;
29+
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
import org.junit.runners.Parameterized;
32+
33+
import java.util.Arrays;
34+
import java.util.Collection;
35+
36+
/**
37+
*
38+
* @author Jacek Grzebyta
39+
*/
40+
@RunWith(Parameterized.class)
41+
public class TargetedLocationParserTest {
42+
43+
private Data request;
44+
45+
public static class Data {
46+
private String Insdc;
47+
48+
/**
49+
* Parser data input. Based on that input it should be able to identity the origin and wanted target
50+
* @param gi origin GI number
51+
* @param originType origin compound set type
52+
* @param Insdc string with INSDC notation
53+
* @param compound wanted compound type {@see CompoundSet}
54+
*/
55+
public Data(String gi, CompoundSet<?> originType, String Insdc, CompoundSet<?> compound) {
56+
this.Insdc = Insdc;
57+
}
58+
};
59+
60+
@Parameterized.Parameters
61+
public static Collection<Data[]> getLocations() throws Exception {
62+
63+
64+
Data[][] out = new Data[][]{
65+
{new Data("7525057", AminoAcidCompoundSet.getAminoAcidCompoundSet(),
66+
"join(complement(NC_000932.1:69611..69724),NC_000932.1:139856..140087,NC_000932.1:140625..140650)", DNACompoundSet.getDNACompoundSet())},
67+
68+
{new Data("7525059", AminoAcidCompoundSet.getAminoAcidCompoundSet(),
69+
"NC_000932.1:72371..73897", DNACompoundSet.getDNACompoundSet())},
70+
71+
{new Data("7525073", DNACompoundSet.getDNACompoundSet() ,
72+
"complement(NC_000932.1:84005..84283)", DNACompoundSet.getDNACompoundSet())},
73+
74+
75+
{new Data("7525012", DNACompoundSet.getDNACompoundSet(),
76+
"complement(9938..11461)", DNACompoundSet.getDNACompoundSet())}
77+
};
78+
79+
return Arrays.asList(out);
80+
}
81+
82+
public TargetedLocationParserTest(Data request) {
83+
this.request = request;
84+
}
85+
86+
87+
@Test
88+
public void locationTest() throws Exception {
89+
90+
InsdcParser parser = new InsdcParser(DataSource.GENBANK);
91+
Location loc = parser.parse(request.Insdc);
92+
93+
Assert.assertNotNull(loc);
94+
if (loc.isComplex()) {
95+
Assert.assertFalse(loc.getSubLocations().isEmpty());
96+
} else {
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)