CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Help with DNA sequence software

 



geneclicker
New User

Sep 27, 2012, 10:55 PM

Post #1 of 7 (1302 views)
Help with DNA sequence software Can't Post

Hello everyone. I'm new to perl. I work on manual curation projects on alphabet based content.

I have a perl program which reads a text file and breaks it up in contiguous chunks according to input provided by the user.

My problem is can get the program to run but it gives me error messages. It says command not found.

The original coder has moved on to better projects.

Can someone please help?

I work on a mac in case this is important to know.

Thank you much.

G clicker

The code in perl

#!/usr/bin/perl
use strict;
use warnings;
my @params = ();
while ( my $param = shift ) {
push @params, $param;
}
unless ( scalar @params == 4 ) {
print "$0 <input fasta file> <block size> <block label> <output file>\n";
exit;
}
my ( $inputFile, $blockSize, $blockLabel, $outputFile ) = @params;
print "Input seems to be valid. Now I will try reading the contents of $inputFile...";
open INPUT, '<', $inputFile or die $!;
open OUTPUT, '>', $outputFile or die $!;
my $sequence = '';
while ( <INPUT> ) {
chomp;
next if ( /^\s*$/ );
next if ( /^>/ );
$sequence .= $_;
}
print "done.\n";
my $pos = 0;
my $index = 0;
print "The sequence has ", length($sequence), " bases. Now I will try breaking it into segments, each of size $blockSize bases.\n";
while ( $pos < length($sequence) ) {
$index++;
print OUTPUT ">$blockLabel$index\n";
print OUTPUT substr($sequence, $pos, $blockSize) . "\n";
$pos += $blockSize;
}
close OUTPUT;
close INPUT;
print "Successfully generated $outputFile.\n";

end of code.

the target file looks like this, the extension on the file is .fa

GCGTCCGCGGAGGGGGCGGCGGGCCTGGGCGACCCTGCACCTCTGGGCCG
TGGGGACTGTGGGGTGGGGCGGGGGCCGATGCGGCAGGGGTGAGGCCTGG
GGCCGGCGGGGTGACGGGGACCCGGCCCTGCGTGGGGAAGCCTCGGGGGG
ACAAGCAGAGACGCAGCCTGCTGGGAGCGGCCCAAGCTCTGCACCGGCCC
GCGGCGGGAGCACAGCAGCCCCCTCCCGCCCCTCCTCCCGGGGGCTCCGA
GGGGTGGTTATGGGGCGAGGGTCCTTGCGGGGCCCGGGCAGTGAAGGGCC
TGGAGGCCCCAGAGTCTGTGCCAGGTCTGAGCCGCGGGGCGTGGGGGGAG
GAGGGGCCTCGGCCGGGGCCCAGGAGACCCAGGACAGGTGGGCCTGGGGC
CAGGTCCCTACGGAGAGGTGGCCGGGCCGGGCTCTGGCTTGCCGGGGTAG
GGGCTCCGCTAGGGGCTGGAGTCCGTCCCTTCGCCAGCGCAGAGCCCCTC
GGCCCGCATCTGCCAAGTGACTGAGGATCGAGCGACAGCGTAGTGGGGCG
GAGGGGCTGGAGGCACGGCCGGAAAGGGTGAGCGGCGCCGTGGCTCCCCC
GCTATTTATTTGGCCCCGCCACGCGCGGAGAGGGAGGAAATTCTCAGGCT
GCGGCTGCAGCTAGGGGAGGCCCAGGTGGGCCTGGAATGGGCCCAGAGAG
GGCTTCCTGGGTCAGACGTGTAGATCCAGTGGACGTGAAAACCGGGTGAG
TGTCCCGGTGGGACCCAGAGCGCGGGGAGGCTTGGAGGCAGGGGCATGGG
CTGAGGACCCTCAAGGCACCCTCCTCGCGACCTGTCAGAGCTCCGAGGGG
TGGGGGTGTCCTGTGTGTGGCTGTGGGGATCCTGGGCGGCGGGTGCTGGG

Please see attached files.


(This post was edited by geneclicker on Sep 27, 2012, 11:12 PM)
Attachments: splitFasta.pl (0.97 KB)
  IGK_2.fa (206 KB)


zing
Novice

Sep 27, 2012, 11:59 PM

Post #2 of 7 (1297 views)
Re: [geneclicker] Help with DNA sequence software [In reply to] Can't Post

Why dont you try this command instead
perl -ne 'BEGIN{ $/=">"; } if(/^\s*(\S+)/){ open(F,">$1.fsa")||warn"$1 write failed:$!\n";chomp;print F ">", $_ }' fastafile.fa


geneclicker
New User

Sep 28, 2012, 3:15 AM

Post #3 of 7 (1272 views)
Re: [zing] Help with DNA sequence software [In reply to] Can't Post

Hey Zing thanks for the input. As said before I wouldnt know where to paste the code you suggested.

I am like a monkey see , monkey do type worker.

Please recommend where I would paste the code , if it is in the script itself or in the terminal.

Thank you for your help. I am much obliged.

[


zing
Novice

Sep 28, 2012, 4:54 AM

Post #4 of 7 (1266 views)
Re: [geneclicker] Help with DNA sequence software [In reply to] Can't Post

You can write the command in the terminal, that would do fine.


Laurent_R
Veteran / Moderator

Sep 28, 2012, 6:02 AM

Post #5 of 7 (1263 views)
Re: [geneclicker] Help with DNA sequence software [In reply to] Can't Post

Hi,

you should tell on which line you get your error message.

This code:


Code
 my @params = ();   
while ( my $param = shift ) {
push @params, $param;
}
unless ( scalar @params == 4 ) {
print "$0 <input fasta file> <block size> <block label> <output file>\n";
exit;
}
my ( $inputFile, $blockSize, $blockLabel, $outputFile ) = @params;
print "Input seems to be valid. Now I will try reading the contents of $inputFile...";


coluld be simplified as follows:


Code
 print "$0 <input fasta file> <block size> <block label> <output file>\n" and die unless $ARGV == 4;  
my ( $inputFile, $blockSize, $blockLabel, $outputFile ) = @ARGV;



(This post was edited by Laurent_R on Sep 28, 2012, 6:16 AM)


FishMonger
Veteran / Moderator

Sep 28, 2012, 6:50 AM

Post #6 of 7 (1257 views)
Re: [geneclicker] Help with DNA sequence software [In reply to] Can't Post

There are improvements that can be made to the script, but the script itself is not generating the error. That's an error generated by the shell. The error message is telling you that the shell couldn't find the script.

How are you executing the script?

Are you executing it from the same directory where it's located and if so, are you specifying the path?


Quote
[root@099-91-RKB01 ~]# splitFasta.pl
bash: splitFasta.pl: command not found

[root@099-91-RKB01 ~]# ./splitFasta.pl
./splitFasta.pl <input fasta file> <block size> <block label> <output file>



geneclicker
New User

Sep 28, 2012, 9:06 AM

Post #7 of 7 (1249 views)
Re: [FishMonger] Help with DNA sequence software [In reply to] Can't Post

Dear all thanks so much it actually worked when I had everything in the same folder. The script and the target in the same folder.

Thanks a lot everyone.

I will be back here requesting for help with another program for pattern finders. Till then gentlemen happy hacks.

Best,
G clicker

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives