- 论坛徽章:
- 0
|
这个样子还是比较容易看懂
假设文件叫data- #!/usr/bin/perl
- use warnings;
- use strict;
- use Data::Dumper;
- $/ = ">";
- my %hash;
- open IN, "<", "data" or die "Can't open data:$!\n";
- <IN>;
- while (<IN>) {
- chomp;
- my @tmp = split /\n/;
- my $comp = (split /_/,$tmp[0])[0];
- if (!exists $hash{$comp}) {
- $hash{$comp}{ID} = $tmp[0];
- $hash{$comp}{seq} = $tmp[1];
- } elsif (length $tmp[1] > length ($hash{$comp}{seq})) {
- $hash{$comp}{ID} = $tmp[0];
- $hash{$comp}{seq} = $tmp[1];
- }
- }
- close IN;
- print ">$hash{$_}{ID}\n$hash{$_}{seq}\n" for keys %hash;
复制代码 ./data.pl
>comp2_c0_seq1 len=468 path=[1:0-467]
ATTAAGAGTTTGGAAGATTAGGTAGCCATTGACAGTTTTACACTGTTTAGAGAAAGACTTATCTTAATTTTGTTTTGGGTTTATTTGGAAATTCAAACTGTATCAAATAAGGGA
>comp3_c1_seq1 len=721 path=[717:0-720]
GTGAAGAAACTGTGTTTGGCACCTGTGTCGGCCGCAAAGCACCAATCGTGGAGAGAAGCCACAA
>comp0_c0_seq1 len=245 path=[391:0-244]
ATCATTGGAGGCATATTGAAATCTTAGTAGCAGGTATTATTAGAACTTGAGAGAA
>comp1_c1_seq1 len=264 path=[1132:0-263]
GGGTATGAGGATATGGATTTTATTTCATGTATGATTTTAGTCAAATACAAGTATTGTATTAAAAAAAAAAAGTGAGGTG
|
|