Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Z
Zalpha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computational Genetics
Zalpha
Commits
39c5499f
Commit
39c5499f
authored
Jul 10, 2020
by
Clare
Browse files
Options
Downloads
Patches
Plain Diff
Used the equal_vector function instead of directly comparing doubles
parent
ba23c578
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/create_LDprofile.R
+4
-4
4 additions, 4 deletions
R/create_LDprofile.R
with
4 additions
and
4 deletions
R/create_LDprofile.R
+
4
−
4
View file @
39c5499f
...
@@ -89,7 +89,7 @@ create_LDprofile<-function(dist,x,bin_size,max_dist=NULL,beta_params=FALSE){
...
@@ -89,7 +89,7 @@ create_LDprofile<-function(dist,x,bin_size,max_dist=NULL,beta_params=FALSE){
#Set max_dist to the maximum distance in the data if it was not supplied
#Set max_dist to the maximum distance in the data if it was not supplied
max_dist
<-
max
(
sapply
(
dist
,
function
(
x
){
x
[
length
(
x
)]
-
x
[
1
]}),
na.rm
=
TRUE
)
max_dist
<-
max
(
sapply
(
dist
,
function
(
x
){
x
[
length
(
x
)]
-
x
[
1
]}),
na.rm
=
TRUE
)
}
}
#Adjusts the
M
ax_dist value so it is equal to an increment of bin_size if it isn't already
#Adjusts the
m
ax_dist value so it is equal to an increment of bin_size if it isn't already
if
(
!
isTRUE
(
all.equal
(
max_dist
,
assign_bins
(
bin_size
,
max_dist
)))){
if
(
!
isTRUE
(
all.equal
(
max_dist
,
assign_bins
(
bin_size
,
max_dist
)))){
max_dist
<-
assign_bins
(
bin_size
,
max_dist
)
+
bin_size
max_dist
<-
assign_bins
(
bin_size
,
max_dist
)
+
bin_size
}
}
...
@@ -132,11 +132,11 @@ create_LDprofile<-function(dist,x,bin_size,max_dist=NULL,beta_params=FALSE){
...
@@ -132,11 +132,11 @@ create_LDprofile<-function(dist,x,bin_size,max_dist=NULL,beta_params=FALSE){
#Loop for each bin (i)
#Loop for each bin (i)
for
(
i
in
1
:
nrow
(
LDprofile
)){
for
(
i
in
1
:
nrow
(
LDprofile
)){
LDprofile
$
n
[
i
]
<-
sum
(
bins
==
LDprofile
$
bin
[
i
])
LDprofile
$
n
[
i
]
<-
sum
(
equal_vector
(
bins
,
LDprofile
$
bin
[
i
])
)
#If there is at least one pair whose genetic distance falls within the bin, calculate stats
#If there is at least one pair whose genetic distance falls within the bin, calculate stats
if
(
LDprofile
$
n
[
i
]
>
0
){
if
(
LDprofile
$
n
[
i
]
>
0
){
#Get the rsquared values for all pairs in this bin
#Get the rsquared values for all pairs in this bin
temprsq
<-
rsq
[
bins
==
LDprofile
$
bin
[
i
]]
temprsq
<-
rsq
[
equal_vector
(
bins
,
LDprofile
$
bin
[
i
]
)
]
#Calculate the mean
#Calculate the mean
LDprofile
$
rsq
[
i
]
<-
mean
(
temprsq
)
LDprofile
$
rsq
[
i
]
<-
mean
(
temprsq
)
#Calculate the standard deviation
#Calculate the standard deviation
...
@@ -145,7 +145,7 @@ create_LDprofile<-function(dist,x,bin_size,max_dist=NULL,beta_params=FALSE){
...
@@ -145,7 +145,7 @@ create_LDprofile<-function(dist,x,bin_size,max_dist=NULL,beta_params=FALSE){
#Calculate Beta distribution parameters if required
#Calculate Beta distribution parameters if required
#Do not calculate for bins containing less than two pairs or the standatd deviation is zero
#Do not calculate for bins containing less than two pairs or the standatd deviation is zero
if
(
beta_params
==
TRUE
&
LDprofile
$
n
[
i
]
>
1
&
LDprofile
$
sd
[
i
]
>
0
){
if
(
beta_params
==
TRUE
&
LDprofile
$
n
[
i
]
>
1
&
LDprofile
$
sd
[
i
]
>
0
){
if
(
sum
(
temprsq
==
1
|
temprsq
==
0
)
>
0
){
if
(
sum
(
equal_vector
(
temprsq
,
1
)
|
equal_vector
(
temprsq
,
0
)
)
>
0
){
#If there are any 0s or 1s adjust the data
#If there are any 0s or 1s adjust the data
temprsq
<-
(
temprsq
*
(
length
(
temprsq
)
-1
)
+0.5
)
/
length
(
temprsq
)
temprsq
<-
(
temprsq
*
(
length
(
temprsq
)
-1
)
+0.5
)
/
length
(
temprsq
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment