maklujkar has asked for the wisdom of the Perl Monks concerning the following question:
Dear PerlMonks,
I would appreciate any advice you have about a problem I have running a Perl script on the newer Mac operating systems.
I wrote a script to read each line of an input table for a pair of coordinates to extract segments from a long DNA sequence. (The whole script is below.) It worked on my old MacBook Pro with the Snow Leopard operating system. It still works on my student's non-Mac laptop. However, when I run it on my new MacBook Pro (Mavericks) or my Mac desktop (Mountain Lion), it only takes the first line of input, as if it is ignoring the while loop. It never gives me an error message.
I tried installing xcode, perlbrew, and Perl 5.18, but that didn't help. The perl -v command told me that I was running Perl 5.16. I deleted xcode and everything in the Perl folder in the Library (versions 5.8, 5.12) and any other Perl folder I could find, and it still runs the script with just the first line of input, and there is still a version 5.16 somewhere inside the computer. I don't know what to do, and Apple support has no idea either.
Muktak Aklujkar
The script:
#!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $inputFile; my $sequenceFile; my $outputFile; my $template; my %hashComps = ("T"=>"A", "G"=>"C", "C"=>"G", "A"=>"T", "N"=>"N"); my %hashStrand = ("f"=>"+", "r"=>"-", "+"=>"+", "-"=>"-"); Getopt::Long::Configure ('bundling'); GetOptions ('i|input_file=s' => \$inputFile, 's|sequence_file=s' => \$sequenceFile, 'o|output_file=s' => \$outputFile); if(!defined($inputFile)) { die ("Usage: FASTAgeneratorDNA.pl -i <input file> -s <sequence file> - +o <output file>\n"); } if(!defined($sequenceFile)) { die ("Usage: FASTAgeneratorDNA.pl -i <input file> -s <sequence file> - +o <output file>\n"); } if(!defined($outputFile)) { die ("Usage: FASTAgeneratorDNA.pl -i <input file> -s <sequence file> - +o <output file>\n"); } open (INFILE, "<$inputFile") or die( "Cannot open file : $!" ); open (SEQFILE, "<$sequenceFile") or die( "Cannot open file : $!" ); open (OUTFILE, ">$outputFile") or die ("Cannot open file for output: $ +!"); my $DNAsequence = ""; while (my $line = <SEQFILE>) { chomp($line); if ($line =~ />/) { #if line contains FASTA header after any amount of + whitespace next; } else { $DNAsequence .= $line; } #end of else structure } #end of while loop for each line while (my $coordinates = <INFILE>) { my @coordinates_array = split /\s+/, $coordinates; my $seqid = $coordinates_array[0]; my $strand = $hashStrand{$coordinates_array[1]}; my $start = $coordinates_array[2] - 1; my $stop = $coordinates_array[3] - $start; print (OUTFILE "\n>$seqid"); $template = substr($DNAsequence, $start, $stop); my $revcomp = ""; if ($strand eq "+") { print (OUTFILE "\n$template"); } elsif ($strand eq "-") { while ($template) { my $lastbase = uc(chop($template)); my $nextbase = $hashComps{$lastbase}; $revcomp .= $nextbase; } #end of while loop for revcomp print (OUTFILE "\n$revcomp"); } else { die( "Please specify the strand with a plus or minus symbol."); } #end of else structure } #end of while loop for each set of coordinates close (OUTFILE) or die( "Cannot close file : $!"); close (SEQFILE) or die( "Cannot close file : $!"); close (INFILE) or die( "Cannot close file : $!");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Script ignoring while loop on Mountain Lion and Mavericks
by kcott (Archbishop) on Feb 13, 2014 at 02:03 UTC | |
by maklujkar (Initiate) on May 31, 2014 at 19:27 UTC | |
|
Re: Script ignoring while loop on Mountain Lion and Mavericks (newline)
by Anonymous Monk on Feb 13, 2014 at 00:49 UTC | |
by maklujkar (Initiate) on Feb 13, 2014 at 02:45 UTC |