Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: mapping data between files

by citromatik (Curate)
on May 06, 2009 at 08:04 UTC ( #762185=note: print w/ replies, xml ) Need Help??


in reply to mapping data between files

If I understood correctly, you want something like:

  • Read and parse the sequences file
  • For each sequence, open a file that is named after the sequence header
  • From that file, get the first number of each line
  • Associate each letter in the sequence with those numbers
use strict; use warnings; my ($seqfile) = @ARGV; #seqfile is the file with the sequences. open my $seqfh, "<", $seqfile or die $!; { local $/ = "\n>"; while (my $nextseq = <$seqfh>){ chop $nextseq unless eof $seqfh; substr ($nextseq,0,1,"") if $. == 1; my ($name,@seq) = split /\n/,$nextseq; my @aas = split //,join "",@seq; my @coords = getCoords ($name); print "$aas[$_] $coords[$_]\n" for(0..$#aas); } } sub getCoords { my ($fname) = @_; local $/="\n"; my @ns; open my $fh, "<", $fname or die $!; while (my $line = <$fh>){ chomp $line; my @ff = split /\s+/,$line; push @ns, (split /\s+/,$line)[0]; } close $fh; return @ns; }

citromatik


Comment on Re: mapping data between files
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (17)
As of 2015-07-06 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls