- 论坛徽章:
- 6
|
本帖最后由 stanley_tam 于 2014-04-02 09:34 编辑
这回详细多了,下面是脚本代码,假设文件24.txt和你的序列文件在一个folder下面。
建议跑之前先进行备份,这个会改变原有的文件。。。- #!perl
- use Modern::Perl;
- use autodie;
- use Tie::File;
- # file store data to be extracted
- my $data_reference = '24.txt';
- my $fh;open $fh, '<', $data_reference;
- while (defined(my $line = readline $fh)) {
- # remove trailing newline
- chomp $line;
- # remove heading and trailing spaces
- $line =~ s{^\s+ | \s+$}{}mgx;
- # split the line by spaces
- my ($file_name, $start_pos, $end_pos) = split /\s+/, $line;
- my @seq_lines = ();
- # map file to array
- tie @seq_lines, 'Tie::File', $file_name or
- die "Fail to tie file $file_name: !\n";
- for my $seq_line (@seq_lines){
- # skip line begin with >, no clue what it is about ...
- next if $seq_line =~ m{^>}m;
- # skip blank line
- next if $seq_line =~ m{^ \s* $}mx;
- # here comes the long sequence line
- my @pieces = split //, $seq_line;
- # get the pieces we want, convet position to index
- # this is in place change
- $seq_line = join '', @pieces[$start_pos-1 .. $end_pos-1];
- }
- # commit changes
- untie @seq_lines;
- }
- close $fh;
- say "Done ! Press <ENTER> to exit.";
- <STDIN>;
- __END__
复制代码 回复 6# yang7473453
|
|