This repository was archived by the owner on Dec 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Clean R code #7
Open
mdavy86
wants to merge
7
commits into
MerrimanLab:master
Choose a base branch
from
mdavy86:cleanR
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.
Open
Clean R code #7
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,25 +1,32 @@ | ||
| #!/bin/env Rscript | ||
| # | ||
| # Murray Cadzow | ||
| # July 2013 | ||
| # University of Otago | ||
|
|
||
| args<-commandArgs(TRUE) | ||
| #read in haps file from shapeit | ||
| hapsPop=read.table(file=args[1]) | ||
| maf=as.numeric(args[2]) | ||
| output=as.character(args[3]) | ||
| args <- commandArgs(TRUE) | ||
|
|
||
| hapsPop=read.table(file=args[1]) | ||
| hapsPop=hapsPop[nchar(as.character(hapsPop[,4]))==1 & | ||
| as.character(hapsPop[,4]) != "-" & | ||
| nchar(as.character(hapsPop[,5]))==1 & | ||
| as.character(hapsPop[,5]) != "-", ] #remove indels | ||
| hapsPop[,1]= hapsPop[,2] | ||
| ## read in haps file from shapeit | ||
|
|
||
| hapsPop <- read.table(file = args[1]) | ||
| maf <- as.numeric(args[2]) | ||
| output <- as.character(args[3]) | ||
|
|
||
| af = apply(hapsPop[,6:length(hapsPop[1,])], 1, FUN=function(x){sum(x)/length(x)} ) | ||
| hapsPop=hapsPop[(af >= maf) & (af <= (1-maf)),] | ||
| print(paste("af >",maf)) | ||
| print(table((af > maf ) & (af < (1-maf)))) | ||
| hapsPop <- read.table(file=args[1]) | ||
| hapsPop <- hapsPop[nchar(as.character(hapsPop[,4]))==1 & | ||
| as.character(hapsPop[,4]) != "-" & | ||
| nchar(as.character(hapsPop[,5]))==1 & | ||
| as.character(hapsPop[,5]) != "-", ] # remove indels | ||
|
|
||
| write.table(hapsPop, file=output, quote=FALSE, row.names=FALSE, col.names=FALSE) | ||
| hapsPop[,1] <- hapsPop[,2] | ||
|
|
||
| ## This could be replaced with apply(..., FUN=mean), or rowMeans(x) | ||
| af <- apply(hapsPop[, 6:length(hapsPop[1, ])], 1, FUN = function(x) { | ||
| sum(x)/length(x) | ||
| }) | ||
|
|
||
| hapsPop <- hapsPop[(af >= maf) & (af <= (1 - maf)), ] | ||
| print(paste("af >", maf)) | ||
| print(table((af > maf) & (af < (1 - maf)))) | ||
|
|
||
| write.table(hapsPop, file = output, quote = FALSE, row.names = FALSE, col.names = FALSE) |
This file contains hidden or 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,40 +1,42 @@ | ||
| #!/bin/env Rscript | ||
|
|
||
| require(getopt) | ||
|
|
||
| spec = matrix(c( | ||
| 'help', 'h', 0, "logical", | ||
| 'plot_type','p', 1, "character", | ||
| 'data_file', 'd', 1, "character", | ||
| 'help', 'h', 0, "logical", | ||
| 'plot_type', 'p', 1, "character", | ||
| 'data_file', 'd', 1, "character", | ||
| 'plot_output_name', 'n', 1, 'character' | ||
| ), byrow=T, ncol=4) | ||
| ), byrow=T, ncol=4) | ||
|
|
||
| opt = getopt(spec) | ||
| opt <- getopt(spec) | ||
|
|
||
| if (!is.null(opt$help)){ | ||
| cat(getopt(spec,usage=TRUE)); | ||
| q(status=1); | ||
| if (!is.null(opt$help)) { | ||
| cat(getopt(spec, usage = TRUE)) | ||
| quit(status = 1) | ||
| } | ||
|
|
||
| if (opt$plot_type == "taj"){ | ||
| tajimaD=read.table(file=opt$data_file, header=TRUE) | ||
| png(opt$plot_output_name) | ||
| plot(tajimaD[,4] ~ tajimaD[,2],pch='.',cex=2,xlab="Chromosome position (bp)", ylab="D statistic") | ||
| dev.off() | ||
| }else if( opt$plot_type == "ihs"){ | ||
| ihs = read.table(file=opt$data_file) | ||
| png(opt$plot_output_name) | ||
| plot(ihs[,4] ~ ihs[,2],,pch='.',cex=2,ylab=expression("-" * log[10] * "[" ~ "1-2|" * Phi[scriptstyle(italic(iHS))] * "-0.5|" ~ "]"), | ||
| xlab="Chromosome Position BP") | ||
| dev.off() | ||
| }else if(opt$plot_type == "fay"){ | ||
| fay = read.table(file=opt$data_file,comment.char="#") | ||
| png(opt$plot_output_name) | ||
| plot(CEUFay[,15] ~ CEUFay[,1],xlab='Chromosome position (bp)',ylab="H Statistic")) | ||
| dev.off() | ||
| }else if(opt$plot_type == "rsb"){ | ||
|
|
||
| }else if(opt$plot_type == "fst_weir"){ | ||
|
|
||
| }else if(opt$plot_type == "fst_hap"){ | ||
|
|
||
| if (opt$plot_type == "taj") { | ||
| tajimaD <- read.table(file = opt$data_file, header = TRUE) | ||
| png(opt$plot_output_name) | ||
| plot(tajimaD[, 4] ~ tajimaD[, 2], pch = ".", cex = 2, xlab = "Chromosome position (bp)", ylab = "D statistic") | ||
| dev.off() | ||
| } else if (opt$plot_type == "ihs") { | ||
| ihs <- read.table(file = opt$data_file) | ||
| png(opt$plot_output_name) | ||
| plot(ihs[, 4] ~ ihs[, 2], , pch = ".", cex = 2, ylab = expression("-" * log[10] * "[" ~ "1-2|" * Phi[scriptstyle(italic(iHS))] * | ||
| "-0.5|" ~ "]"), xlab = "Chromosome Position BP") | ||
| dev.off() | ||
| } else if (opt$plot_type == "fay") { | ||
| fay <- read.table(file = opt$data_file, comment.char = "#") | ||
| png(opt$plot_output_name) | ||
| plot(CEUFay[, 15] ~ CEUFay[, 1], xlab = "Chromosome position (bp)", ylab = "H Statistic") | ||
| dev.off() | ||
| } else if (opt$plot_type == "rsb") { | ||
| } else if (opt$plot_type == "fst_weir") { | ||
| } else if (opt$plot_type == "fst_hap") { | ||
| } | ||
|
|
Oops, something went wrong.
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.
the tabulation in this line seems wrong, compared to the next 4 lines.