How to reverse complement the DNA sequences for given inverse/reverse coordinates? I have the series of coordinates in id.txt file, whose coordinates sequences are in genome.fasta file.
The coordinates of id.txt file is shown below,

Contig3:15-7
Contig2:5-10
Contig1:12-3


The genome.fasta file is shown below,

&gt;Contig1
AAGGCCATCAAGGACGTGGATGAGGTCGTCAAG
&gt;Contig2
ACGAAGCGCTCGCCAAGGCCGAAGAAGAAGGCC 
&gt;Contig3
GCTGCGGCGCTGATCCTGGCGGCCCGCGCCGAG


I have used the following codes to extract the sequences from genome.fasta based on the coordinates in id.txt by using the following command xargs samtools faidx genome.fasta &lt;id.txt &gt; result.fasta
It has extracted only Contig2:5-10sequence. Because, the coordinates of Contig2:5-10is in proper order. But Contig3:15-7 and Contig1:12-3 coordinates are in inverse/reverse order, So samtools could not fetch those sequences.

I need to extract those sequences from Contig1:12-3 and Contig3:15-7 coordinates and also I want to reverse complement them. I have  larger fasta file and plenty of coordinates sequences to be extracted, So I need to automate this process. So, please help me to automate this process.

The expected output is

&gt;Contig3    
GATCAGCGC
&gt;Contig2
AGCGCT
&gt;Contig1
CTTGATGGCC


Thank you in advance.
Since you tagged python, here is a solution that solves this in a single script using Biopython:

import sys
from Bio import SeqIO

d = {}
with open('id.txt') as f:
    for line in f:
        contig, coords = line.split(':')
        start, end = map(int, coords.split('-'))
        d[contig] = start, end

for record in SeqIO.parse('genome.fasta', 'fasta'):
    start, end = d[record.id]
    if start &gt; end:
        record.seq = record.seq[end - 1: start].reverse_complement()
    else:
        record.seq = record.seq[start - 1: end]
    SeqIO.write(record, sys.stdout, 'fasta')


Output on your example:

&gt;Contig1
CTTGATGGCC
&gt;Contig2
AGCGCT
&gt;Contig3
GATCAGCGC