Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • semna
    Member
    • Apr 2010
    • 55

    #1

    just perl script

    Hi
    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.

    #!/usr/bin/perl
    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 @_;
    }

    }
  • zhidkov.ilia
    Member
    • Dec 2010
    • 25

    #2
    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.

    Ilia
    Last edited by zhidkov.ilia; 07-02-2011, 03:41 AM.

    Comment

    • semna
      Member
      • Apr 2010
      • 55

      #3
      HI,
      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.
      thanks

      Comment

      • gringer
        David Eccles (gringer)
        • May 2011
        • 845

        #4
        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...

        Code:
         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:
        Code:
        #!/usr/bin/perl
        print "type Taxid number:"
        Could you please explain in a bit more detail what you were trying to do?

        Comment

        Latest Articles

        Collapse

        • kinpict.com
          Reply to 16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
          by kinpict.com
          The part about this topic feels surprisingly grounded, and the details on the page is the bit that made me slow down. I’d keep <a href="https://kinpict.com/">ai family photo generator</a> bookmarked for later.
          Today, 06:37 PM
        • SEQadmin2
          16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
          by SEQadmin2





          NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification,...
          10-30-2026, 06:46 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by SEQadmin2, 11-12-2026, 07:59 AM
        0 responses
        27 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 11-05-2026, 09:25 AM
        0 responses
        35 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 11-03-2026, 11:54 AM
        2 responses
        56 views
        0 reactions
        Last Post kinpict.com  
        Started by SEQadmin2, 10-28-2026, 09:57 AM
        0 responses
        175 views
        0 reactions
        Last Post SEQadmin2  
        Working...