Created
October 23, 2015 15:06
-
-
Save explodecomputer/28057532370c80807d06 to your computer and use it in GitHub Desktop.
profile scores
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
# Suppose you have some files that look like this: | |
# bmi_chr01.profile | |
# bmi_chr02.profile | |
# bmi_chr03.profile | |
# etc | |
# Read in each profile score | |
l <- list() | |
j <- 1 | |
for(i in 1:22) | |
{ | |
# Add leading zeros to i | |
ii <- sprintf("%02d", i) | |
profile_file <- paste0("bmi_chr", ii, ".profile") | |
if(file.exists(profile_file)) | |
{ | |
message("reading ", profile_file) | |
l[[j]] <- read.table(profile_file, header=TRUE) | |
j <- j + 1 | |
} | |
} | |
# Now we have a list with 22 different data frames | |
# Need to extract the "SCORESUM" columns from each data frame | |
scores_chr <- sapply(l, function(x) { | |
a <- x$SCORESUM | |
}) | |
# Now we have a matrix of the scores for each chromosome | |
# To get a single score we just sum each row | |
scores <- rowSums(scores_chr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment