# Version 6 # gcContent: Calculates GC content. It is also possible to calculate the AT # content (AT = TRUE), the function takes into account lower and upper case # letters (thanks to Ingo Müller for this improvement) # Author: Sonja Grath # Last update: 2019-03-14 # Input: DNA sequence # Output: GC (AT) content of the DNA sequence gcContent <- function(dna, counter = 0, AT = FALSE){ if (!is.character(dna)){ stop("The argument must be of type character.") } # Transforms DNA sequence to upper case letters dna <- toupper(dna) if (length(grep("[^ACGT]", dna)) > 0){ warning("The input contains characters other than A, C, G or T - value should not be trusted!") } dna <- unlist(strsplit(dna, "")) for(i in 1:length(dna)){ if(dna[i] == "C" | dna[i] == "G") {counter = counter + 1} } if (AT == TRUE){ return(1 - counter/length(dna)) } else { return(counter/length(dna)) } }