Perl code for counting number of bases
1
0
Entering edit mode
7.0 years ago
Arindam Ghosh ▴ 530

I need help regarding a perl code that was used to count the numbr of bases. I am aware of the function of cat and grep commands here. But the perl portion of the code is a bit puzzling.

> cat chr22_with_ERCC92.fa | grep -v ">" | perl -ne 'chomp $_; $bases{$_}++ for split //; if (eof){print "$_ $bases{$_}\n" for sort keys %bases}'
perl coding • 1.7k views
ADD COMMENT
1
Entering edit mode
7.0 years ago
Joseph Hughes ★ 3.0k

chomp removes the end of line character

split // splits the string into characters that are added to the hash with $bases{$_}++ whilst incrementing with ++. The for is for looping through the array which is produced by split //

Then if you reach the end of the file eof you sort the hash and print the character $_ followed by its value/count $bases{$_}

ADD COMMENT
0
Entering edit mode

And what about the

for

statement. Is it used for for looping? Usually the syntax is

for( ; ; );

Is this an alternate way of using it?

ADD REPLY

Login before adding your answer.

Traffic: 2484 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6