From d32de5d7d82507b6509296ff064340e01c8ffdb7 Mon Sep 17 00:00:00 2001 From: preecej Date: Thu, 11 Aug 2011 00:08:27 +0000 Subject: [PATCH] Added creation of new groups when needed. svn path=/; revision=149 --- .../perl_singletons/pathway_gene_swapper.pl | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/preecej/perl_singletons/pathway_gene_swapper.pl b/preecej/perl_singletons/pathway_gene_swapper.pl index 41b0162..25772e7 100644 --- a/preecej/perl_singletons/pathway_gene_swapper.pl +++ b/preecej/perl_singletons/pathway_gene_swapper.pl @@ -325,7 +325,7 @@ sub create_unique_hex_id($$) if (exists ${$_[0]}{$candidate_id}) { # print "not unique...\n"; # TEST - $candidate_id = create_unique_hex_id($_[0]); + $candidate_id = create_unique_hex_id($_[0],$_[1]); } else { @@ -464,16 +464,38 @@ sub swap_genes } # print "@new_nodes_map\n"; # TEST - # if more than one new gene maps, you'll need a group for multiple gene boxes + # if more than one new paralog exists, and the old gene doesn't + # already belong to a group, you'll need a new Group for multiple + # gene boxes + my $new_GroupId; + if (scalar(@new_nodes_map) > 1) { # if curr old gene does not belong to a group + + # print $curr_old_gene_node->toString . "\n"; # TEST + # print $curr_old_gene_node->getAttribute("GroupRef"); # TEST + + if (!$curr_old_gene_node->getAttribute("GroupRef")) + { + #print "no existing group ref\n"; # TEST + + # generate a new GroupId and Group.GraphId hex ids not + # already in use + $new_GroupId = create_unique_hex_id(\%existing_hex_ids,"Group.GroupId"); + # my $new_Group_GraphId = create_unique_hex_id(\%existing_hex_ids,"Group.GraphId"); + #print "new group id: $new_GroupId\n"; # TEST + # print "$new_GroupId, $new_Group_GraphId\n"; # TEST + # create a new group node - # SUB: generate a new groupRef hex id not already in use - # add to end of group nodes - # for each new gene box - # use new or existing group id for new boxes - # add to new nodes ary + my $new_group = $gpml_doc->createElement("Group"); + $new_group->setAttribute("GroupId",$new_GroupId); + #$new_group->setAttribute("GraphId",$new_Group_GraphId); + $new_group->setAttribute("Style","Group"); + + # add to beginning of group nodes + $pathway_node->insertBefore($new_group,${$group_nodes}[0]); + } } # flag for determining if there are one or many replacement paralogs @@ -490,7 +512,6 @@ sub swap_genes if (scalar(@new_nodes_map) > 1) { $gene_suffix_counter++; - # TODO: check for new group ref to use } my $curr_new_node = $$_[0]; @@ -507,6 +528,12 @@ sub swap_genes . $curr_new_node->getAttributeNode("TextLabel")->getValue . (($gene_suffix_counter > 0) ? "-$gene_suffix_counter" : "")); + # add new GroupRef if necessary + if ($new_GroupId) + { + $curr_new_node->setAttribute("GroupRef",$new_GroupId); + } + # add Comment back-referencing TAIR locus id (use "source" attribute) # NOTE: order is important in GPML; the tags are first my $new_comment = $gpml_doc->createElement("Comment"); @@ -556,6 +583,7 @@ sub swap_genes - ($configs{"Y-Offset"} * $offset_multiplier)); } } + undef $new_GroupId; # clear this out so we can test against its existence next time # replace old node w/ new node(s) for (@new_nodes_map) { -- 2.34.1