cut -d " " -f 1 sequences.fa | tr -s "\n" "\t"| sed -s 's/>/\n/g' > sequences.tab
while read id start end; do \
g=$(grep "$id" sequences.tab | cut -f 2 | cut -c $start-$end);\
echo ">$id";\
echo $g;\
done<coordinates.txt
#!/usr/bin/perl -w
use Bio::DB::Fasta;
#Usage: extract_substring.pl file.fasta coordinates.txt (where: id, start, stop) > out.fasta
my $fasta = $ARGV[0];
my $query = $ARGV[1];
my ($id,$start,$stop);
my $db = Bio::DB::Fasta -> new($fasta); # Create database from a directory of Fasta files
# my $db = Bio::DB::Fasta->new('/path/to/fasta/files/');
open (IN1, $query);
while (<IN1>) {
($id,$start,$stop) = split "\t";
my $subseq = $db->subseq($id,$start,$stop);
print ">", $id, "_", $start, "_", $stop;
print $subseq, "\n";
}
close IN1;