cut -d " " -f 1 sequences.fa | tr -s "\n" "\t"| sed -s 's/>/\n/g' > sequences.tabwhile read id start end; do \g=$(grep "$id" sequences.tab | cut -f 2 | cut -c $start-$end);\echo ">$id";\echo $g;\done
#!/usr/bin/perl -wuse Bio::DB::Fasta;#Usage: extract_substring.pl file.fasta coordinates.txt (where: id, start, stop) > out.fastamy $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 () { ($id,$start,$stop) = split "\t"; my $subseq = $db->subseq($id,$start,$stop); print ">", $id, "_", $start, "_", $stop; print $subseq, "\n"; }close IN1;