Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: how to merge the files of DNA sequences?

by graff (Chancellor)
on Jul 24, 2004 at 19:50 UTC ( [id://377159]=note: print w/replies, xml ) Need Help??


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

Are you confident that the two files have the same number of lines, the same number and set of individual names, and the same number of sequences per individual? And, are the individuals presented in the same order? That is, are the two files already aligned?

If there is a lack of alignment between the two, then some more specification is needed about what to do to reconcile differences between the two files.

But if the files are fully aligned, you could use a trivial perl script to join the two files line-by-line (or use the time-honored "paste" utility that has been in /usr/bin/ on unix systems since forever):

#!/usr/bin/perl open( F1, "file1" ) or die "file1: $!"; open( F2, "file2" ) or die "file2: $!"; while ( $s1 = <F1> ) { $s2 = <F2>; if ( $s1 =~ /^>/ ) { print $s1; } else { chomp $s1; print "$s1$s2"; # (update: added "$" on "s1") } }
or, using the "join" command and an even shorter perl script (which just removes duplicated individual names):
paste -d '' file1 file2 | perl -pe 's/(?<=\w)>.*//' > files.joined
(updates: mistakenly started with "join" command instead of "paste"; added the "-d ''" option on the paste command, to concatentate input strings with no separator. Regarding the (?<=\w)>.*, see the perlre man page about "zero-width look-behind assertion" -- this RE is checking for an angle bracket preceded by an alphanumeric, and replacing that angle bracket, and everything after it on the line, with an empty string. If a name ends in something other than a letter or digit, this will fail to remove the duplication.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-03-29 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found