bisimen has asked for the wisdom of the Perl Monks concerning the following question:
I can't figure out how to apply this subroutine (pretty_print) to my data:
#!/usr/bin/perl use warnings; #use strict; ($sfile_1, $sfile_2) = @ARGV; ($id1, $seq1) = read_fasta($sfile_1); ($id2, $seq2) = read_fasta($sfile_2); pretty_print(\$id1, \$seq1); pretty_print(\$id2, \$seq2); sub read_fasta { ## reads a single sequence from a fasta file my $seqFile = shift @_; my $seq = ""; my $id = ""; open(my $in, "<", $seqFile) or die "unable to open $seqFile $!\n"; while(<$in>){ chomp; if($_ =~ /^>(\S+)/ ){ last if(length($id)); $id = $1; next; } if(length($id)){ $seq .= $_; } } return ($id, $seq); } sub pretty_print { my($seq, $colno) = shift @_; # We want to start from 0, and increment the starting position. # for this we use a classical loop. for (my $b=0; $b < length($seq); $b += $colno){ print( substr($seq, $b, $colno), "\n"); } } exit;
The two data files if needed: https://justpaste.it/1ch48 and https://justpaste.it/1ch4b
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to use this subroutine
by LanX (Saint) on Oct 16, 2017 at 14:55 UTC | |
by bisimen (Acolyte) on Oct 16, 2017 at 15:48 UTC | |
|
Re: How to use this subroutine
by hippo (Archbishop) on Oct 16, 2017 at 14:52 UTC | |
by bisimen (Acolyte) on Oct 16, 2017 at 15:46 UTC | |
|
Re: How to use this subroutine
by wjw (Priest) on Oct 16, 2017 at 15:55 UTC | |
|
Re: How to use this subroutine
by Anonymous Monk on Oct 16, 2017 at 14:50 UTC | |
by bisimen (Acolyte) on Oct 16, 2017 at 15:40 UTC |