| 1 |
package vcfgo_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"io" |
| 5 |
"strings" |
| 6 |
"testing" |
| 7 |
|
| 8 |
"github.com/brentp/vcfgo" |
| 9 |
|
| 10 |
. "gopkg.in/check.v1" |
| 11 |
) |
| 12 |
|
| 13 |
func Test(t *testing.T) { TestingT(t) } |
| 14 |
|
| 15 |
var cnvStr = `##fileformat=VCFv4.1 |
| 16 |
##fileDate=20100501 |
| 17 |
##reference=1000GenomesPilot-NCBI36 |
| 18 |
##assembly=ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/release/sv/breakpoint_assemblies.fasta |
| 19 |
##INFO=<ID=BKPTID,Number=.,Type=String,Description="ID of the assembled alternate allele in the assembly file"> |
| 20 |
##INFO=<ID=CIEND,Number=2,Type=Integer,Description="Confidence interval around END for imprecise variants"> |
| 21 |
##INFO=<ID=CIPOS,Number=2,Type=Integer,Description="Confidence interval around POS for imprecise variants"> |
| 22 |
##INFO=<ID=END,Number=1,Type=Integer,Description="End position of the variant described in this record"> |
| 23 |
##INFO=<ID=HOMLEN,Number=.,Type=Integer,Description="Length of base pair identical micro-homology at event breakpoints"> |
| 24 |
##INFO=<ID=HOMSEQ,Number=.,Type=String,Description="Sequence of base pair identical micro-homology at event breakpoints"> |
| 25 |
##INFO=<ID=SVLEN,Number=.,Type=Integer,Description="Difference in length between REF and ALT alleles"> |
| 26 |
##INFO=<ID=SVTYPE,Number=1,Type=String,Description="Type of structural variant"> |
| 27 |
##ALT=<ID=DEL,Description="Deletion"> |
| 28 |
##ALT=<ID=DEL:ME:ALU,Description="Deletion of ALU element"> |
| 29 |
##ALT=<ID=DEL:ME:L1,Description="Deletion of L1 element"> |
| 30 |
##ALT=<ID=DUP,Description="Duplication"> |
| 31 |
##ALT=<ID=DUP:TANDEM,Description="Tandem Duplication"> |
| 32 |
##ALT=<ID=INS,Description="Insertion of novel sequence"> |
| 33 |
##ALT=<ID=INS:ME:ALU,Description="Insertion of ALU element"> |
| 34 |
##ALT=<ID=INS:ME:L1,Description="Insertion of L1 element"> |
| 35 |
##ALT=<ID=INV,Description="Inversion"> |
| 36 |
##ALT=<ID=CNV,Description="Copy number variable region"> |
| 37 |
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype"> |
| 38 |
##FORMAT=<ID=GQ,Number=1,Type=Float,Description="Genotype quality"> |
| 39 |
##FORMAT=<ID=CN,Number=1,Type=Integer,Description="Copy number genotype for imprecise events"> |
| 40 |
##FORMAT=<ID=CNQ,Number=1,Type=Float,Description="Copy number genotype quality for imprecise events"> |
| 41 |
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT NA00001 |
| 42 |
2 321682 . T <DEL> 6 PASS SVTYPE=DEL;END=321887;SVLEN=-205;CIPOS=-56,20;CIEND=-10,62 GT:GQ 0/1:12 |
| 43 |
2 14477084 . C <DEL:ME:ALU> 12 PASS SVTYPE=DEL;END=14477381;CIPOS=-22,18;CIEND=-12,32 GT:GQ 0/1:12 |
| 44 |
3 9425916 . C <INS:ME:L1> 23 PASS SVTYPE=INS;SVLEN=6027;CIPOS=-16,22 GT:GQ 1/1:15 |
| 45 |
3 12665100 . A <DUP> 14 PASS SVTYPE=DUP;END=12686200;SVLEN=21100;CIPOS=-500,500;CIEND=-500,500 GT:GQ:CN:CNQ ./.:0:3:16.2 |
| 46 |
4 18665128 . T <DUP:TANDEM> 11 PASS SVTYPE=DUP;END=18665204;SVLEN=76;CIPOS=-10,10;CIEND=-10,10 GT:GQ:CN:CNQ ./.:0:5:8.3 |
| 47 |
4 18665128 . T <INV> 11 PASS SVTYPE=INS;END=18665204;SVLEN=76;CIPOS=-10,10;CIEND=-10,10 GT:GQ:CN:CNQ ./.:0:5:8.3 |
| 48 |
4 18665128 . T <CNV> 11 PASS SVTYPE=DUP;END=18665204;SVLEN=76;CIPOS=-10,10;CIEND=-10,10 GT:GQ:CN:CNQ ./.:0:5:8.3 |
| 49 |
4 43266825 rs369548269 T <DEL> . . ON=0;OLD_MULTIALLELIC=4:43266825:T/TAC/<DEL> GT 0/1 |
| 50 |
5 755892 175981_1 N ]1:759001]N 112.69 PASS AC=4;AF=0.01361;ALG=PROD;AN=294;CIEND=-10,29;CIEND95=0,34;CIPOS=-30,29;CIPOS95=28,32;EVENT=175981;EXVAR=0.00508;HW=0.00;HetPct=2.7;HomRefPct=97.3;HomVarPct=0.0;IMPRECISE;MATEID=1 GT 0/1` |
| 51 |
|
| 52 |
//1 2827694 rs2376870 CGTGGATGCGGGGAC C . PASS SVTYPE=DEL;END=2827762;HOMLEN=1;HOMSEQ=G;SVLEN=-68 GT:GQ 1/1:13.9 |
| 53 |
|
| 54 |
type CNVSuite struct { |
| 55 |
reader io.Reader |
| 56 |
vcfStr string |
| 57 |
} |
| 58 |
|
| 59 |
var _ = Suite(&CNVSuite{vcfStr: cnvStr}) |
| 60 |
|
| 61 |
func (s *CNVSuite) SetUpTest(c *C) { |
| 62 |
s.reader = strings.NewReader(s.vcfStr) |
| 63 |
} |
| 64 |
|
| 65 |
func (s *CNVSuite) TestDupIns(c *C) { |
| 66 |
r, err := vcfgo.NewReader(s.reader, false) |
| 67 |
c.Assert(err, IsNil) |
| 68 |
var v *vcfgo.Variant |
| 69 |
|
| 70 |
v = r.Read() //.(*vcfgo.Variant) |
| 71 |
c.Assert(int(v.End()), Equals, 321887) |
| 72 |
|
| 73 |
left, right, ok := v.CIPos() |
| 74 |
c.Assert(ok, Equals, true) |
| 75 |
c.Assert(int(left), Equals, 321682-56-1) |
| 76 |
c.Assert(int(right), Equals, 321682+20) |
| 77 |
|
| 78 |
eleft, eright, ok := v.CIEnd() |
| 79 |
c.Assert(ok, Equals, true) |
| 80 |
c.Assert(int(eleft), Equals, 321887-10-1) |
| 81 |
c.Assert(int(eright), Equals, 321887+62) |
| 82 |
|
| 83 |
v = r.Read() //.(*vcfgo.Variant) |
| 84 |
c.Assert(int(v.End()), Equals, 14477381) |
| 85 |
|
| 86 |
v = r.Read() //.(*vcfgo.Variant) |
| 87 |
c.Assert(int(v.Start()), Equals, 9425915) |
| 88 |
c.Assert(int(v.End()), Equals, 9431943) |
| 89 |
|
| 90 |
v = r.Read() //.(*vcfgo.Variant) |
| 91 |
c.Assert(int(v.End()), Equals, 12686200) |
| 92 |
|
| 93 |
v = r.Read() //.(*vcfgo.Variant) |
| 94 |
c.Assert(int(v.End()), Equals, 18665204) |
| 95 |
|
| 96 |
v = r.Read() //.(*vcfgo.Variant) // INS |
| 97 |
c.Assert(int(v.End()), Equals, 18665204) |
| 98 |
|
| 99 |
v = r.Read() //.(*vcfgo.Variant) // CNV |
| 100 |
c.Assert(int(v.End()), Equals, 18665204) |
| 101 |
|
| 102 |
v = r.Read() //.(*vcfgo.Variant) // CNV |
| 103 |
c.Assert(int(v.End()), Equals, 43266825) |
| 104 |
|
| 105 |
left, right, ok = v.CIPos() |
| 106 |
c.Assert(left, Equals, v.Start()) |
| 107 |
c.Assert(right, Equals, v.Start()+uint32(1)) |
| 108 |
c.Assert(ok, Equals, false) |
| 109 |
|
| 110 |
eleft, eright, ok = v.CIEnd() |
| 111 |
c.Assert(eleft, Equals, v.End()-1) |
| 112 |
c.Assert(eright, Equals, v.End()) |
| 113 |
c.Assert(ok, Equals, false) |
| 114 |
|
| 115 |
v = r.Read() //.(*vcfgo.Variant) // BND |
| 116 |
c.Assert(int(v.Start()), Equals, 755891) |
| 117 |
c.Assert(int(v.End()), Equals, 755891+1) |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
var svlenNumberAStr = `##fileformat=VCFv4.1 |
| 122 |
##fileDate=20100501 |
| 123 |
##reference=1000GenomesPilot-NCBI36 |
| 124 |
##assembly=ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/release/sv/breakpoint_assemblies.fasta |
| 125 |
##INFO=<ID=SVLEN,Number=A,Type=Integer,Description="Length of structural variant"> |
| 126 |
##INFO=<ID=SVTYPE,Number=1,Type=String,Description="Type of structural variant"> |
| 127 |
##ALT=<ID=DEL,Description="Deletion"> |
| 128 |
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype"> |
| 129 |
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT NA00001 |
| 130 |
1 1000 . T <DEL> 60 PASS SVTYPE=DEL;SVLEN=100 GT 0/1 |
| 131 |
1 2000 . A <DEL>,<DEL> 60 PASS SVTYPE=DEL;SVLEN=150,200 GT 1/2 |
| 132 |
` |
| 133 |
|
| 134 |
type SVLENNumberASuite struct { |
| 135 |
reader io.Reader |
| 136 |
vcfStr string |
| 137 |
} |
| 138 |
|
| 139 |
var _ = Suite(&SVLENNumberASuite{vcfStr: svlenNumberAStr}) |
| 140 |
|
| 141 |
func (s *SVLENNumberASuite) SetUpTest(c *C) { |
| 142 |
s.reader = strings.NewReader(s.vcfStr) |
| 143 |
} |
| 144 |
|
| 145 |
func (s *SVLENNumberASuite) TestSVLENNumberA(c *C) { |
| 146 |
r, err := vcfgo.NewReader(s.reader, false) |
| 147 |
c.Assert(err, IsNil) |
| 148 |
var v *vcfgo.Variant |
| 149 |
|
| 150 |
// Test single alternative allele with SVLEN Number=A |
| 151 |
v = r.Read() |
| 152 |
c.Assert(v, NotNil) |
| 153 |
c.Assert(int(v.Start()), Equals, 999) // 0-based |
| 154 |
c.Assert(int(v.End()), Equals, 1100) // 1000 + 100 |
| 155 |
|
| 156 |
// Test multiple alternative alleles with SVLEN Number=A |
| 157 |
v = r.Read() |
| 158 |
c.Assert(v, NotNil) |
| 159 |
c.Assert(int(v.Start()), Equals, 1999) // 0-based |
| 160 |
c.Assert(int(v.End()), Equals, 2150) // 2000 + 150 (first alt allele) |
| 161 |
} |