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
In reply to How to use this subroutine by bisimen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |