http://qs321.pair.com?node_id=838797


in reply to Finding all connected nodes in an all-against-all comparison

Hi,

take a look at the Graph module:

use warnings; use strict; use Data::Dumper; use Graph; my $g = Graph->new(directed => 1); $g->add_vertex("Contig$_") for (1..11); while (my $line = <DATA>){ my @nodes = split( /\s+/,$line ); $g->add_edge( @nodes ); } print Dumper $g->weakly_connected_components; __DATA__ Contig1 Contig2 Contig1 Contig3 Contig2 Contig1 Contig2 Contig3 Contig3 Contig1 Contig3 Contig2 Contig3 Contig4 Contig4 Contig3 Contig4 Contig5 Contig6 Contig7 Contig7 Contig6 Contig8 Contig9 Contig9 Contig10 Contig10 Contig8 Contig10 Contig11 Contig11 Contig10
Cheers, Christoph

Replies are listed 'Best First'.
Re^2: Finding all connected nodes in an all-against-all comparison
by LanX (Sage) on May 07, 2010 at 14:15 UTC
    UPDATE: ARGH sorry this reply was meant for the OP!

    Thats really not trivial and more complicated than I thought because of edge cases (not covered in your sample code)

    So I can fully recommend using an already tested and optimized graph module because all solutions I had so far need to be rewritten for performance reasons...

    Cheers Rolf