- 论坛徽章:
- 8
|
回复 6# yang7473453
你的意思是:- #!/usr/bin/perl -w
- my $txt = '24.txt';
- my ( $key, %seqId );
- open TXT, $txt or die $!;
- open OUT, '>', 'Sequence_extraction_part.fa' or die "don't worry";
- while (<TXT>) {
- my ( $file, $s, $e) = ( split /\s+/, $_)[ 0, 1, 2 ];
- my $l = $e - $s + 1;
- my $chr = ( split /_/, $file)[1];
- extract( $file, $chr, $s, $l, $_ );
- }
- sub extract {
- my ( $fin, $SequenceId, $start, $len, $m ) = @_;
- open( SCA, $fin ) or die $!;
- while (<SCA>) {
- chomp;
- /^>/ ? ( ($key) = /^>(\w+)/ ) : $seqId{$key} .= $_;
- }
- close SCA;
- unless ( exists $seqId{$SequenceId} ) {
- print "$SequenceId\t$start\t$start+$len\terro\n";
- return;
- }
- my $Seq = substr $seqId{$SequenceId}, $start - 1, $len;
- my @OUT;
- my $lenseq = length($Seq);
- for ( my $j = 0 ; $j * 60 < $lenseq ; $j++ ) {
- push @OUT, substr( $Seq, $j * 60, 60 ), "\n";
- }
- print OUT ">$m", @OUT;
- }
- close OUT;
复制代码 这样吗? |
|