bio-sam-mutation 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.travis.yml +12 -0
- data/Gemfile +21 -0
- data/LICENSE.txt +20 -0
- data/README.md +88 -0
- data/README.rdoc +48 -0
- data/Rakefile +54 -0
- data/bin/mutations +108 -0
- data/bin/sam-mutation +20 -0
- data/lib/bio-sam-mutation.rb +26 -0
- data/lib/bio-sam-mutation/bio/alignment/cigar.rb +239 -0
- data/lib/bio-sam-mutation/bio/alignment/iterate_pairs.rb +68 -0
- data/lib/bio-sam-mutation/bio/db/alignment.rb +176 -0
- data/lib/bio-sam-mutation/bio/db/tag.rb +5 -0
- data/lib/bio-sam-mutation/bio/db/tag/md.rb +126 -0
- data/lib/bio-sam-mutation/bio/mutantallele.rb +24 -0
- data/lib/bio-sam-mutation/bio/mutation.rb +63 -0
- data/lib/bio-sam-mutation/bio/mutation_array.rb +15 -0
- data/lib/bio-sam-mutation/bio/vephgvs.rb +21 -0
- data/lib/bio-sam-mutation/mutationscli.rb +83 -0
- data/test/helper.rb +34 -0
- data/test/test_cigar.rb +145 -0
- data/test/test_mdtag.rb +46 -0
- data/test/test_mutant_allele.rb +21 -0
- data/test/test_mutation.rb +84 -0
- data/test/test_mutation_array.rb +13 -0
- data/test/test_sam.rb +160 -0
- data/test/test_vep_hgvs.rb +9 -0
- metadata +247 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
class Bio::MutationArray < Array
|
2
|
+
include VepHgvs
|
3
|
+
def to_hgvs(reference_type=nil)
|
4
|
+
if length > 0 && reference_type.nil?
|
5
|
+
reference_type = first.seqname.match(/^ENS/) ? "c" : "g"
|
6
|
+
end
|
7
|
+
if length == 1
|
8
|
+
first.to_hgvs(reference_type)
|
9
|
+
elsif length > 1
|
10
|
+
[first.seqname,":",reference_type,".["].join + map(&:to_hgvs).join(";") + "]"
|
11
|
+
elsif length == 0
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VepHgvs
|
2
|
+
require 'bio-ensembl-rest'
|
3
|
+
def vep(species="human",reference_type=nil)
|
4
|
+
return unless self.first.to_hgvs
|
5
|
+
if reference_type.nil?
|
6
|
+
reference_type = self.first.seqname.match(/^ENS/) ? "c" : "g"
|
7
|
+
end
|
8
|
+
EnsemblRest.connect_db
|
9
|
+
JSON.parse(EnsemblRest::Variation.vep_hgvs(species,self.to_hgvs(reference_type)))
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.consequences_for_transcript (json_object,tscript)
|
13
|
+
if json_object.length > 0
|
14
|
+
if json_object.first["transcript_consequences"]
|
15
|
+
consequences = json_object.first["transcript_consequences"]
|
16
|
+
consequences.keep_if{|a| a["transcript_id"] == tscript}
|
17
|
+
consequences.map{|a| {"Allele" => json_object.first["allele_string"], "CDS position" => a["cds_start"], "Protein start" => a["protein_start"], "Mutation" => a["amino_acids"], "Consequence" => a["consequence_terms"]}}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module MutationsCLI
|
2
|
+
@default_species = "human"
|
3
|
+
@tag_to_add = "YH:m"
|
4
|
+
class << self
|
5
|
+
attr_accessor :default_species, :tag_to_add
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.tag (sam, config, species=MutationsCLI.default_species)
|
9
|
+
# With multiple files, could end up with duplicate headers...
|
10
|
+
if sam.match(/^@/)
|
11
|
+
if config[:single_product]
|
12
|
+
config[:outfile].puts sam
|
13
|
+
return
|
14
|
+
else
|
15
|
+
# If we have multiple products, output sam headers to each output file
|
16
|
+
config.each do |key, config_hash|
|
17
|
+
next if [:start_length].include? key
|
18
|
+
config_hash[:outfile].puts sam
|
19
|
+
end
|
20
|
+
return
|
21
|
+
end
|
22
|
+
end
|
23
|
+
sam = Bio::DB::Alignment.new(sam)
|
24
|
+
# DRY up:
|
25
|
+
unless config[:single_product]
|
26
|
+
first_bases = sam.seq[0..config[:start_length]-1].upcase
|
27
|
+
config[first_bases] ? config = config[first_bases] : return
|
28
|
+
end
|
29
|
+
# Stop if a search file is specified, and this isn't it.
|
30
|
+
return if MutationsCLI.not_included_file?(config, ARGF)
|
31
|
+
mut_array = sam.mutations(config[:offset],config[:length],config[:translation_start])
|
32
|
+
if mut_array
|
33
|
+
new_tag = Bio::DB::Tag.new(MutationsCLI.tag_to_add + ":" + mut_array.to_hgvs)
|
34
|
+
config[:outfile].puts sam.add_tag(new_tag)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns a MutationArray
|
39
|
+
def self.call_mutations sam, config
|
40
|
+
unless config[:single_product]
|
41
|
+
first_bases = sam.seq[0..config[:start_length]-1].upcase
|
42
|
+
config[first_bases] ? config = config[first_bases] : return
|
43
|
+
end
|
44
|
+
MutationsCLI.call_mutations_given_product sam, config
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.call_mutations_given_product sam, config
|
48
|
+
# Stop if a search file is specified, and this isn't it.
|
49
|
+
return if MutationsCLI.not_included_file?(config, ARGF)
|
50
|
+
sam.mutations(config[:offset],config[:length],config[:translation_start])
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.not_included_file? config, input
|
54
|
+
config[:file] && input.filename !~ config[:file]
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.set_defaults config_hash
|
58
|
+
config_hash[:start] ||= "." # i.e. regexp will match anything
|
59
|
+
config_hash[:offset] ||= 1
|
60
|
+
config_hash[:length] ||= 100
|
61
|
+
config_hash[:translation_start] ||= 1
|
62
|
+
config_hash[:file] = Regexp.new(config_hash[:file]) if config_hash[:file]
|
63
|
+
config_hash
|
64
|
+
end
|
65
|
+
|
66
|
+
# Allows multiple amplicons to be considered
|
67
|
+
# Organises the configuration data by sequence start
|
68
|
+
def self.construct_products config_hash
|
69
|
+
new_hash = {}
|
70
|
+
config_hash[:products].each do |product_name, config|
|
71
|
+
new_hash[config[:start]] = config
|
72
|
+
new_hash[config[:start]][:output] ||= product_name + ".sam"
|
73
|
+
new_hash[config[:start]][:outfile] = File.open(new_hash[config[:start]][:output],'w')
|
74
|
+
end
|
75
|
+
lengths = new_hash.keys.map!(&:length).uniq
|
76
|
+
new_hash[:start_length] = lengths[0]
|
77
|
+
warn "Start sequences given must be same length" if lengths.size > 1
|
78
|
+
new_hash
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
|
83
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
require 'rubygems'
|
18
|
+
require 'bundler'
|
19
|
+
begin
|
20
|
+
Bundler.setup(:default, :development)
|
21
|
+
rescue Bundler::BundlerError => e
|
22
|
+
$stderr.puts e.message
|
23
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
24
|
+
exit e.status_code
|
25
|
+
end
|
26
|
+
require 'test/unit'
|
27
|
+
require 'shoulda'
|
28
|
+
|
29
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
30
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
31
|
+
require 'bio-sam-mutation'
|
32
|
+
|
33
|
+
class Test::Unit::TestCase
|
34
|
+
end
|
data/test/test_cigar.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'helper'
|
2
|
+
class CigarTest < Test::Unit::TestCase
|
3
|
+
def test_partition
|
4
|
+
s = Bio::Alignment::CIGAR.new("M 1 D 2 I 3","GAT",source="exonerate")
|
5
|
+
assert_equal([["M",1],["D",2],["I",3]], s.pairs)
|
6
|
+
assert_equal(3, s.pairs.length)
|
7
|
+
assert_equal(1, s.matched_length)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_auto_detect
|
11
|
+
exonerate = Bio::Alignment::CIGAR.new("M 1 D 2 I 3","GAT")
|
12
|
+
sam = Bio::Alignment::CIGAR.new("2M5D4M","ATCCTCCGGAA")
|
13
|
+
assert_raise {Bio::Alignment::CIGAR.new("rubbish","GATC")}
|
14
|
+
assert_nothing_raised {Bio::Alignment::CIGAR.new("M 1 D 2 I 3","GAT")}
|
15
|
+
assert_equal [["M",1],["D",2],["I",3]], exonerate.pairs
|
16
|
+
assert_equal [["M",2],["D",5],["M",4]], sam.pairs
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_subalignment
|
20
|
+
m = Bio::Alignment::CIGAR.new("M 35","GGATCGATCGATCGATCGATCGATCGATCGATCGA")
|
21
|
+
msa = m.subalignment(10,12)
|
22
|
+
assert_equal "GATCGATCGATC", msa.reference
|
23
|
+
assert_equal [["M", 12]], msa.pairs
|
24
|
+
|
25
|
+
s = Bio::Alignment::CIGAR.new("M 16 I 1 M 325 D 3 M 4 D 2 M 178 I 1 M 17","TTTAATTGCATTTAATTGCATTTAATTGCATTAATTGCATGGTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTA")
|
26
|
+
sa = s.subalignment(340,7)
|
27
|
+
# M 16 + M 325 [I not included] = 341
|
28
|
+
# Start at 340 = include 340 and 341, i.e. M 2
|
29
|
+
# Total of all M+D in subalignment should be 7
|
30
|
+
assert_equal([["M", 2],["D",3],["M",2]],sa.pairs)
|
31
|
+
assert_equal("CATTTAA",sa.reference)
|
32
|
+
# Case where subalignment starts at the end of a pair (M 325 in test case)
|
33
|
+
sa2 = s.subalignment(341,7)
|
34
|
+
assert_equal([["M", 1],["D",3],["M",3]],sa2.pairs)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_subcigar
|
38
|
+
s = Bio::Alignment::CIGAR.new("M 16 I 1 M 325 D 3 M 4 D 2 M 178 I 1 M 17","TTTAATTGCATTTAATTGCATTTAATTGCATTAATTGCATGGTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTAATTGCATTTA")
|
39
|
+
soft = Bio::Alignment::CIGAR.new("1S5M6D15M","CCCTGACGTTGAGGTGGATGGGTTCTCTGAGCTTCGG",source="sam")
|
40
|
+
assert_equal [["M", 2],["I",1],["M",4]], s.subcigar(15,7).pairs
|
41
|
+
assert_equal [["M",16],["I",1]], s.subcigar(1,17).pairs
|
42
|
+
assert_equal [["S",1],["M",2]], soft.subcigar(1,3).pairs
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_small
|
46
|
+
s = Bio::Alignment::CIGAR.new("M 20 D 1 I 1 M 1 D 8 I 2 M 10","GGATCGATCGATCGATCGATCGATCGATCGATCGATCGAT")
|
47
|
+
assert_equal([["M",20],["M",1],["M",1],["D",8],["I",2],["M",10]],s.remove_small!.pairs)
|
48
|
+
# Could improve by combining adjacent pairs of same type.
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_small_deletions
|
52
|
+
d = Bio::Alignment::CIGAR.new("M 20 D 1 M 10 D 4","GGATCGATCGATCGATCGATCGATCGATCGATCGA")
|
53
|
+
i = Bio::Alignment::CIGAR.new("M 20 I 1 M 10 D 4","GGATCGATCGATCGATCGATCGATCGATCGATCG")
|
54
|
+
assert_equal([["M",20],["M",1],["M",10],["D",4]],d.remove_small!.pairs)
|
55
|
+
assert_equal([["M",20],["M",10],["D",4]],i.remove_small!.pairs)
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_lengths
|
60
|
+
m = Bio::Alignment::CIGAR.new("M 1 D 2 M 3 I 4 M 5","AAAATAAAATA")
|
61
|
+
d = Bio::Alignment::CIGAR.new("M 1 D 2 M 3 I 4 D 5","AAAATAAAATA")
|
62
|
+
i = Bio::Alignment::CIGAR.new("M 1 I 2 M 3 I 4 D 5","AAAATAAAA")
|
63
|
+
assert_equal(9,m.matched_length)
|
64
|
+
assert_equal(7,d.deleted_length)
|
65
|
+
assert_equal(6,i.inserted_length)
|
66
|
+
assert_equal(11,m.reference_length)
|
67
|
+
assert_equal(11,d.reference_length)
|
68
|
+
assert_equal(9,i.reference_length)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_masking
|
72
|
+
s1 = Bio::Alignment::CIGAR.new("1S10M","AAAATAAAA",source="sam")
|
73
|
+
s2 = Bio::Alignment::CIGAR.new("10M5D","AAAATAAAA",source="sam")
|
74
|
+
h = Bio::Alignment::CIGAR.new("25H1I10M","AAAATAAAA",source="sam")
|
75
|
+
assert_equal 1, s1.masked_length
|
76
|
+
assert_equal 0, s2.masked_length
|
77
|
+
assert_equal 25, h.masked_length
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_query_length
|
81
|
+
m = Bio::Alignment::CIGAR.new("M 1 D 2 M 3 I 4 M 5","AAAATAAAATA")
|
82
|
+
d = Bio::Alignment::CIGAR.new("M 1 D 2 M 3 I 4 D 5","AAAATAAAATA")
|
83
|
+
i = Bio::Alignment::CIGAR.new("M 1 I 2 M 3 I 4 D 5","AAAATAAAA")
|
84
|
+
s1 = Bio::Alignment::CIGAR.new("1S10M","AAAATAAAA",source="sam")
|
85
|
+
s = Bio::Alignment::CIGAR.new("1S5M2D2M1I5M","AAAATAAAA",source="sam")
|
86
|
+
assert_equal 13, m.query_length
|
87
|
+
assert_equal 8, d.query_length
|
88
|
+
assert_equal 10, i.query_length
|
89
|
+
assert_equal 11, s1.query_length
|
90
|
+
assert_equal 14, s.query_length
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_query_output
|
94
|
+
m = Bio::Alignment::CIGAR.new("M 11","AAAATAAAATA")
|
95
|
+
lc = Bio::Alignment::CIGAR.new("M 11","aaaataaaata")
|
96
|
+
d = Bio::Alignment::CIGAR.new("M 5 D 2 M 4","AAAATAAAATA")
|
97
|
+
i = Bio::Alignment::CIGAR.new("M 5 I 10 M 6","AAAATAAAATA")
|
98
|
+
i2 = Bio::Alignment::CIGAR.new("M 5 I 2 M 3 I 4 M 6","AAAATGCCAAAATA")
|
99
|
+
assert_equal("AAAATAAAATA",m.query)
|
100
|
+
assert_equal("AAAATAAAATA",lc.query)
|
101
|
+
assert_equal("AAAAT--AATA",d.query)
|
102
|
+
assert_equal("AAAAT[10]AAAATA",i.query)
|
103
|
+
assert_equal("AAAAT-insertion-AAAATA",i.query("-insertion-"))
|
104
|
+
assert_equal("AAAATttGCCataaAAAATA",i2.query(["tt","ataa"]))
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_positions
|
108
|
+
i = Bio::Alignment::CIGAR.new("M 5 I 10 M 6","AAAATAAAATA")
|
109
|
+
assert_equal({"I" => [[5, 10, 5]]}, i.positions(/I/))
|
110
|
+
d = Bio::Alignment::CIGAR.new("M 5 D 2 M 4","AAAATAAAATA")
|
111
|
+
assert_equal({"M" => [[0,5,0],[7,4,5]], "D" => [[5,2,5]]},d.positions(/[MD]/))
|
112
|
+
end
|
113
|
+
def test_positions_on_query
|
114
|
+
i = Bio::Alignment::CIGAR.new("M 5 I 10 D 3 M 6","AAAATAAAATA")
|
115
|
+
assert_equal({"D" => [[5, 3, 15]]}, i.positions(/D/))
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_hgnc
|
119
|
+
d = Bio::Alignment::CIGAR.new("M 5 D 2 M 4","AAAATAAAATA")
|
120
|
+
i = Bio::Alignment::CIGAR.new("M 5 I 10 M 6","AAAATAAAATA")
|
121
|
+
i2 = Bio::Alignment::CIGAR.new("M 5 I 2 M 3 D 1 M 6","AAAATGCCGAAAATA")
|
122
|
+
dsam = Bio::Alignment::CIGAR.new("155M6D15M","CCCTGACGTTGAGGTGGATGGGTTCTCTGAGCTTCGGTGGGATGACCAGCAGAAAGTCAAGAAGACAGCGGAAGCTGGAGGAGTGACAGGCAAAGGCCAGGATGGAATTGGTAGCAAGGCAGAGAAGACTCTGGGTGACTTTGCAGCAGAGTATGCCAAGTCCAACAGAAGTACGT",source="sam")
|
123
|
+
assert_equal "g.6_7delAA", d.hgnc
|
124
|
+
assert_equal "g.25_26insGATCGATCGA", i.hgnc(20,"GATCGATCGA")
|
125
|
+
assert_equal "g.[5_6insGA;9delG]", i2.hgnc(0,"GA")
|
126
|
+
assert_equal "g.156_161delCCAAGT", dsam.hgnc(0)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_hgnc_from_subalignment
|
130
|
+
align = Bio::Alignment::CIGAR.new("M 5 I 2 M 3 D 1 M 6","AAAATGCCGAAAATA")
|
131
|
+
sa = align.subalignment(6,7)
|
132
|
+
assert_equal([["M", 3],["D",1],["M",3]],sa.pairs)
|
133
|
+
assert_equal("GCCGAAA",sa.reference)
|
134
|
+
assert_equal "g.4delG", sa.hgnc
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_substitutions
|
138
|
+
d = Bio::Alignment::CIGAR.new("M 5 D 2 M 4","AAAATAAAATA")
|
139
|
+
s = Bio::Alignment::CIGAR.new("M 11","AAAATAAAATA")
|
140
|
+
assert_equal "c.5T>A", s.hgnc(0,[],"c",["5T>A"])
|
141
|
+
assert_equal "g.[6_7delAA;1A>T]", d.hgnc(0,[],"g",["1A>T"])
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
data/test/test_mdtag.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'helper'
|
2
|
+
class MDZTest < Test::Unit::TestCase
|
3
|
+
def test_match
|
4
|
+
mdz = Bio::DB::Tag::MD.new("MD:Z:60^G13")
|
5
|
+
assert_equal "60^G13", mdz.tag
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_ref_length
|
9
|
+
mdz_del = Bio::DB::Tag::MD.new("MD:Z:60^G13")
|
10
|
+
assert_equal(mdz_del.ref_length, 74)
|
11
|
+
mdz_sub = Bio::DB::Tag::MD.new("MD:Z:60G0A13")
|
12
|
+
assert_equal(mdz_sub.ref_length, 75)
|
13
|
+
mdz_none = Bio::DB::Tag::MD.new("MD:Z:150")
|
14
|
+
assert_equal(mdz_none.ref_length, 150)
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_pairs
|
19
|
+
mdz = Bio::DB::Tag::MD.new("MD:Z:60^G13T")
|
20
|
+
assert_equal [["m",60],["d","G"],["m",13],["s","T"]], mdz.pairs
|
21
|
+
assert_equal [["m",60,0,0],["d","G",60,60],["m",13,61,60],["s","T",74,73]], mdz.cumulative
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_reconstruct_tag
|
25
|
+
mdz = Bio::DB::Tag::MD.new("MD:Z:60^G13T")
|
26
|
+
assert_equal "60^G13T", mdz.reconstruct_tag
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_slice
|
30
|
+
mdz = Bio::DB::Tag::MD.new("MD:Z:60^G13T")
|
31
|
+
|
32
|
+
new_mdz = Bio::DB::Tag::MD.new("MD:Z:6^G3")
|
33
|
+
assert_equal new_mdz.tag, mdz.slice(55,10).tag
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_report
|
37
|
+
mdz_del = Bio::DB::Tag::MD.new("MD:Z:60^G13")
|
38
|
+
assert_equal([["d","G",60,60]], mdz_del.deletions)
|
39
|
+
mdz_sub = Bio::DB::Tag::MD.new("MD:Z:60G0A13")
|
40
|
+
assert_equal([["s","G",60,60],["s","A",61,61]], mdz_sub.substitutions)
|
41
|
+
mdz_none = Bio::DB::Tag::MD.new("MD:Z:150")
|
42
|
+
assert_equal([], mdz_none.report)
|
43
|
+
mdz_del_sub = Bio::DB::Tag::MD.new("MD:Z:60^G5A13")
|
44
|
+
assert_equal [["s","A",66,65]], mdz_del_sub.substitutions
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'helper'
|
2
|
+
class MutantAlleleTest < Test::Unit::TestCase
|
3
|
+
def test_initialization
|
4
|
+
ma = MutantAllele.new
|
5
|
+
assert_equal 0, ma.count
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_cached_lookup
|
9
|
+
ma = MutantAllele.new
|
10
|
+
m = Bio::Mutation.new
|
11
|
+
m.position = 358
|
12
|
+
m.reference = "TCC"
|
13
|
+
m.seqname = "ENST00000366794"
|
14
|
+
m.type = :deletion
|
15
|
+
m.mutant = nil
|
16
|
+
ma.mutations = Bio::MutationArray.new([m])
|
17
|
+
MutantAllele.previous_lookups[ma.mutations.to_hgvs] = "mock previous lookup"
|
18
|
+
assert_equal "mock previous lookup", ma.lookup
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'helper'
|
2
|
+
class MutationTest < Test::Unit::TestCase
|
3
|
+
def test_mutation_initialisation
|
4
|
+
params = {position: 1234,
|
5
|
+
type: :deletion,
|
6
|
+
reference: "ATGG",
|
7
|
+
mutant: nil,
|
8
|
+
seqname: 5}
|
9
|
+
mut = Bio::Mutation.new(params)
|
10
|
+
assert_equal 1234, mut.position
|
11
|
+
assert_equal :deletion, mut.type
|
12
|
+
assert_equal "ATGG", mut.reference
|
13
|
+
assert_nil mut.mutant
|
14
|
+
assert_equal 5, mut.seqname
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_single_deletion_hgvs
|
18
|
+
params = {position: 1234,
|
19
|
+
type: :deletion,
|
20
|
+
reference: "G",
|
21
|
+
mutant: nil,
|
22
|
+
seqname: 5}
|
23
|
+
mut = Bio::Mutation.new(params)
|
24
|
+
assert_equal "1234delG", mut.to_hgvs
|
25
|
+
assert_equal "5:g.1234delG", mut.to_hgvs("g")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_deletion_hgvs
|
29
|
+
params = {position: 1234,
|
30
|
+
type: :deletion,
|
31
|
+
reference: "ATGG",
|
32
|
+
mutant: nil,
|
33
|
+
seqname: 5}
|
34
|
+
mut = Bio::Mutation.new(params)
|
35
|
+
assert_equal "1234_1237delATGG", mut.to_hgvs
|
36
|
+
assert_equal "5:g.1234_1237delATGG", mut.to_hgvs("g")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_substitution_hgvs
|
40
|
+
params = {position: 1234,
|
41
|
+
type: :substitution,
|
42
|
+
reference: "A",
|
43
|
+
mutant: "T",
|
44
|
+
seqname: 5}
|
45
|
+
mut = Bio::Mutation.new(params)
|
46
|
+
assert_equal "1234A>T", mut.to_hgvs
|
47
|
+
assert_equal "5:g.1234A>T", mut.to_hgvs("g")
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_longer_substitution_hgvs
|
51
|
+
params = {position: 1234,
|
52
|
+
type: :substitution,
|
53
|
+
reference: "ATG",
|
54
|
+
mutant: "CCT",
|
55
|
+
seqname: 5}
|
56
|
+
mut = Bio::Mutation.new(params)
|
57
|
+
assert_equal "1234_1236ATG>CCT", mut.to_hgvs
|
58
|
+
assert_equal "5:c.1234_1236ATG>CCT", mut.to_hgvs("c")
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_insertion_hgvs
|
62
|
+
params = {position: 1234,
|
63
|
+
type: :insertion,
|
64
|
+
reference: nil,
|
65
|
+
mutant: "T",
|
66
|
+
seqname: 5}
|
67
|
+
mut = Bio::Mutation.new(params)
|
68
|
+
assert_equal "1234_1235insT", mut.to_hgvs
|
69
|
+
assert_equal "5:g.1234_1235insT", mut.to_hgvs("g")
|
70
|
+
end
|
71
|
+
|
72
|
+
# def test_vep
|
73
|
+
# params = {position: 112839914,
|
74
|
+
# type: :deletion,
|
75
|
+
# reference: "ACCACC",
|
76
|
+
# mutant: nil,
|
77
|
+
# seqname: 5}
|
78
|
+
# mut = Bio::Mutation.new(params)
|
79
|
+
# result = mut.vep("human","g")
|
80
|
+
# assert_equal "inframe_deletion", result.first["most_severe_consequence"], "NB: Test written for GRCh38"
|
81
|
+
# assert_equal "ACCACC/-", result.first["allele_string"], "NB: Test written for GRCh38"
|
82
|
+
# # TODO Continue...
|
83
|
+
# end
|
84
|
+
end
|