Created
March 17, 2015 17:16
-
-
Save sephraim/ae82ec1aeaec11dd6a91 to your computer and use it in GitHub Desktop.
Swap nucleotide sequence to opposite chromosome strand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Swaps the nucleotide sequence to the opposite strand | |
# | |
# This means if the sequence is on the forward strand, | |
# then the function will return the corresponding sequence | |
# on the reverse strand, and vice versa. | |
# | |
# For example: | |
# Original: TCCAGACAC | |
# Swapped: GTGTCTGGA | |
# | |
# @param seq [String] Original nucleotide sequence | |
# @return [String] Nucleotide sequence on opposite strand | |
def swap_strand(seq) | |
seq = seq.reverse.upcase.split("") | |
seq.each_with_index do |base, i| | |
seq[i] = 'A' if base == 'T' | |
seq[i] = 'T' if base == 'A' | |
seq[i] = 'G' if base == 'C' | |
seq[i] = 'C' if base == 'G' | |
end | |
return seq.join("") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment