[Bioperl-l] problem parsing a newick format

Mark A. Jensen maj at fortinbras.us
Thu Feb 12 15:07:39 UTC 2009


I'm pretty close to (what I think is) a solution to this very issue--more soon.
In the meantime--rom the looks of  Bio::Root::IO, it looks like there is no
explicit check of  $fh when it is defined and $file is not. (The arg $input is
well-checked, maybe $fh got lost in the shuffle)--
I suggest

 --- IO.pm       (revision 15529)
 +++ IO.pm       (working copy)
 @@ -311,6 +311,9 @@
            $self->throw("Could not open $file: $!");
            $self->file($file);
      }
 +    if ( defined($fh) && !ref($fh) ) {
 +       $self->throw("file handle $fh doesn't appear to be a handle");
 +    }
      $self->_fh($fh) if $fh; # if not provided, defaults to STDIN and STDOUT

      $self->_flush_on_write(defined $flush ? $flush : 1);

MAJ

----- Original Message ----- 
From: "Hilmar Lapp" <hlapp at gmx.net>
To: "Mark A. Jensen" <maj at fortinbras.us>
Cc: "bioPerl List" <bioperl-l at lists.open-bio.org>; "Chrysanthi A." 
<chrysain at gmail.com>
Sent: Thursday, February 12, 2009 9:58 AM
Subject: Re: [Bioperl-l] problem parsing a newick format


> Note that the terminal semi-colon is part of the format spec. I've  been 
> bitten by this a few times in other programs - it's quite common  that 
> programs reading newick will throw an error or ignore the tree if  it's not 
> terminated by semi-colon.
>
> Having said that, along the lines of being strict on what we emit but  liberal 
> in what we accept, I guess it can be loosened up. But what if  there is more 
> than one tree in the file?
>
> -hilmar
>
> On Feb 12, 2009, at 8:03 AM, Mark A. Jensen wrote:
>
>> No problem, Chyrsanthi--
>>
>> Jason-- may I loosen up the parser a bit on this?
>> MAJ
>>  ----- Original Message -----
>>  From: Chrysanthi A.
>>  To: Mark A. Jensen
>>  Sent: Thursday, February 12, 2009 7:47 AM
>>  Subject: Re: [Bioperl-l] problem parsing a newick format
>>
>>
>>  Yes, that was the problem.. Now its working perfect!!!! Thanks a lot!
>>
>>  Chrysanthi
>>
>>
>>  2009/2/12 Mark A. Jensen <maj at fortinbras.us>
>>
>>    Chrysanthi-
>>    Do the trees in your test file end with a semicolon? When I do
>>
>>    use Bio::TreeIO;
>>    $inp = Bio::TreeIO->new(-fh=>\*DATA, -format=>'newick);
>>    $tre=$inp->next_tree;
>>    __END__
>>    (A:1,(B:2,C:3))
>>
>>    $tre is empty, but when
>>
>>    use Bio::TreeIO;
>>    $inp = Bio::TreeIO->new(-fh=>\*DATA, -format=>'newick);
>>    $tre=$inp->next_tree;
>>    __END__
>>    (A:1,(B:2,C:3));
>>
>>    $tre contains the tree.
>>
>>    If this is the problem, it sounds like a bug to me-
>>    Mark
>>      ----- Original Message -----
>>      From: Chrysanthi A.
>>      To: Mark A. Jensen
>>      Cc: BioPerl List
>>      Sent: Thursday, February 12, 2009 5:42 AM
>>      Subject: Re: [Bioperl-l] problem parsing a newick format
>>
>>
>>      I tried also that, but it does not work.. It does not give me  any error 
>> message.. It
>> seems that the code is correct, but It does not print anything..Why???
>>
>>      Thanks,
>>
>>      Chrysanthi.
>>
>>
>>
>>
>>      2009/2/12 Mark A. Jensen <maj at fortinbras.us>
>>
>>        C- I think you maybe want
>>
>>        my $input = new Bio::TreeIO(-file =>"nexusCytochrome7R.newick",
>>                                  -format => "newick");
>>
>>        and not
>>
>>
>>          my $input = new Bio::TreeIO(-fh =>"nexusCytochrome7R.newick",
>>                                    -format => "newick");
>>
>>
>>        ?
>>
>>        Mark
>>
>>        ----- Original Message ----- From: "Chrysanthi A." <chrysain at gmail.com
>> >
>>        To: "BioPerl List" <bioperl-l at lists.open-bio.org>
>>        Sent: Wednesday, February 11, 2009 9:13 PM
>>        Subject: [Bioperl-l] problem parsing a newick format
>>
>>
>>
>>          Is the code below correct?? Why it does not print anything???
>>          use strict;
>>
>>          use Bio::TreeIO;
>>
>>
>>          my $input = new Bio::TreeIO(-fh =>"nexusCytochrome7R.newick",
>>                                    -format => "newick");
>>
>>          while(my $tree = $input->next_tree){
>>            for my $node(grep{!$_->is_Leaf}$tree->get_nodes){
>>          next if !$node->ancestor;
>>          print "Node:", $node->id, "length:", $node->branch_length,  " ";
>>          for my $child($node->get_Descendents){
>>            print "child:", $child->id, "", $child->branch_length, " ";
>>          }
>>            print "\n";
>>            }
>>          }
>>
>>          Any ideas? I want to read a tree and mainly get the  duplication 
>> events.
>>          Could someone help me?
>>
>>          Thanks a lot,
>>
>>          Chrysanthi
>>          _______________________________________________
>>          Bioperl-l mailing list
>>          Bioperl-l at lists.open-bio.org
>>          http://lists.open-bio.org/mailman/listinfo/bioperl-l
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> Bioperl-l mailing list
>> Bioperl-l at lists.open-bio.org
>> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>
> -- 
> ===========================================================
> : Hilmar Lapp  -:-  Durham, NC  -:-  hlapp at gmx dot net :
> ===========================================================
>
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>
> 




More information about the Bioperl-l mailing list