perform the following using Ruby language
A DNA strand is represented by a string of the characters A, C, G, and T, each of which represents a nucleotide. Each nucleotide has its complement as indicated by this Ruby hash:
NUCLEOTIDE_COMPLEMENT = { 'A' => 'T', 'T' => 'A', 'C' => 'G', 'G' => 'C'
}
The reverse-complement of a DNA string is a new string in which each nucleotide is replaced by its complement and the string is reversed. Reverse-complements are important in bioinformatics since a strand of DNA can be read in forward direction or, equivalently, its complementary strand can be read in its forward direction, which is reverse of the original string’s direction. Add the reverse_complement method to your DNA class. In response to reverse_complement, it returns a new DNA instance representing its reverse-complement. Note also that a == b if and only if DNA instances a and b represent the same DNA strand.
Output:
puts dna1 = DNA.new('ATTGCC')
#ATTGCC
puts dna2 = dna1.reverse_complement
#GGCAAT
puts dna2
#GGCAAT
puts dna1
#ATTGCC
puts dna2.reverse_complement
#ATTGCC
puts dna1.reverse_complement.reverse_complement == dna1
#true
Please UPVOTE my answer if you find this explaination to be helpful !!
CODE:
#!/usr/bin/ruby
class DNA_strand
def initialize(seq)
@sequence = seq
end
def reverse_complement
rC = ''
@sequence.split('').each do |i|
if i == 'A'
rC += 'T'
else if i == 'C'
rC += 'G'
else if i == 'G'
rC += 'C'
else
rC += 'A'
end
end
return rC
end
end
Please UPVOTE my answer if you find this explaination to be helpful !!
Get Answers For Free
Most questions answered within 1 hours.