Newer
Older
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package uk.ac.sanger.artemis.components.variant;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.InputStream;
import java.io.StringWriter;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JPanel;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import uk.ac.sanger.artemis.Entry;
import uk.ac.sanger.artemis.EntryGroup;
import uk.ac.sanger.artemis.FeatureVector;
import uk.ac.sanger.artemis.Feature;
import uk.ac.sanger.artemis.Options;
import uk.ac.sanger.artemis.Selection;
import uk.ac.sanger.artemis.SimpleEntryGroup;
import uk.ac.sanger.artemis.components.EntryFileDialog;
import uk.ac.sanger.artemis.components.variant.VCFview;
import uk.ac.sanger.artemis.io.EntryInformation;
import uk.ac.sanger.artemis.sequence.MarkerRange;
import uk.ac.sanger.artemis.sequence.Strand;
import uk.ac.sanger.artemis.util.Document;
import uk.ac.sanger.artemis.util.DocumentFactory;
/**
* Tests for writing out sequences based on VCF data.
*/
public class WriteVCFTest
{
private VCFview vcfView;
/**
* Write FASTA, from a range selection on the forward strand.
* Variation is a SNP.
* VCF line : test 120768 . C T
*/
@Test
public void testWriteFwdFastaSNP()
{
StringWriter writer = getWriter(true, 120768, 120777);
StringBuffer buff = new StringBuffer("> test.embl.gz 120768:120777\n");
buff.append("cttgtcaagg\n");
buff.append(">test.vcf.gz test.embl.gz 120768:120777\n");
buff.append("tttgtcaagg\n");
assertEquals("Export FASTA range ", writer.toString(), buff.toString());
}
/**
* Write FASTA, from a range selection on the reverse strand.
* Variation is a SNP.
* VCF line : test 120768 . C T
*/
@Test
public void testWriteRevFastaSNP()
{
StringWriter writer = getWriter(false, 120768, 120777);
StringBuffer buff = new StringBuffer("> test.embl.gz 120768:120777 reverse\n");
buff.append("ccttgacaag\n");
buff.append(">test.vcf.gz test.embl.gz 120768:120777 reverse\n");
buff.append("ccttgacaaa\n");
assertEquals("Export FASTA range ", writer.toString(), buff.toString());
}
/**
* Write FASTA, from a range selection on the forward strand.
* Variation is a deletion.
* test 396838 . tt t
*/
@Test
public void testWriteFwdFastaDeletion()
{
StringWriter writer = getWriter(true, 396835, 396845);
StringBuffer buff = new StringBuffer("> test.embl.gz 396835:396845\n");
buff.append("tttttaggtat\n");
buff.append(">test.vcf.gz test.embl.gz 396835:396845\n");
buff.append("tttt-aggtat\n");
assertEquals("Export FASTA range ", writer.toString(), buff.toString());
}
/**
* Write FASTA, from a range selection on the reverse strand.
* Variation is a deletion.
* test 396838 . tt t
*/
@Test
public void testWriteRevFastaDeletion()
{
StringWriter writer = getWriter(false, 396835, 396845);
StringBuffer buff = new StringBuffer("> test.embl.gz 396835:396845 reverse\n");
buff.append("atacctaaaaa\n");
buff.append(">test.vcf.gz test.embl.gz 396835:396845 reverse\n");
buff.append("ataccta-aaa\n");
assertEquals("Export FASTA range ", writer.toString(), buff.toString());
}
/**
* Write FASTA, from a range selection on the forward strand.
* Variation is a insertion.
* test 366787 . t tT
*/
@Test
public void testWriteFwdFastaInsertion()
{
StringWriter writer = getWriter(true, 366785, 366795);
StringBuffer buff = new StringBuffer("> test.embl.gz 366785:366795\n");
buff.append("tttcgcttttt\n");
buff.append(">test.vcf.gz test.embl.gz 366785:366795\n");
buff.append("tttTcgcttttt\n");
assertEquals("Export FASTA range ", writer.toString(), buff.toString());
}
/**
* Write FASTA, from a range selection on the reverse strand.
* Variation is a insertion.
* test 366787 . t tT
*/
@Test
public void testWriteRevFastaInsertion()
{
StringWriter writer = getWriter(false, 366785, 366795);
StringBuffer buff = new StringBuffer("> test.embl.gz 366785:366795 reverse\n");
buff.append("aaaaagcgaaa\n");
buff.append(">test.vcf.gz test.embl.gz 366785:366795 reverse\n");
buff.append("aaaaagcgaaaa\n");
assertEquals("Export FASTA range ", writer.toString(), buff.toString());
}
/**
* Write FASTA, from a range selection on the forward strand.
* Variation is a multiple allele, (PL number indicates either G or T):
* test 361978 . G T 77.76842 . DP=11;AF1=0.95;CI95=0.5,1;DP4=1,0,10,0;MQ=58;PV4=1,9.6e-06,0.37,1 PL:DP:SP:GT:GQ 106,0,0:11:0:1/1:10
*/
@Test
public void testWriteFwdFastaMultipleAllele()
{
StringWriter writer = getWriter(true, 361975, 361985);
StringBuffer buff = new StringBuffer("> test.embl.gz 361975:361985\n");
buff.append("actgaaaaatt\n");
buff.append(">test.vcf.gz test.embl.gz 361975:361985\n");
buff.append("actkaaaaatt\n");
assertEquals("Export FASTA range ", writer.toString(), buff.toString());
}
/**
* G
* @param isFwd
* @param start
* @param end
* @return
*/
private StringWriter getWriter(boolean isFwd, int start, int end)
{
StringWriter writer = new StringWriter();
Selection selection = new Selection(null);
FeatureVector features = vcfView.getEntryGroup().getAllFeatures();
Feature feature = null;
for(int i=0; i<features.size(); i++)
{
if(features.elementAt(i).isForwardFeature() && isFwd)
{
feature = features.elementAt(i);
break;
}
else if(!features.elementAt(i).isForwardFeature() && !isFwd)
{
feature = features.elementAt(i);
int length = vcfView.getEntryGroup().getSequenceEntry().getBases().getLength();
int tmp = start;
start = length - end + 1;
end = length - tmp + 1;
break;
}
}
try
{
selection.setMarkerRange(new MarkerRange(feature.getStrand(), start, end));
}
catch(uk.ac.sanger.artemis.util.OutOfRangeException e)
{
e.printStackTrace();
}
IOUtils.exportFastaByRange(vcfView, selection, false, writer);
return writer;
}
/**
* Open a flat file and create the components in the TransferAnnotaionTool
* used to control the transfer of annotation.
*/
@Before
public void setup()
{
final URL ref = WriteVCFTest.class.getResource("/data/test.embl.gz");
final URL vcf = WriteVCFTest.class.getResource("/data/test.vcf.gz");
List<String> vcfFileList = new Vector<String>();
vcfFileList.add(vcf.getFile());
JFrame f = new JFrame();
vcfView = new VCFview(f, (JPanel) f.getContentPane(),
vcfFileList,
5000, 100000000, null,
ref.getFile(), null);
f.setVisible(false);
}
}