http://www.perlmonks.org?node_id=1045408


in reply to Iso electric point calculation using perl

Looking at the original code from that page, I conclude that it is the body of a subroutine, and not a standalone program.

So, wrap it in a subroutine (say, calculate_protein_details and call that subroutine with 2 arguments: a protein sequence $protein (the input), and an empty hash %results (the output, which whill be filled in by the subroutine).

#!/usr/bin/perl use strict; use warnings; main(); exit; sub main { # I took this example sequence from uniprot.org # from entry >sp|P02754|LACB_BOVIN Beta-lactoglobulin my $protein = "MKCLLLALALTCGAQALIVTQTMKGLDIQKVAGTWYSLAMAASDISLLDAQSA +PLRVYVEELKPTPEGDLEILLQKWENGECAQKKIIAEKTKIPAVFKIDALNENKVLVLDTDYKKYLLFC +MENSAEPEQSLACQCLVRTPEVDDEALEKFDKALKALPMHIRLSFNPTQLEEQCHI"; my %results = (); calculate_protein_details( $protein, \%results); while (my ($k,$v) = each %results) { print $k, " => ", $v, "\n"; } } sub calculate_protein_details { my ($protein, $hash_ref) = @_; # copy here the code (except the first line) from # http://www-nmr.cabm.rutgers.edu/bioinformatics/ZebaView/help.html # (not your mangled code...) }

Output:

extinction => 16960 pI => 4.93 MW_N15 => 20105.52 MW => 19883.00 MW_SeMet => 20117.50 MW_N15_C13 => 20986.05

( Don't complicate matters and solve one problem at a time. Reading a fasta file to get its sequence is a entirely separate thing )

UPDATED: restructured the code a bit