Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Added creation of new groups when needed.
authorpreecej <preecej@localhost>
Thu, 11 Aug 2011 00:08:27 +0000 (00:08 +0000)
committerpreecej <preecej@localhost>
Thu, 11 Aug 2011 00:08:27 +0000 (00:08 +0000)
svn path=/; revision=149

preecej/perl_singletons/pathway_gene_swapper.pl

index 41b01625e18a36b556e7b5cda1d972a464f9795a..25772e76ffefc7edc1b908442dfb1c56e5e5138b 100644 (file)
@@ -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 <Comment> 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) {