-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Genetic #42
Open
soniamitchell
wants to merge
14
commits into
dev
Choose a base branch
from
genetic
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Genetic #42
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
173b4d1
initial commit
soniamitchell 3020fe7
export genDistance
soniamitchell 726a281
typo
soniamitchell f622115
rename
soniamitchell 7efb6b0
typo
soniamitchell da8b15a
create genetic type
soniamitchell 772146d
Commented out code isn't useful
soniamitchell e2f3e7f
add second constructor
soniamitchell 53f5072
Merge branch 'dev' into genetic
richardreeve a884b04
Fix Genetics as an extension
richardreeve 610a99f
Add in extra packages for 1.8 requires
richardreeve 4e3bb38
Nest @requires correctly
richardreeve 907543e
Package compat updates
richardreeve 38515ec
Merge branch 'dev' into genetic
richardreeve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,68 @@ | ||
# using Diversity | ||
# using Diversity.API | ||
using Diversity | ||
using Diversity.API | ||
|
||
# using PopGen | ||
# using StringDistances | ||
# using LinearAlgebra | ||
using PopGen | ||
using StringDistances | ||
using LinearAlgebra | ||
|
||
# using FASTX | ||
using FASTX | ||
|
||
# abstract type AbstractGeneticTypes{PopData} <: | ||
# Diversity.API.AbstractTypes | ||
# end | ||
abstract type AbstractGeneticTypes{PopData} <: | ||
Diversity.API.AbstractTypes | ||
end | ||
|
||
# struct GeneticType{PopData} <: AbstractGeneticTypes{PopData} | ||
# dat::PopData | ||
# ntypes::Int64 | ||
# Zmatrix::Matrix{Float64} | ||
# end | ||
struct GeneticType{PopData} <: AbstractGeneticTypes{PopData} | ||
dat::PopData | ||
ntypes::Int64 | ||
Zmatrix::Matrix{Float64} | ||
end | ||
|
||
# function _hammingDistance(geno1, geno2) | ||
# ismissing(geno1) || ismissing(geno2) && return missing | ||
# if length(geno1) > 2 | ||
# @warn "hamming_distance may not work correctly for ploidy > 2" | ||
# end | ||
# #TODO Fix ploidy > 2 - e.g. (1, 1, 1, 2) ≠ (1, 2, 2, 2) | ||
function _hammingDistance(geno1, geno2) | ||
ismissing(geno1) || ismissing(geno2) && return missing | ||
if length(geno1) > 2 | ||
@warn "hamming_distance may not work correctly for ploidy > 2" | ||
end | ||
#TODO Fix ploidy > 2 - e.g. (1, 1, 1, 2) ≠ (1, 2, 2, 2) | ||
|
||
# max(sum(geno1 .∉ Ref(geno2)), sum(geno2 .∉ Ref(geno1))) | ||
# end | ||
max(sum(geno1 .∉ Ref(geno2)), sum(geno2 .∉ Ref(geno1))) | ||
end | ||
|
||
# function GeneticType(dat::PopData) | ||
# # Initialise objects | ||
# matrix_obj = PopGen.loci_matrix(dat) | ||
# ntypes = size(matrix_obj, 1) | ||
# output = zeros(Float64, ntypes, ntypes) | ||
# indices = PopGen.pairwise_pairs(1:ntypes) | ||
function GeneticType(dat::PopData) | ||
# Initialise objects | ||
matrix_obj = PopGen.loci_matrix(dat) | ||
ntypes = size(matrix_obj, 1) | ||
output = zeros(Float64, ntypes, ntypes) | ||
indices = PopGen.pairwise_pairs(1:ntypes) | ||
|
||
# # Calculate distance matrix | ||
# for (a, b) in indices | ||
# output[a, b] = sum(_hammingDistance.((@view matrix_obj[a, :]), | ||
# (@view matrix_obj[b, :]))) | ||
# end | ||
# dist = Symmetric(output) | ||
# dist /= maximum(dist) | ||
# Calculate distance matrix | ||
for (a, b) in indices | ||
output[a, b] = sum(_hammingDistance.((@view matrix_obj[a, :]), | ||
(@view matrix_obj[b, :]))) | ||
end | ||
dist = Symmetric(output) | ||
dist /= maximum(dist) | ||
|
||
# # Calculate similarity matrix | ||
# Zmatrix = 1 .- dist | ||
# Calculate similarity matrix | ||
Zmatrix = 1 .- dist | ||
|
||
# return GeneticType{PopData}(dat, ntypes, Zmatrix) | ||
# end | ||
return GeneticType{PopData}(dat, ntypes, Zmatrix) | ||
end | ||
|
||
# function GeneticType(dat::Vector) # Vector{BioSequences.AminoAcidSequence} | ||
# # Initialise objects | ||
# ntypes = length(dat) | ||
# output = zeros(Int64, ntypes, ntypes) | ||
# indices = PopGen.pairwise_pairs(1:ntypes) | ||
function GeneticType(dat::Vector) # Vector{BioSequences.AminoAcidSequence} | ||
# Initialise objects | ||
ntypes = length(dat) | ||
output = zeros(Int64, ntypes, ntypes) | ||
indices = PopGen.pairwise_pairs(1:ntypes) | ||
|
||
# # Calculate distance matrix | ||
# for (a, b) in indices | ||
# output[a, b] = evaluate(Hamming(), dat[a], dat[b]) | ||
# end | ||
# dist = Symmetric(output) | ||
# dist /= maximum(dist) | ||
# Calculate distance matrix | ||
for (a, b) in indices | ||
output[a, b] = evaluate(Hamming(), dat[a], dat[b]) | ||
end | ||
dist = Symmetric(output) | ||
dist /= maximum(dist) | ||
|
||
# # Calculate similarity matrix | ||
# Zmatrix = 1 .- dist | ||
# Calculate similarity matrix | ||
Zmatrix = 1 .- dist | ||
|
||
# return GeneticType{BioSequences.AminoAcidSequence}(dat, ntypes, Zmatrix) | ||
# end | ||
return GeneticType{BioSequences.AminoAcidSequence}(dat, ntypes, Zmatrix) | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, as a for instance, I would make this some arbitrary "
Data
" type, which is defined when you construct the object (noteData
must not already exist!):There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alrighty, got both constructors working. Wondering though if
AbstractGenetic
is necessary? Since the two genetic types could just as easily be subtypes ofDiversity.API.AbstractTypes
, unless you want genetic types to be treated differently?