The reverse complement of a DNA sequence signifies the contents of the opposite strand in a DNA molecule. DNA molecules are constructed as such because each nucleotide has a complementary nucleotide on the other strand to which a non-covalent bond exists.

Method 2
Method 2 of 2:
Programmatically (Python 2)

  1. 1
    Create or accept an input file. This article assumes that the input is in FASTA format, with a single sequence per file. The following steps also assume that all nucleotides are ATGC bases.
  2. 2
    Read in the file. For FASTA format:
    • Discard the first line of the file.
    • Remove all remaining newlines and other trailing whitespace.
    def init(sequence):
        with open(argv[1]) as input:
            sequence = "".join([line.strip() for line in input.readlines()[1:]])
        return sequence
    
  3. 3
    Create a hash table that maps each nucleotide to its complement.
    complement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A'}
    
  4. 4
    Iterate through the sequence and use a hash table lookup to construct the complementary sequence. Reverse the resulting vector.
    def reverse_complement(seq):
        bases = [complement[base] for base in seq]
        bases = reversed(bases)
        return bases
    
  5. 5
    Print the contents of the vector.=
    result = reverse_complement(seq)
    print ''.join(result)
    
    Advertisement

References

  1. StackOverflow: Reverse complement of DNA strand using Python - Source of original programmatic solution that handles non-ATGC base pairs. Solution by Gabriel. Licensed under a CC-By-SA 3.0 license.

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, volunteer authors worked to edit and improve it over time. This article has been viewed 12,485 times.
8 votes - 75%
Co-authors: 3
Updated: May 6, 2021
Views: 12,485
Categories: Genetics
Advertisement