1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
*/
package org.biojava.bio.seq.impl;
import java.util.Iterator;
import junit.framework.TestCase;
import org.biojava.bio.Annotation;
import org.biojava.bio.seq.DNATools;
import org.biojava.bio.seq.Feature;
import org.biojava.bio.seq.FeatureFilter;
import org.biojava.bio.seq.FeatureHolder;
import org.biojava.bio.seq.RemoteFeature;
import org.biojava.bio.seq.Sequence;
import org.biojava.bio.symbol.Location;
import org.biojava.bio.symbol.RangeLocation;
import org.biojava.bio.symbol.SymbolList;
/**
* Tests for SimpleAssembly. By dependancy, this also
* tests ProjectedFeatureHolder and SimpleAssembly.
*
* @author Thomas Down
* @author Matthew Pocock
* @since 1.3
*/
public class SubSequenceTest extends TestCase {
protected Sequence seq;
protected Sequence subseq;
public SubSequenceTest(String name) {
super(name);
}
protected void setUp() throws Exception {
seq = new SimpleSequence(DNATools.createDNA("aacgtaggttccatgc"),
"fragment1",
"fragment1",
Annotation.EMPTY_ANNOTATION);
Feature.Template sft = new Feature.Template();
sft.source = "test1";
sft.annotation = Annotation.EMPTY_ANNOTATION;
sft.location = new RangeLocation(1, 3);
seq.createFeature(sft);
sft.type = "test2";
sft.location = new RangeLocation(10, 12);
seq.createFeature(sft);
sft.type = "test3";
sft.location = new RangeLocation(5, 13);
Feature choppedFeature = seq.createFeature(sft);
sft.type = "test4";
sft.location = new RangeLocation(5, 6);
choppedFeature.createFeature(sft);
sft.type = "test5";
sft.location = new RangeLocation(9, 10);
choppedFeature.createFeature(sft);
subseq = new SubSequence(seq, 8, 14);
}
public void testSymbols()
throws Exception {
assertTrue(compareSymbolList(subseq,
DNATools.createDNA("gttccat")));
}
public void testFeatureClipping()
throws Exception {
assertEquals("subseq.countFeatures()", 2, subseq.countFeatures());
}
public void testFeatureProjection()
throws Exception {
Feature f = (Feature) subseq.filter(new FeatureFilter.Not(new FeatureFilter.ByClass(RemoteFeature.class)), false).features().next();
Location fl = f.getLocation();
assertEquals("projection.getMin()", 3, fl.getMin());
assertEquals("projection.getMax()", 5, fl.getMax());
}
public void testRemoteFeature()
throws Exception {
FeatureHolder remotes = subseq.filter(new FeatureFilter.ByClass(RemoteFeature.class), false);
assertEquals("One remote feature: ", 1, remotes.countFeatures());
Feature f = (Feature) remotes.features().next();
assertTrue("Feature implements RemoteFeature", f instanceof RemoteFeature);
RemoteFeature rf = (RemoteFeature) f;
Location fl = rf.getLocation();
assertEquals("remote feature getMin()", 1, fl.getMin());
assertEquals("remote feature getMax()", 6, fl.getMax());
assertEquals("remote feature name", seq.getName(), rf.getRemoteFeature().getSequence().getName());
}
public void testRemoteChildFeature()
throws Exception {
FeatureHolder remotes = subseq.filter(new FeatureFilter.ByClass(RemoteFeature.class), false);
assertEquals("One remote feature: ", 1, remotes.countFeatures());
Feature f = (Feature) remotes.features().next();
assertTrue("Feature implements RemoteFeature", f instanceof RemoteFeature);
RemoteFeature rf = (RemoteFeature) f;
assertEquals("child remote features should be pruned - counting them", 1, rf.countFeatures());
Feature cf = (Feature) rf.features().next();
Location cfl = cf.getLocation();
assertEquals("cf.getMin()", 2, cfl.getMin());
assertEquals("cf.getMax()", 3, cfl.getMax());
}
public void testCreateOnSubsequence()
throws Exception {
Feature.Template templ = new Feature.Template();
templ.type = "create_on_subsequence";
templ.source = "test";
templ.location = new RangeLocation(2, 3);
templ.annotation = Annotation.EMPTY_ANNOTATION;
subseq.createFeature(templ);
Feature f = (Feature) seq.filter(new FeatureFilter.ByType("create_on_subsequence"), false).features().next();
Location fl = f.getLocation();
assertEquals("fl.getMin()", 9, fl.getMin());
assertEquals("fl.getMax()", 10, fl.getMax());
}
public void testCreateOnSubsequenceFeature()
throws Exception {
Feature.Template templ = new Feature.Template();
templ.type = "create_on_subsequence_feature";
templ.source = "test";
templ.location = new RangeLocation(3, 4);
templ.annotation = Annotation.EMPTY_ANNOTATION;
Feature subf = (Feature) subseq.filter(new FeatureFilter.Not(new FeatureFilter.ByClass(RemoteFeature.class)), false).features().next();
subf.createFeature(templ);
Feature f = (Feature) seq.filter(new FeatureFilter.ByType("create_on_subsequence_feature"), true).features().next();
Location fl = f.getLocation();
assertEquals(fl.getMin(), 10);
assertEquals(fl.getMax(), 11);
}
public void testRemoveFeatureFromSubsequence()
throws Exception {
FeatureHolder fh = subseq.filter(new FeatureFilter.Not(new FeatureFilter.ByClass(RemoteFeature.class)), false);
assertEquals(fh.countFeatures(), 1);
Feature f = (Feature) fh.features().next();
subseq.removeFeature(f);
fh = subseq.filter(new FeatureFilter.Not(new FeatureFilter.ByClass(RemoteFeature.class)), false);
assertEquals(fh.countFeatures(), 0);
}
private boolean compareSymbolList(SymbolList sl1, SymbolList sl2) {
if (sl1.length() != sl2.length()) {
return false;
}
Iterator si1 = sl1.iterator();
Iterator si2 = sl2.iterator();
while (si1.hasNext()) {
if (!(si1.next() == si2.next())) {
return false;
}
}
return true;
}
}
|