Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Created October 23, 2015 15:06
Show Gist options
  • Save explodecomputer/28057532370c80807d06 to your computer and use it in GitHub Desktop.
Save explodecomputer/28057532370c80807d06 to your computer and use it in GitHub Desktop.
profile scores
# 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