Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^19: how to read input from a file, one section at a time?

by davi54 (Sexton)
on Apr 03, 2019 at 16:49 UTC ( [id://1232102]=note: print w/replies, xml ) Need Help??


in reply to Re^18: how to read input from a file, one section at a time?
in thread how to read input from a file, one section at a time?

Hi, can someone tell me what's the mistake I'm doing in the following code? To be precise, in line- 'printf "%d duplicate records written\n",$name,$para,$out_filename;'?
I get an error:
Argument "sdAb_1193_LgLlama" isn't numeric in printf at ../duplicate.p +l line 35, <$PROTFILE> chunk 165. 'Redundant argument in printf at ../duplicate.pl line 35, <$PROTFILE> +chunk 1164.'
#!/usr/bin/perl # cleanup.pl use strict; use warnings; print 'Enter protein sequence filename: '; chomp( my $prot_filename = <STDIN> ); open my $PROTFILE, '<', $prot_filename or die "Cannot open '$prot_filename' because: $!"; my $out_filename = 'duplicates_entries_in_'.$prot_filename; open my $OUTFILE, '>', $out_filename or die "Cannot open '$out_filename' because: $!"; $/ = ''; # Set paragraph mode my $name; my %fasta_seen; FASTA_RECORD: while ( my $para = <$PROTFILE> ) { # Remove fasta header line if ( $para =~ s/^>(.*)//m ){ $name = $1; }; # Remove comment line(s) $para =~ s/^\s*#.*//mg; # Trim trailing white space $para =~ s/\s+$//; # next FASTA_RECORD if $fasta_seen{ $para }++; if ( $fasta_seen{ $para }++ ){ printf "%d duplicate records written\n",$name,$para,$out_filename; next FASTA_RECORD; } } print "\n";

2019-04-07 Athanasius added code tags and removed break tags within code

Replies are listed 'Best First'.
Re^20: how to read input from a file, one section at a time?
by poj (Abbot) on Apr 03, 2019 at 17:08 UTC
    printf "%d duplicate records written\n",$name,$para,$out_filename;

    see printf and sprintf. You need to put %s in the print format for strings, %d for integers

    while ( my $para = <$PROTFILE> ) { # Remove fasta header line if ( $para =~ s/^>(.*)//m ){ $name = $1; }; # Remove comment line(s) $para =~ s/^\s*#.*//mg; # Trim trailing white space $para =~ s/\s+$//; # next FASTA_RECORD if $fasta_seen{ $para }++; if ( $fasta_seen{ $para }++ ){ printf "duplicate record %s %s \nwritten to %s\n",$name,$para,$out +_filename; print $OUTFILE '>'.$name.$para."\n\n"; } }
    poj
      Ohh.. okay.. still learning.. Thanks.. :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-29 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found