-
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
V0.4 #127
Draft
kose-y
wants to merge
13
commits into
OpenMendel:master
Choose a base branch
from
kaitlynmarlor:v0.4
base: master
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.
Draft
V0.4 #127
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8b68388
Add feature: Implement SnpArray iterator
kaitlynmarlor fad109e
startidx is greater than col num return nothing
kaitlynmarlor 84a92f0
updated SnpArrayIndex
kaitlynmarlor c0b31b3
added some GeneticBaseVariant functions
kaitlynmarlor f4fdbd7
Add maf helper function and maf
kaitlynmarlor fa5cfba
Add unit tests for iterator
kaitlynmarlor c42cefe
v0.4
kaitlynmarlor 6436387
v0.4
kaitlynmarlor c7bc594
return type SnpArrayIndex
kaitlynmarlor 52d8ce2
hwepval
kaitlynmarlor 8ab499c
GeneticVariantBase
kaitlynmarlor a5f4746
GeneticVariantBase
kaitlynmarlor 824a658
done
kaitlynmarlor 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
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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
mutable struct SnpArrayIterator <: VariantIterator | ||
snpdata::SnpData | ||
end | ||
|
||
struct SnpArrayIndex <: Variant | ||
index::Int | ||
end | ||
|
||
@inline function Base.eltype(::Type{<:VariantIterator}) | ||
SnpArray | ||
end | ||
|
||
function Base.iterate(itr::SnpArrayIterator, state=itr.index) | ||
if state > size(itr.snpdata.snp_info,2) | ||
return nothing | ||
else | ||
state = state + 1 | ||
result = (view(itr.snpdata.snp_info, :, state), state+1) | ||
return result | ||
end | ||
end | ||
|
||
@inline function Base.length(itr::SnpArrayIterator) | ||
return size(itr.snpdata.snp_info, 2) | ||
end | ||
|
||
@inline function snparrayiterator(snpdata::SnpData) | ||
SnpArrayIterator(snpdata) | ||
end | ||
|
||
function iterator(snpdata::SnpData; startidx=1)::SnpArrayIterator | ||
if startidx > size(snpdata,2) | ||
return nothing | ||
else | ||
SnpArrayIndex(startidx) | ||
return SnpArrayIterator(snpdata) | ||
end | ||
end | ||
|
||
function iterator(s::SnpData; startidx=1) | ||
iterator = SnpArrayIterator(s) | ||
end | ||
|
||
function chrom(s::SnpData, startidx=1)::String | ||
result = view(s.snp_info,startidx,1) | ||
return result | ||
end | ||
|
||
function pos(s::SnpData, startidx=1)::Int | ||
result = view(s.snp_info,startidx,2) | ||
return result | ||
end | ||
|
||
function rsid(s::SnpData, startidx=1)::String | ||
result = view(s.snp_info,startidx,3) | ||
return result | ||
end | ||
|
||
function alleles(s::SnpData, startidx=1)::Vector{String} | ||
allele1 = view(s.snp_info,startidx,5) | ||
allele2 = view(s.snp_info,startidx,6) | ||
return [allele1, allele2] | ||
end | ||
|
||
function alt_allele(s::SnpData, startidx=1)::String | ||
alt = view(s.snp_info,startidx,6) | ||
return alt | ||
end | ||
|
||
function ref_allele(s::SnpData, startidx=1)::String | ||
ref = view(s.snp_info,v,5) | ||
return ref | ||
end | ||
|
||
function mafCount(s::SnpData,startidx=1)::Int | ||
n00 = 0 | ||
n01 = 0 | ||
n11 = 0 | ||
for i in startidx:size(s,1) | ||
row = s[i,:] | ||
totalCount += 1 | ||
if row[5] == 0 && row[6] == 0 | ||
n00 += 1 | ||
else if row[5] == 0 && row[6] == 1 | ||
n01 += 1 | ||
else if row[5] == 1 && row[6] == 1 | ||
n11 += 1 | ||
end | ||
end | ||
|
||
return n00,n01,n11,totalCount | ||
end | ||
|
||
function maf(s::SnpData, startidx=1) | ||
results = mafCount(s) | ||
if results[1] <= results[2] && results[1] <= results[3] | ||
return float(results[1]) / float(results[4]) | ||
end | ||
if results[2] <= results[1] && results[2] <= results[1] | ||
return float(results[2]) / float(results[4]) | ||
end | ||
if results[3] <= results[1] && results[3] <= results[2] | ||
return float(results[3]) / float(results[4]) | ||
end | ||
end |
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
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.
change
itr.idx
to1