Help: Count characters

A

Amy Lee

Hello,

I make a small perl script to count how many sequences in a fasta
formation file. In fasta formation file every sequence starts with a ">",
so I can count how many ">" in a file.

There's my code:

if (@ARGV != 0)
{
foreach $file (@ARGV)
{
unless (-e $file)
{
print "***Error: $file dose not exist.\n";
next;
}
unless (open $FILE_IN, '<', $file)
{
print "***Error: Cannot read $file.\n";
next;
}
$full_size = (stat($file))[7];
while (<$FILE_IN>)
{
s/>//g;
}
$mod_size = (stat($FILE_IN))[7];
$num = $full_size-$mod_size;
close $FILE_IN;
print "$file ==> $num seq.\n"
}
}

However, when I run this script, it always shows "0 seqs". I don't know
what happened. And is there any better way to count ">"?

Thank you very much~

Regards,

Amy Lee
 
R

Ron Bergin

Hello,

I make a small perl script to count how many sequences in a fasta
formation file. In fasta formation file every sequence starts with a ">",
so I can count how many ">" in a file.

There's my code:

if (@ARGV != 0)
{
foreach $file (@ARGV)
{
unless (-e $file)
{
print "***Error: $file dose not exist.\n";
next;
}
unless (open $FILE_IN, '<', $file)
{
print "***Error: Cannot read $file.\n";
next;
}
$full_size = (stat($file))[7];
while (<$FILE_IN>)
{
s/>//g;
}
You're not maintaining a count of the number of substitutions.
$mod_size = (stat($FILE_IN))[7];
$num = $full_size-$mod_size;
close $FILE_IN;
print "$file ==> $num seq.\n"
}
Since the file was opened in read only mode, its size will not have
been changed.
}

However, when I run this script, it always shows "0 seqs". I don't know
what happened. And is there any better way to count ">"?
perldoc -q "how do I count the number of lines in a file"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top