-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPercent_Ns.R
More file actions
30 lines (24 loc) · 817 Bytes
/
Percent_Ns.R
File metadata and controls
30 lines (24 loc) · 817 Bytes
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
library(Biostrings)
Percent_Ns = function(filename, output.as.df = F){
x = readDNAStringSet(filename)
if(output.as.df == F){
for(i in 1:length(x)){
x[i] = gsub("-","",x[i])
freqs = alphabetFrequency(x[i], baseOnly = F, as.prob = F)
N_percent = (sum(freqs[colnames(freqs) %in% c("n", "N")])/sum(freqs)) * 100
message("\n", names(x[i]), " contains ", N_percent,"% Ns.")
}
message("\nEnd of warnings.")
}
if(output.as.df == T){
ID = names(x)
N_percent = rep(NA, length(x))
for(i in 1:length(x)){
x[i] = gsub("-","",x[i])
freqs = alphabetFrequency(x[i], baseOnly = F, as.prob = F)
N_percent[i] = (sum(freqs[colnames(freqs) %in% c("n", "N")])/sum(freqs)) * 100
}
df = as.data.frame(cbind(ID,N_percent))
return(df)
}
}