-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from camilogarciabotero/dev
Improve BCM struct correctness and other features
- Loading branch information
Showing
8 changed files
with
151 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
function _int_to_dna(index::Int64; extended_alphabet::Bool = false) | ||
A = extended_alphabet ? [DNA_Gap, DNA_A, DNA_C, DNA_M, DNA_G, DNA_R, DNA_S, DNA_V, DNA_T, DNA_W, DNA_Y, DNA_H, DNA_K, DNA_D, DNA_B, DNA_N] : [DNA_A, DNA_C, DNA_G, DNA_T] | ||
return LongSequence{DNAAlphabet{4}}([A[index]]) | ||
function _int_to_dna(index::Int64) | ||
# A = extended_alphabet ? alphabet(DNA) : ACGT | ||
modifier(value) = (value == 3) ? 4 : (value == 4) ? 8 : value | ||
return reinterpret.(DNA, Int8(modifier(index))) #LongSequence{DNAAlphabet{4}}([A[index]]) # reinterpret.(DNA, Int8(1)) == A, reinterpret.(Int8, DNA_A) = 1 | ||
end | ||
|
||
function _dna_to_int(nucleotide::DNA; extended_alphabet::Bool = false) | ||
A = extended_alphabet ? [DNA_Gap, DNA_A, DNA_C, DNA_M, DNA_G, DNA_R, DNA_S, DNA_V, DNA_T, DNA_W, DNA_Y, DNA_H, DNA_K, DNA_D, DNA_B, DNA_N] : [DNA_A, DNA_C, DNA_G, DNA_T] | ||
return findfirst(nucleotide, LongSequence{DNAAlphabet{4}}(A)) | ||
function _dna_to_int(nucleotide::DNA) | ||
# A = extended_alphabet ? [DNA_Gap, DNA_A, DNA_C, DNA_M, DNA_G, DNA_R, DNA_S, DNA_V, DNA_T, DNA_W, DNA_Y, DNA_H, DNA_K, DNA_D, DNA_B, DNA_N] : [DNA_A, DNA_C, DNA_G, DNA_T] | ||
modifier(value) = (value == DNA_G) ? DNA_M : (value == DNA_T) ? DNA_G : value | ||
return reinterpret.(Int8, modifier(nucleotide))[1] #searchsortedfirst(A, nucleotide) # findfirst(nucleotide, LongSequence{DNAAlphabet{4}}(A)) | ||
end | ||
|
||
function randbmc(statespace::DataType, n::Int64=1) | ||
if statespace == DNA || statespace == RNA | ||
tpm = rand(4, 4) | ||
row_sums = sum(tpm, dims=2) | ||
inits = rand(4) | ||
init_sum = sum(inits) | ||
@views tpm ./= row_sums | ||
@views inits ./= init_sum | ||
elseif statespace == AminoAcid | ||
tpm = rand(20, 20) | ||
row_sums = sum(tpm, dims=2) | ||
inits = rand(20) | ||
init_sum = sum(inits) | ||
@views tpm ./= row_sums | ||
@views inits ./= init_sum | ||
else | ||
error("Alphabet must be of the DNA, RNA or AminoAcid DataType") | ||
|
||
if !(statespace in (DNA, RNA, AminoAcid)) | ||
throw(ArgumentError("Alphabet must be of the DNA, RNA, or AminoAcid DataType.")) | ||
end | ||
|
||
nstates = (statespace == AminoAcid) ? 20 : 4 | ||
tpm = rand(nstates, nstates) | ||
|
||
# Normalize rows of the transition probability matrix | ||
rowsums = sum(tpm, dims=2) | ||
@views tpm ./= rowsums | ||
|
||
# Generate random initial probabilities and normalize them | ||
inits = rand(nstates) | ||
initsum = sum(inits) | ||
@views inits ./= initsum | ||
|
||
return BMC(statespace, tpm, inits, n) | ||
end | ||
end |