反向互补序列

#!/usr/bin/perl -w

use strict;
use Getopt::Long;
use Bio::SeqIO;

my %opts;

GetOptions(\%opts, "i=s", "o=s");

if (!(defined $opts{i} && defined $opts{o})){
        print "\n";
        &usage;
}

my $input_file = $opts{'i'};
my $output_file = $opts{'o'};

my $seq_input = Bio::SeqIO->new(-format => 'fasta',
                                -file => $input_file);

unless ( open(RESULT, ">$output_file") ) {
        print "Cannot open \"$output_file\" to write to!!\n\n";
exit;
}

my ($seq_obj, $display_name, $seq_str, $revcom_seq);

while ($seq_obj = $seq_input->next_seq) {
       $display_name = $seq_obj->display_id;        
       $seq_str = $seq_obj->seq;
       $seq_str =~ tr/ATGCatgc/TACGtacg/;
       $revcom_seq = reverse $seq_str;
        print RESULT ">$display_name" . "\n" . "$revcom_seq" . "\n";
}

close(RESULT);

sub usage {
        print <<"USAGE";
Usage:
        $0 -i <input_file> -o <output_file>
options:
        -i input fasta sequence file name
        -o output file name
USAGE
        print "\n";
        exit(1);
}
posted @ 2015-12-10 15:21  liuhui_pine  阅读(1645)  评论(0)    收藏  举报