Skip to content

Commit

Permalink
Merged branch develop into master
Browse files Browse the repository at this point in the history
  • Loading branch information
albertopessia committed Feb 15, 2017
2 parents 584b787 + 948a220 commit 247a55f
Show file tree
Hide file tree
Showing 35 changed files with 1,305 additions and 1,855 deletions.
33 changes: 0 additions & 33 deletions src/boot.jl

This file was deleted.

4 changes: 2 additions & 2 deletions src/mcmc/algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function splitmerge!(ij::Vector{Int},
end
end

shuffle!(neighbours, S)
shuffleunits!(neighbours, S)

split!(ij, neighbours, S, data, priorR, priorC, settings, support, state)
else
Expand All @@ -336,7 +336,7 @@ function splitmerge!(ij::Vector{Int},
end
end

shuffle!(neighbours, S)
shuffleunits!(neighbours, S)

merge!(ij, neighbours, S, data, priorR, priorC, settings, support, state)
end
Expand Down
2 changes: 1 addition & 1 deletion src/mcmc/gibbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function gibbs!(data::Matrix{UInt8},
settings::KSettings,
support::MCMCSupport,
state::AminoAcidState)
shuffle!(support.u)
shuffleunits!(support.u)

for a in support.u
resizesupport!(support, state.k + 1)
Expand Down
6 changes: 3 additions & 3 deletions src/misc/basic_functions.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of Kpax3. License is MIT.

function shuffle!(x::Vector{Int})
function shuffleunits!(x::Vector{Int})
for i = length(x):-1:2
j = rand(1:i)
x[i], x[j] = x[j], x[i]
Expand All @@ -9,8 +9,8 @@ function shuffle!(x::Vector{Int})
nothing
end

function shuffle!(x::Vector{Int},
S::Int)
function shuffleunits!(x::Vector{Int},
S::Int)
for i = S:-1:2
j = rand(1:i)
x[i], x[j] = x[j], x[i]
Expand Down
110 changes: 40 additions & 70 deletions test/data_processing/data_processing.jl
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
# This file is part of Kpax3. License is MIT.

function test_data_processing_exceptions()
missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's',
'v', 'w', 'x', 'y', 'j', 'z']

@test_throws KFASTAError readfasta("data/empty_file.fasta", false, missdna,
100000000, false, 0)
@test_throws KFASTAError readfasta("data/no_1st_seq.fasta", false, missdna,
100000000, false, 0)
@test_throws KFASTAError readfasta("data/no_id_char.fasta", false, missdna,
100000000, false, 0)
@test_throws KFASTAError readfasta("data/no_nth_seq.fasta", false, missdna,
100000000, false, 0)

@test_throws KFASTAError readfasta("data/utf8_id.fasta", false, missdna,
100000000, false, 0)
@test_throws KFASTAError readfasta("data/utf8_seq.fasta", false, missdna,
100000000, false, 0)
missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z']

@test_throws Kpax3.KFASTAError Kpax3.readfasta("data/empty_file.fasta", false, missdna, 100000000, false, 0)
@test_throws Kpax3.KFASTAError Kpax3.readfasta("data/no_1st_seq.fasta", false, missdna, 100000000, false, 0)
@test_throws Kpax3.KFASTAError Kpax3.readfasta("data/no_id_char.fasta", false, missdna, 100000000, false, 0)
@test_throws Kpax3.KFASTAError Kpax3.readfasta("data/no_nth_seq.fasta", false, missdna, 100000000, false, 0)

@test_throws Kpax3.KFASTAError Kpax3.readfasta("data/utf8_id.fasta", false, missdna, 100000000, false, 0)
@test_throws Kpax3.KFASTAError Kpax3.readfasta("data/utf8_seq.fasta", false, missdna, 100000000, false, 0)

nothing
end

test_data_processing_exceptions()

function test_data_processing_read_blanks()
missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's',
'v', 'w', 'x', 'y', 'j', 'z']
missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z']

(data, id, refseq) = readfasta("data/blanks.fasta", false, missdna,
100000000, false, 0)
(data, id, refseq) = Kpax3.readfasta("data/blanks.fasta", false, missdna, 100000000, false, 0)
@test data == UInt8['g' 'a';
'a' 'g';
'g' 'c';
'c' 'g';
'a' 'g';
'g' 'c']
@test id == String["ID1", "ID5"]
@test refseq == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.',
'a']
@test refseq == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', 'a']

@test_throws KDomainError categorical2binary(data, UInt8(1), UInt8('?'))
@test_throws Kpax3.KDomainError Kpax3.categorical2binary(data, UInt8(1), UInt8('?'))

(bindata, val, key) = categorical2binary(data, UInt8(127), UInt8('?'))
(bindata, val, key) = Kpax3.categorical2binary(data, UInt8(127), UInt8('?'))
@test bindata == UInt8[0 1;
1 0;
1 0;
Expand All @@ -54,33 +44,28 @@ function test_data_processing_read_blanks()
0 1;
0 1;
1 0]
@test val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c',
'g']
@test val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c', 'g']
@test key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]

(data, id, refseq) = readfasta("data/blanks.fasta", false, missdna, 1, false,
0)
(data, id, refseq) = Kpax3.readfasta("data/blanks.fasta", false, missdna, 1, false, 0)
@test data == UInt8['g' 'a';
'a' 'g';
'g' 'c';
'c' 'g';
'a' 'g';
'g' 'c']
@test id == String["ID1", "ID5"]
@test refseq == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.',
'a']
@test refseq == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', 'a']

nothing
end

test_data_processing_read_blanks()

function test_data_processing_proper_dna_file()
missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's',
'v', 'w', 'x', 'y', 'j', 'z']
missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z']

(data, id, refseq) = readfasta("data/proper_nt.fasta", false, missdna,
100000000, false, 0)
(data, id, refseq) = Kpax3.readfasta("data/proper_nt.fasta", false, missdna, 100000000, false, 0)

@test data == UInt8['t' 't' 't' 't' 't' 'c';
'g' 'g' 'a' 'g' 'a' 'a';
Expand All @@ -91,12 +76,11 @@ function test_data_processing_proper_dna_file()
'a' 'a' 't' 't' 'a' 'a';
'g' 'c' 'g' 'g' 'c' 'g']
@test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"]
@test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.',
'a']
@test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', 'a']

@test_throws KDomainError categorical2binary(data, UInt8(1), UInt8('?'))
@test_throws Kpax3.KDomainError Kpax3.categorical2binary(data, UInt8(1), UInt8('?'))

(bindata, val, key) = categorical2binary(data, UInt8(127), UInt8('?'))
(bindata, val, key) = Kpax3.categorical2binary(data, UInt8(127), UInt8('?'))
@test bindata == UInt8[0 0 0 0 0 1;
1 1 1 1 1 0;
0 0 1 0 1 1;
Expand All @@ -115,12 +99,10 @@ function test_data_processing_proper_dna_file()
0 0 1 1 0 0;
0 1 0 0 1 0;
1 0 1 1 0 1]
@test val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'c', 'g', 'a', 'c', 'g',
'a', 'g', 't', 'a', 't', 'c', 'g']
@test val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'c', 'g', 'a', 'c', 'g', 'a', 'g', 't', 'a', 't', 'c', 'g']
@test key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8]

(data, id, refseq) = readfasta("data/proper_nt.fasta", false, missdna, 1,
false, 0)
(data, id, refseq) = Kpax3.readfasta("data/proper_nt.fasta", false, missdna, 1, false, 0)
@test data == UInt8['t' 't' 't' 't' 't' 'c';
'g' 'g' 'a' 'g' 'a' 'a';
'a' 'a' '?' 'g' 'g' '?';
Expand All @@ -130,12 +112,10 @@ function test_data_processing_proper_dna_file()
'a' 'a' 't' 't' 'a' 'a';
'g' 'c' 'g' 'g' 'c' 'g']
@test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"]
@test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.',
'a']
@test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', 'a']

# consider all characters
(data, id, refseq) = readfasta("data/proper_nt.fasta", false,
zeros(UInt8, 1), 100000000, false, 0)
(data, id, refseq) = Kpax3.readfasta("data/proper_nt.fasta", false, zeros(UInt8, 1), 100000000, false, 0)
@test data == UInt8['t' 't' 't' 't' 't' 'c';
'g' 'g' 'a' 'g' 'a' 'a';
'a' 'a' 'x' 'g' 'g' 'x';
Expand All @@ -146,12 +126,11 @@ function test_data_processing_proper_dna_file()
'g' 'c' 'g' 'g' 'c' 'g';
'a' 'x' 'a' 'a' 'a' 'a']
@test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"]
@test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.',
'.']
@test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', '.']

@test_throws KDomainError categorical2binary(data, UInt8(1), UInt8('\0'))
@test_throws Kpax3.KDomainError Kpax3.categorical2binary(data, UInt8(1), UInt8('\0'))

(bindata, val, key) = categorical2binary(data, UInt8(127), UInt8('\0'))
(bindata, val, key) = Kpax3.categorical2binary(data, UInt8(127), UInt8('\0'))
@test bindata == UInt8[0 0 0 0 0 1;
1 1 1 1 1 0;
0 0 1 0 1 1;
Expand All @@ -173,8 +152,7 @@ function test_data_processing_proper_dna_file()
1 0 1 1 0 1;
1 0 1 1 1 1;
0 1 0 0 0 0]
@test val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'x', 'c', 'g', 'a', 'c',
'g', 'a', 'g', 't', 'a', 't', 'c', 'g', 'a', 'x']
@test val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'x', 'c', 'g', 'a', 'c', 'g', 'a', 'g', 't', 'a', 't', 'c', 'g', 'a', 'x']
@test key == [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9]

nothing
Expand All @@ -185,8 +163,7 @@ test_data_processing_proper_dna_file()
function test_data_processing_proper_protein_file()
misspro = UInt8['?', '*', '#', '-', 'b', 'j', 'x', 'z']

(data, id, refseq) = readfasta("data/proper_aa.fasta", true, misspro,
100000000, false, 0)
(data, id, refseq) = Kpax3.readfasta("data/proper_aa.fasta", true, misspro, 100000000, false, 0)

@test data == UInt8['k' 'k' 'k' 'k' 'k' 'e';
'k' 'k' 'i' 'k' 'i' 'i';
Expand All @@ -197,10 +174,9 @@ function test_data_processing_proper_protein_file()
'c' 'c' 'y' 'y' 'c' 'c';
'a' 'a' 't' 'a' 't' 't']
@test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"]
@test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.',
'f']
@test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', 'f']

(bindata, val, key) = categorical2binary(data, UInt8(127), UInt8('?'))
(bindata, val, key) = Kpax3.categorical2binary(data, UInt8(127), UInt8('?'))
@test bindata == UInt8[0 0 0 0 0 1;
1 1 1 1 1 0;
0 0 1 0 1 1;
Expand All @@ -219,12 +195,10 @@ function test_data_processing_proper_protein_file()
0 0 1 1 0 0;
1 1 0 1 0 0;
0 0 1 0 1 1]
@test val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'l', 'v', 'c', 'l', 't',
'e', 'l', 'm', 'c', 'y', 'a', 't']
@test val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'l', 'v', 'c', 'l', 't', 'e', 'l', 'm', 'c', 'y', 'a', 't']
@test key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8]

(data, id, refseq) = readfasta("data/proper_aa.fasta", true, misspro, 1,
false, 0)
(data, id, refseq) = Kpax3.readfasta("data/proper_aa.fasta", true, misspro, 1, false, 0)
@test data == UInt8['k' 'k' 'k' 'k' 'k' 'e';
'k' 'k' 'i' 'k' 'i' 'i';
'l' 'l' '?' 'v' 'v' '?';
Expand All @@ -234,12 +208,10 @@ function test_data_processing_proper_protein_file()
'c' 'c' 'y' 'y' 'c' 'c';
'a' 'a' 't' 'a' 't' 't']
@test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"]
@test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.',
'f']
@test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', 'f']

# consider all characters
(data, id, refseq) = readfasta("data/proper_aa.fasta", true, zeros(UInt8, 1),
100000000, false, 0)
(data, id, refseq) = Kpax3.readfasta("data/proper_aa.fasta", true, zeros(UInt8, 1), 100000000, false, 0)
@test data == UInt8['k' 'k' 'k' 'k' 'k' 'e';
'k' 'k' 'i' 'k' 'i' 'i';
'l' 'l' 'x' 'v' 'v' 'x';
Expand All @@ -250,10 +222,9 @@ function test_data_processing_proper_protein_file()
'a' 'a' 't' 'a' 't' 't';
'f' 'x' 'f' 'f' 'f' 'f']
@test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"]
@test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.',
'.']
@test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', '.']

(bindata, val, key) = categorical2binary(data, UInt8(127), UInt8('\0'))
(bindata, val, key) = Kpax3.categorical2binary(data, UInt8(127), UInt8('\0'))
@test bindata == UInt8[0 0 0 0 0 1;
1 1 1 1 1 0;
0 0 1 0 1 1;
Expand All @@ -275,8 +246,7 @@ function test_data_processing_proper_protein_file()
0 0 1 0 1 1;
1 0 1 1 1 1;
0 1 0 0 0 0]
@test val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'x', 'l', 'v', 'c', 'l',
't', 'e', 'l', 'm', 'c', 'y', 'a', 't', 'f', 'x']
@test val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'x', 'l', 'v', 'c', 'l', 't', 'e', 'l', 'm', 'c', 'y', 'a', 't', 'f', 'x']
@test key == [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9]

nothing
Expand Down
Loading

0 comments on commit 247a55f

Please sign in to comment.