Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: A better (problem-specific) perl hash?

by l3v3l (Monk)
on Feb 17, 2006 at 19:42 UTC ( #531051=note: print w/replies, xml ) Need Help??

in reply to A better (problem-specific) perl hash?

In the vein of perl liners and cmd line tools that do "simple" tasks and work with other liners to do more interesting tasks, I had put the following together to do just this sort of thing but have not run on really big files and I am sure this can be improved but it works great for fasta input files ~300K or so ...
perl -nle 'chomp;tr/a-z/A-Z/;next if /[^ATCG]/;$l=length();$c=0;for $m +(5..$l){print substr($_,$c++,5)}' uniBNL_SSR_fasta.txt.input_library. +txt | perl -nle '$c{$_}++ for split/\W/;}print map {"$_:$c{$_}\n"} so +rt{$c{$b}<=>$c{$a}}keys %c;{' -
output example:
... AGAGA:5334 GAGAG:5124 TCTCT:1938 AAAAA:1908 ACACA:1884 TTTTT:1851 CTCTC:1798 ...
more details - for genome type data sets I split the bases up into N files and run individual jobs on N nodes of a cluster - if anyone is interested - here is what I use to split the large files into N files (thanks thor - custom version of what we discussed):
#!/usr/bin/perl # # simple fasta input file cleaver # usage: --format OUTPUT_FILE_PREFIX --number X input_file # where X is the number of files to split input_file into # # note: you can optionally pass more than one input file # to (re)combine into X files use strict; use warnings; use Getopt::Long; my ($number,$format)=(2,"output"); GetOptions( "number=i" => \$number, "format=s" => \$format, ); my @output_file; foreach my $num(1..$number) { my $file ="$format.$num"; open($output_file[$num-1],">",$file) or die; } my $file_num = 0; while(<>) { $/='>'; chomp; my $pre = ($. != 2 ? ">" : ""); print {$output_file[$file_num]} "$pre$_"; next if $. == 1; $file_num +=1; $file_num %= $number; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2022-05-20 16:52 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (75 votes). Check out past polls.