Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: how to merge the files of DNA sequences?

by wfsp (Abbot)
on Jul 24, 2004 at 08:58 UTC ( #377110=note: print w/replies, xml ) Need Help??

in reply to how to merge the files of DNA sequences?

This is what I came up with:
#!/bin/perl5 use strict; use warnings; @ARGV = qw( file1.txt file2.txt ); my $name; my %hash; while (<>){ chomp; my $record = $_; if ( $record =~ /^>/ ){ $name = $record; next; } else{ $hash{$name} .= $record } } for my $key ( keys %hash ){ print "$key\n$hash{$key}\n" }
Updated: Use hash instead of a hashref

Replies are listed 'Best First'.
little golf
by ccn (Vicar) on Jul 24, 2004 at 10:34 UTC

    perl -lne '/^>(.*)/ or$H{$1}.=$_;END{print for map{">$_\n$H{$_}"}keys%H}' file1.txt file2.txt

      Ok, ok I'm impressed! I'm still at the 'baby idiom' stage.

      ...and anyway, I like typing!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://377110]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2023-02-05 23:23 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (33 votes). Check out past polls.