#!/usr/bin/perl
use strict;
use warnings;
use Bio::SeqIO;
use Bio::Tools::Run::RepeatMasker;
my $genome_file = "genome.fasta";
# read genome sequence
my $seqio = Bio::SeqIO->new(-file => $genome_file, -format => "fasta");
my $seqobj = $seqio->next_seq();
my $seq = $seqobj->seq();
# run RepeatMasker
my $rm = Bio::Tools::Run::RepeatMasker->new();
my $rm_report = $rm->run($genome_file);
# parse RepeatMasker output
while (my $rm_result = $rm_report->next_result()) {
my $rm_match = $rm_result->repeat_consensus();
my $rm_class = $rm_result->repeat_class();
my $rm_start = $rm_result->start();
my $rm_end = $rm_result->end();
my $rm_strand = $rm_result->strand();
if ($rm_class eq "Inverted") {
my $rm_seq = substr($seq, $rm_start-1, $rm_end-$rm_start+1);
if ($rm_strand eq "-") {
$rm_seq = reverse_complement($rm_seq);
}
print "Inverted repeat found at positions $rm_start-$rm_end: $rm_seq\n";
}
}
sub reverse_complement {
my ($seq) = @_;
$seq = reverse($seq);
$seq =~ tr/ACGTacgt/TGCAtgca/;
return $seq;
}