forked from CNuge/snp-placer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
samParse.R
66 lines (55 loc) · 1.61 KB
/
samParse.R
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
snp_contig_location <- function(flag, pos, adjusted_bp_location, alignment_length){
if (is.numeric(adjusted_bp_location)){
} else {
return("-")
}
if (flag == 0 || flag == 256){
return((pos + adjusted_bp_location - 1))
} else if (flag == 16 || flag == 272){
return((pos + alignment_length - adjusted_bp_location))
} else {
return("-")
}
}
compliment_name <- function(name, flag){
#if the alignment is a reverse, add _comp to the end of its identification
if (flag == 16 || flag == 272){
return(paste0(name,"_comp"))
} else {
return(name)
}
}
match_snp <- function(allele){
allele <- toupper(allele)
if (allele == "A"){
return("T")
} else if (allele == "T"){
return("A")
} else if (allele == "C"){
return("G")
} else if (allele == "G"){
return("C")
} else if (allele == "N"){
return("N")
} else {
return(paste0("Need valid nucleotide (ATGC) or N\n, not valid = ",allele))
}
}
allele_comp_check <- function(in_allele, flag){
# if alignment is a reverse, flip the alleles to the complimentary nucleotides """
if (flag == 0 || flag == 256){
return(in_allele)
} else if (flag == 16 || flag == 272){
in_allele <- unlist(strsplit(in_allele,",",fixed=TRUE),use.names=FALSE)
if (length(in_allele) == 1){
return(match_snp(in_allele))
} else {
out_alleles <- NULL
for (i in 1:length(in_allele)){
out_alleles[i] <- (match_snp(in_allele[i]))
}
out_alleles <- paste(out_alleles,collapse=",")
return(out_alleles)
}
}
}