1 | find.maf.block(snp.data, maf.threshold, snp.number, out.file.name)
|
snp.data |
|
maf.threshold |
|
snp.number |
|
out.file.name |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (snp.data, maf.threshold, snp.number, out.file.name)
{
if (missing(snp.data)) {
stop("An data.frame object containing SNP data must be provided!")
}
else {
column_count = ncol(snp.data)
if (column_count != 7) {
stop("Input data must be in the required format. See the example input file!")
}
}
if (missing(maf.threshold)) {
maf.threshold <- 0.05
}
if (missing(snp.number)) {
snp.number <- 5
}
if (missing(out.file.name)) {
out.file.name = "MafSelSweep.out"
}
chroms <- snp.data[, 1]
chroms <- chroms[!duplicated(chroms)]
for (chr in chroms) {
tyu <- subset(snp.data, snp.data[, 1] == chr)
row.num <- length(tyu[, 1])
tyu$flag <- tyu[, 5] <= maf.threshold
tyu$flag[is.na(tyu$flag)] <- FALSE
tyu$chromosome <- NA
tyu$start <- NA
tyu$end <- NA
tyu$blocksize <- NA
tyu$snpnumber <- NA
count1 = 1
tyu
while (count1 <= row.num) {
if (tyu$flag[count1]) {
sum = 1
count2 = count1 + 1
condition1 = 1
while (condition1) {
if (tyu$flag[count2]) {
sum = sum + 1
count2 = count2 + 1
}
else {
condition1 = 0
chr.name = paste("chr", chr, sep = "")
start = tyu[count1, 7]
end = tyu[count2 - 1, 7]
blocksize = end - start + 1
for (index in count1:(count2 - 1)) {
if (sum >= snp.number) {
tyu$chromosome[index] = chr.name
tyu$start[index] = start
tyu$end[index] = end
tyu$blocksize[index] = blocksize
tyu$snpnumber[index] = sum
}
}
}
}
count1 = count2
}
else {
count1 = count1 + 1
}
}
snp.data$Chromosome[snp.data[, 1] == chr] <- tyu$chromosome
snp.data$Start[snp.data[, 1] == chr] <- tyu$start
snp.data$End[snp.data[, 1] == chr] <- tyu$end
snp.data$Block_size[snp.data[, 1] == chr] <- tyu$blocksize
snp.data$SNP_number[snp.data[, 1] == chr] <- tyu$snpnumber
}
write.table(snp.data, file = out.file.name, sep = "\t", row.names = F,
quote = F)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.