|||
将下列代码存入文件get_position_seq.pl,然后可以使用perl get_position_seq.pl -h获得帮助!
#! /usr/bin/perl
use Bio::SeqIO;
use Getopt::Long;
GetOptions(
'Position|P=s' => $inputfile1,
'Seq|s=s' => \$inputfile2,
'O=s' => \$inputfile3,
'help|h!' => \$help,
);
my @good;
my $h=0;$k=0;
if($help){
print "###################################################################\n";
print "usage perl get_position_seq.pl -p position.file -s seq.file -o getseq.file\n";
print "######input position file is the format:\n" ;
print "######gene_ID start(0 as start) get_length\n";
print "Options:\n";
print " -p:the input position file\n";
print " -s:the fasta sequence file\n";
print " -o:the output sequence file\n";
}else{
open (IN1, "<$inputfile1")|| die "cannot open $inputfile:$!";
open (OUT, ">$inputfile3")|| die "cannot open $inputfile:$!";
while (<IN1>){
@tmp=split;
push @position, [@tmp];
}
my $ina = Bio::SeqIO->new(-file => $inputfile2, -format => 'fasta');
while(my $obj = $ina->next_seq()){
my $id = $obj->id;
my $seq = $obj->seq;
$xulie[$k++]="$id $seq\n";
}
foreach(@xulie){
@tmp=split;
push @Mat, [@tmp];
}
for($i=0;$i<=($#position);$i++){
for($j=0;$j<=($#Mat);$j++){
if($position[$i][0] eq $Mat[$j][0]){
$good[$h][0]=">$position[$i][0]";
$good[$h][1]=substr($Mat[$j][1],$position[$i][1],$position[$i][2]);
print OUT "$good[$h][0]\n$good[$h][1]\n";
$h++;
last;
}
}
}
close IN1;
close OUT;
}
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-17 12:56
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社