Go Back   SEQanswers > Bioinformatics > Bioinformatics

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl script to convert BAM to BED? rebrendi Bioinformatics 3 03-22-2012 10:34 PM
vcftools perl script weiyulin Bioinformatics 6 12-09-2010 02:13 PM
perl script bioenvisage Bioinformatics 5 02-01-2010 08:11 AM
perl script bioenvisage Bioinformatics 0 02-01-2010 07:23 AM
Perl script bioenvisage Bioinformatics 4 01-28-2010 12:25 PM

Thread Tools
Old 07-02-2011, 02:27 AM   #1
Location: holland

Join Date: Apr 2010
Posts: 55
Default just perl script

I am a new user in perl. I want to make a subroutine that takes the taxonomy-id as input and returns the list of leaf nodes as output and I wrote this script but it's not working. Any suggestion? Thanks in advance.

use strict;
my @leafnodes_list = getleafnodes (my $taxid);
print @leafnodes_list;
sub getleafnodes
my ($taxid) = @_;
print "type Taxid number:";
$taxid = <STDIN>;
chomp $taxid;
foreach (@_){
"getz [taxonomy-ID:$taxid] >_ tax_down";
return @_;

semna is offline   Reply With Quote
Old 07-02-2011, 03:35 AM   #2
Location: Israel

Join Date: Dec 2010
Posts: 25

Hi semma,
your question fits better to PerlMonks:

Can you give an example of expected INPUT and expected OUTPUT, it might help to figure out where is your bug in script.


Last edited by zhidkov.ilia; 07-02-2011 at 03:41 AM.
zhidkov.ilia is offline   Reply With Quote
Old 07-02-2011, 03:56 AM   #3
Location: holland

Join Date: Apr 2010
Posts: 55

This is actually used to make a tree by using taxonomy ID. input is just a number and output is a list of different names and numbers that I used getz command for that.
semna is offline   Reply With Quote
Old 07-02-2011, 08:42 AM   #4
David Eccles (gringer)
Location: Wellington, New Zealand

Join Date: May 2011
Posts: 838
Default Here's what your code does as it is

I need to re-order your code a tiny bit to get my head around how it works...

 1 #!/usr/bin/perl
 2 use strict;
 3 sub getleafnodes {
 4   my ($taxid) = @_;
 5   print "type Taxid number:";
 6   $taxid = <STDIN>;
 7   chomp $taxid;
 8     foreach (@_){
 9       "getz [taxonomy-ID:$taxid] >_ tax_down";
10       return @_;
11    }
12 }
13 my @leafnodes_list = getleafnodes (my $taxid);
14 print @leafnodes_list;
Up to line 3, things look good, although I'd suggest 'use warnings;' as well.
Line 4: the scalar variable $taxid is set to the first argument of the function getleafnodes. Nothing is done with this variable before it is assigned a new value on line 6.
Line 5: Print (without line breaks) the string "type Taxid number:"
Line 6: read a single line from standard input, store the result (including ending line break) in the scalar variable $taxid.
Line 7: Remove the final line break from the variable $taxid.
Line 8: loop through the arguments of the function (@_), setting the default scalar variable (i.e. $_) to that argument.
Line 9: Do absolutely nothing with the string "getz [taxonomy-ID:$taxid] >_ tax_down" -- no printing, no evaulation, no assignment.
Line 10: return the arguments of the function (@_), breaking out of the loop in the process
Lines 11-12 are never reached by any code
Line 13: create an array @leafnodes_list, which is set to the return value of the function getleafnodes, given an argument that is an undefined value, created due to the initialisation of a new scalar variable $taxid. The function returns the arguments sent to the function, so this will be an array containing a single element, namely an undefined value.
Line 14: print the elements of the array @leafnodes_list, not separated by anything. As the only element in the list is the undefined value, this will not print anything.

So, if you're lucky, this function will probably output one thing, "type Taxid number:". If that is what you wanted to do, here's a simpler way to do it:
print "type Taxid number:"
Could you please explain in a bit more detail what you were trying to do?
gringer is offline   Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

All times are GMT -8. The time now is 07:37 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO