diff --git a/.gitignore b/.gitignore index 40fb65a17..5fee796cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ /dist/ /target/ jsbml.log -/bin/ **/.DS_Store **/.classpath .settings/ diff --git a/bin/GeneNet b/bin/GeneNet new file mode 100755 index 000000000..a51b631ca Binary files /dev/null and b/bin/GeneNet differ diff --git a/bin/GeneNet.mac64 b/bin/GeneNet.mac64 new file mode 100755 index 000000000..a51b631ca Binary files /dev/null and b/bin/GeneNet.mac64 differ diff --git a/bin/apply_post_filter.pl b/bin/apply_post_filter.pl new file mode 100755 index 000000000..6dcb118f6 --- /dev/null +++ b/bin/apply_post_filter.pl @@ -0,0 +1,115 @@ +#!/usr/bin/perl +#******************************************************************************* +# +# This file is part of iBioSim. Please visit +# for the latest version of iBioSim. +# +# Copyright (C) 2017 University of Utah +# +# This library is free software; you can redistribute it and/or modify it +# under the terms of the Apache License. A copy of the license agreement is provided +# in the file named "LICENSE.txt" included with this software distribution +# and also available online at . +# +#******************************************************************************* + +if ($#ARGV != 3){ + print "Usage: ./recheck_results.pl cutoff file_method_dot file_correct.dot file_output\n"; + exit(1); +} + +my $cutoff = $ARGV[0]; +my $outfile = $ARGV[3]; + +check_correctness($ARGV[1], $ARGV[2]); + + +sub check_correctness{ + my $filename = shift; + my $dot_file = shift; + + open (IN1, "$dot_file") or die "I cannot check dot correctness for $dot_file\n"; + open (IN2, "$filename") or die "I cannot check correctness for $filename\/method.dot\n"; + open (OUT, ">$outfile") or die "I cannot write the checked file\n"; + + my @in1 = ; + my @in2 = ; + close IN1; + close IN2; + + my $in1 = join ("",@in1); + my $in2 = join ("",@in2); + + $in1 =~ s/sp_//g; + $in2 =~ s/sp_//g; + + print OUT "digraph G {\n"; + #generate the states in the corrected output + for (my $i = 0; $i <= $#in2; $i++){ + if ($in2[$i] =~ m/shape=ellipse/){ + print OUT $in2[$i]; + } + } + + my $r_c = 0; + my $r_t = 0; + #check precision + while ($in1 =~ m/s([0-9]+) -> s([0-9]+) .+arrowhead=((vee|tee))/g){ + $r_t++; + my $state1 = $1; + my $state2 = $2; + my $arc = $3; + #print "I matched $state1 $arc $state2\n"; + if ($in2 =~ m/s$state1 -> s$state2 .*arrowhead=$arc/){ + $r_c++; + } + } + print "\tRecall: $r_c/$r_t = '" . $r_c/$r_t . "'\n"; + + my $p_c = 0; + my $p_t = 0; + #check precision + while ($in2 =~ m/s([0-9]+) -> s([0-9]+) (.+), *arrowhead=((vee|tee))/g){ + $p_t++; + my $state1 = $1; + my $state2 = $2; + my $mid = $3; + my $arc = $4; + + my $remove_arc = 0; + #print "I matched $state1 $arc $state2\n"; + if ($mid =~ m/label=\"[-]*([0-9]+[.]*[0-9]*)/){ + my $num = $1; + $num = (int (10000 * $num)) / 10000; +# $mid =~ m/(label=\"[-]*)[0-9]+[.]*[0-9]*/$1$num/; + if ($num < $cutoff){ + $mid =~ s/color=\"[^\"]+/color=\"green/; + $remove_arc = 1; + } + } + if (not $remove_arc){ +#WE DO NOT NEED TO CHECK THIS AT THIS STAGE +# if ($in1 =~ m/s$state1 -> s$state2 .*arrowhead=$arc/){ +# $p_c++; + print OUT "s$state1 -> s$state2 $mid,arrowhead=$arc]\n"; +# } +# else{ +# print OUT "s$state1 -> s$state2 $mid,arrowhead=$arc,style=dashed]\n"; +# } + } + } + if ($p_t > 0){ + print "\tPrecision: $p_c/$p_t = '" . $p_c/$p_t . "'\n"; + } + else{ + print "\tPrecision: $p_c/$p_t = '0'\n"; + } + + print OUT "\n}\n"; + + close OUT; + + return ($r_c,$r_t,$p_c,$p_t); + +} + diff --git a/bin/check_dot.pl b/bin/check_dot.pl new file mode 100755 index 000000000..75b80e4a2 --- /dev/null +++ b/bin/check_dot.pl @@ -0,0 +1,152 @@ +#!/usr/bin/perl +#******************************************************************************* +# +# This file is part of iBioSim. Please visit +# for the latest version of iBioSim. +# +# Copyright (C) 2017 University of Utah +# +# This library is free software; you can redistribute it and/or modify it +# under the terms of the Apache License. A copy of the license agreement is provided +# in the file named "LICENSE.txt" included with this software distribution +# and also available online at . +# +#******************************************************************************* + +#This file writes the checked dot file. + +if ($#ARGV == 1){ + print "Normal Usage: ./check_dot.pl Unchecked_Dot, Master_Dot, Out_Dot\n"; + print "Assumed usage: ./check_dot.pl Unchecked_Dot, [find the masterdot ] Out_Dot\n"; + $assumed = $ARGV[1]; + $assumed =~ s/(.*)\/(.*)\/(.*)\/([^\/]*).dot/$1\/$2\/$2.dot/; + if (not -e "$assumed"){ + print "ERROR: Unable to find a master dot file $assumed from $ARGV[1]\n"; + exit(1); + } + + $unchecked = $ARGV[0]; + $master_dot = $assumed; + $out = $ARGV[1]; + +} +elsif ($#ARGV != 2){ + print "Usage: ./check_dot.pl Unchecked_Dot, Master_Dot, Out_Dot\n"; + exit(1); +} +else{ + $unchecked = $ARGV[0]; + $master_dot = $ARGV[1]; + $out = $ARGV[2]; +} + + + +if (not -e "$master_dot"){ + print "ERROR: unable to check correctness for non exsistant? $master_dot\n"; + exit(1); +} +if (not -e "$unchecked"){ + print "ERROR: unable to check correctness for non exsistant? '$unchecked'\n"; + exit(1); +} +open (IN1, "$master_dot") or die "I cannot check dot correctness for $master_dot\n"; +open (IN2, "$unchecked") or die "I cannot check correctness for $filename\/method.dot\n"; +open (CHECKED, ">$out") or die "I cannot write the checked file\n"; + +my @in1 = ; +my @in2 = ; +close IN1; +close IN2; + +my $in1 = join ("",@in1); +my $in2 = join ("",@in2); + +$in1 =~ s/sp_//g; +$in2 =~ s/sp_//g; + +print CHECKED "digraph G {\n"; +#generate the states in the corrected output +for (my $i = 0; $i <= $#in2; $i++){ + if ($in2[$i] =~ m/shape=ellipse/){ + print CHECKED $in2[$i]; + } +} + +#draw things acording to the following plan +# \ True +#Reported \ a r n +# \ ___________________________ +# a | blue | red | black | +# | solid | dashed | dashed | +# | normal | tee | onormal | +# |-----------------|---------| +# r | blue | red | black | +# | dashed | solid | dashed | +# | normal | tee | obox | +# |-----------------|---------| +# n | blue | red | | +# | dotted | dotted | | +# | normal | tee | | +# ----------------------------- +# +#Check the first 2 columns above +while ($in1 =~ m/s([0-9]+) -> s([0-9]+) (.+)arrowhead= *((vee|tee))/g){ + my $state1 = $1; + my $state2 = $2; + my $mid = $3; + my $arc = $4; +# if ($mid =~ m/label=\"[-]*([0-9]+[.]*[0-9]*)/){ +# my $num = $1; +# $num = (int (10000 * $num)) / 10000; +# if ($num < $green_level){ +# $mid =~ s/color=\"[^\"]+/color=\"green/; +# } +# } + if ($in2 =~ m/s$state1 -> s$state2 (.*)arrowhead=$arc/){ + $tmp = $1; + $arc =~ s/vee/normal/; + print CHECKED "s$state1 -> s$state2 $tmp arrowhead=$arc]\n"; + } + elsif ($in2 =~ m/s$state1 -> s$state2 (.*)arrowhead=/){ + $tmp = $1; + if ($tmp =~ m/blue/){ + $tmp =~ s/blue/firebrick/; + } + else{ + $tmp =~ s/firebrick/blue/; + } + $arc =~ s/vee/normal/; + print CHECKED "s$state1 -> s$state2 $tmp style=dashed, arrowhead=$arc]\n"; + } + else{ + $arc =~ s/vee/normal/; + #$mid =~ s/color=\"[^\"]+/color=\"gray/; + print CHECKED "s$state1 -> s$state2 $mid style=dotted, arrowhead=$arc]\n"; + } +} +#Check the third column +while ($in2 =~ m/s([0-9]+) -> s([0-9]+) (.+)arrowhead=((vee|tee))/g){ + my $state1 = $1; + my $state2 = $2; + my $mid = $3; + my $arc = $4; + if ($in1 =~ m/s$state1 -> s$state2 /){ + #do nothing as this was already taken care of above + } + else{ + $mid =~ s/color=\"[^\"]+/color=\"black/; + $arc =~ s/(vee|normal)/onormal/; + $arc =~ s/tee/obox/; + print CHECKED "s$state1 -> s$state2 $mid style=dashed, arrowhead=$arc]\n"; + } +} + + + + +print CHECKED "\n}\n"; + +close CHECKED; + + diff --git a/bin/gcm2sbml.pl b/bin/gcm2sbml.pl new file mode 100755 index 000000000..faa2db0c5 --- /dev/null +++ b/bin/gcm2sbml.pl @@ -0,0 +1,1190 @@ +#!/usr/bin/perl -w +#******************************************************************************* +# +# This file is part of iBioSim. Please visit +# for the latest version of iBioSim. +# +# Copyright (C) 2017 University of Utah +# +# This library is free software; you can redistribute it and/or modify it +# under the terms of the Apache License. A copy of the license agreement is provided +# in the file named "LICENSE.txt" included with this software distribution +# and also available online at . +# +#******************************************************************************* + +use Getopt::Std; + +#Global indicing variables +$STATE = 0; +$PROTEIN = 1; +$CONST = 2; + +$PROMOTER = 0; +$INPUT = 1; +$OUTPUT = 2; +$ARROWHEAD = 3; +$STOC = 4; +$TYPE = 5; + +#Global reaction params +$deg = 0.0003; +$kf_dimer = 20.0; +$kr_dimer = 1.0; + +$kf_complex = 20.0; +$kr_complex = 1.0; + +$kf_rep = 0.8; +$kr_rep = 1.0; + +$kf_bind_dimer = 10.0; +$kr_bind_dimer = 1.0; + +$kf_act = .00033; +$kr_act = 1.0; + +$rnap_binding = 0.033; +$rnap_unbinding = 1.0; +$ocr = 0.1; +$unactived_production = 0.01; +$activated_production = 0.1; +$num_promo = 1.0; +$stochiometry = 1.; +$num_RNAP = 30.0; +$dimer_deg = .0003; + +$spastic = 0.9; + +sub getuid{ + return $uid++; +} + +sub main{ + if ($#ARGV == 1){ + #open up the dotfile and store it to an array + my $file = $ARGV[0]; + $abv_name = $ARGV[0]; + open (FILE, "$file") or die "I cannot open dot $file\n"; + @dot_file = ; + close FILE; + #open out outfile and start writing to it when writing to OUT + open (OUT, ">$ARGV[1]") or die "I cannot open out file $ARGV[1]\n"; + $dot_file = join ("", @dot_file); + + #create the normal sbml file + fill_hashes(); + build_reactions(); +# print_all_info(); + + create_real_network($file); + } elsif ($#ARGV >= 2) { + getopts ('dcf:'); + if ($opt_c) { + print "Applying biochemical abstraction\n"; + } + if ($opt_d) { + print "Applying dimer degradation\n"; + } + #open up the dotfile and store it to an array + $abv_name = $ARGV[$#ARGV-1]; + my $file = $ARGV[$#ARGV-1]; + open (FILE, "$file") or die "I cannot open dot $file\n"; + @dot_file = ; + close FILE; + + if ($opt_f) { + $file = $opt_f; + open (FILE, "$file") or die "I cannot open parameterfile $file\n"; + @parameter_file = ; + close FILE; + $parameter_file = join ("", @parameter_file); + load_parameters(); + } + + #open out outfile and start writing to it when writing to OUT + open (OUT, ">$ARGV[$#ARGV]") or die "I cannot open out file $ARGV[$#ARGV]\n"; + $dot_file = join ("", @dot_file); + + #create the normal sbml file + fill_hashes(); + build_reactions(); +# print_all_info(); + + create_real_network($file); + + } else { + print "Usage: dot2sbml.pl dotfile outfile or dot2sbml.pl -options dotfile outfile\n"; + } + +} + +sub load_parameters{ + print "Loading parameters\n"; + if ($parameter_file =~ m/deg[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing degradation to: $1\n"; + $deg = $1; + } + if ($parameter_file =~ m/dimer_deg[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing dimer degradation to: $1\n"; + $dimer_deg = $1; + } + if ($parameter_file =~ m/kf_dimer[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing dimer formation to: $1\n"; + $kf_dimer = $1; + } + if ($parameter_file =~ m/kr_dimer[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing dimer breaking to: $1\n"; + $kr_dimer = $1; + } + if ($parameter_file =~ m/kf_complex[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing complex formation to: $1\n"; + $kf_complex = $1; + } + if ($parameter_file =~ m/kr_complex[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing complex breakup to: $1\n"; + $kr_complex = $1; + } + if ($parameter_file =~ m/kf_rep[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing repression binding to: $1\n"; + $kf_rep = $1; + } + if ($parameter_file =~ m/kr_rep[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing repression unbinding to: $1\n"; + $kr_rep = $1; + } + if ($parameter_file =~ m/kf_act[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing activation binding to: $1\n"; + $kf_act = $1; + } + if ($parameter_file =~ m/kr_act[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing activation unbinding to: $1\n"; + $kr_act = $1; + } + if ($parameter_file =~ m/rnap_binding[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing rnap binding to: $1\n"; + $rnap_binding = $1; + } + if ($parameter_file =~ m/rnap_unbinding[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing rnap unbinding to: $1\n"; + $rnap_unbinding = $1; + } + if ($parameter_file =~ m/ocr[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing open complex production reaction binding to: $1\n"; + $ocr = $1; + } + if ($parameter_file =~ m/basal[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing open complex production (basal): $1\n"; + $unactived_production = $1; + } + if ($parameter_file =~ m/activated[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing open complex production (activated): $1\n"; + $activated_production = $1; + } + if ($parameter_file =~ m/dimer_binding[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing dimer binding rate: $1\n"; + $kf_bind_dimer = $1; + } + if ($parameter_file =~ m/dimer_unbinding[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing dimer unbinding rate: $1\n"; + $kr_bind_dimer = $1; + } + if ($parameter_file =~ m/stochiometry[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Stochiometry: $1\n"; + $stochiometry = $1; + } + if ($parameter_file =~ m/promoters[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing number of promoters: $1\n"; + $num_promo = $1; + } + if ($parameter_file =~ m/RNAP[\s]*=[\s]*([0-9]*\.?[0-9]*)/) { + print "Changing RNAP: $1\n"; + $num_RNAP = $1; + } +} + +sub fill_hashes{ + undef %dimers; + undef %proteins; #list of proteins in the soup + undef %promoters; #list of promoters + undef %biochem; #list of biochem reactions + undef %states; #list of states to proteins + undef %spastics; #list of spastic proteins + + $uid = 0; +# print "Try to parse inside bracket of species\n"; + while ($dot_file =~ m/(^|\n) *([^- \n]*) *\[(.*)\]/g){ + my $constant; + my $protein; + my $state = $2; + my $temp = $3; + my @struc; +# print "$temp\n"; + # Parse the label + if ($temp =~ m/label=\"(.*)\"/) { +# print "Protein Name: $1\n"; + $protein = $1; + if ($protein =~ m/spastic/){ + $spastics{$protein} =$protein; + } + } else { + print "Error, must have label for $state\n"; + exit(0); + } +# print "$temp\n"; + if ($temp =~ m/const=([^,|\s]*)/) { +# print "Constant Source: true\n"; + if ($1 eq "true") { + $constant = 1; + } else { + $constant = 0; + } + } else { +# print "Constant Source: false\n"; + $constant = 0; + } + #State name, protein name, is constant?, number of sources + @struct = ($state, $protein, $constant, 0); + + $proteins{$state} = [@struct]; + $states{$protein}=$state; + } +# print "Done parse inside bracket of species\n"; +# print "Try to parse inside bracket of edge\n"; + while ($dot_file =~ m/(^|\n) *([^ \n]*) *\-\> *([^ \n]*) *\[(.*)arrowhead=([^,\]]*)(.*)/g){ + my $start = $2; + my $end = $3; + my $info = $4; + my $arrowhead = $5; + my $extra_info = $6; + my $stoc = 1; + + my $promoter; + my $type="regular"; + + # custom data struct to hold information + my @struct; + + my $total_info = "$info,$extra_info"; + + if ($total_info =~ m/label="*([0-9]+)[,|\"]/){ + #dimerization for first species +# print "Found a dimer for $start in '$total_info'\n"; + $stoc = $1; + if (exists($dimers{$start}) and $dimers{$start} != $stoc){ + print "ERROR: unhandled dimerization. Unable to create different dimerizations, '$dimers{$start}' and '$start'"; + exit(0); + } + else{ + $dimers{$start} = $stoc; + } + } + + if ($total_info =~ m/promoter="(.*)"/){ +# print "Found promoter $1 in '$total_info'\n"; + $promoter = $1; + } else { + # If no promoter name is given, use the default promoter, the end name + #my $uid = getuid(); + $promoter = "Promoter_$end"; + } + if ($total_info =~ m/type=(.*)[,]/){ +# print "Found biochemical reaction\n"; + $type = $1; + } + build_interaction(($promoter, $proteins{$start}[1], $proteins{$end}[1], $arrowhead, $stoc, $type)); +# if ($total_info =~ m/label="*([0-9]+[,|\"])/){ #" +# } + } +# print "Done parse inside bracket of edge\n"; +} + +#Builds the interaction map used to generate the SBML +sub build_interaction { + my @params = @_; +# print "Printing params\n@params\n"; + #TODO: Check for problems if species used in more than 1 reaction + #Check to see if the promoter exists yet, if not, add it + if (not exists($promoters{$params[$PROMOTER]})) { + my @input = [[{$params[$INPUT]=>$params[$STOC]}, $params[$TYPE], $params[$ARROWHEAD]]]; +# print "First promo addr: @input\n"; + $promoters{$params[$PROMOTER]} = [$params[$PROMOTER], @input, {$params[$OUTPUT]=>$params[$OUTPUT]}]; + } + #If it does exist, check to see if it is a biochem reaction, and if so, see if it can be combined + #with an existing input + else { + my $found = 0; + #Check to see if it can be added to any reactions + #by cycling through each promoter and checking the input arrays + #and checking to see if the arrowhead matches + for (my $i = 0; $i <= $#{$promoters{$params[$PROMOTER]}[$INPUT]}; $i++) { + @aref = $promoters{$params[$PROMOTER]}[$INPUT][$i]; + if ($aref[0][2] eq $params[$ARROWHEAD] and $aref[0][1] eq "biochemical") { + $aref[0][0]{$params[$INPUT]} = $params[$STOC]; + $found = 1; + last; + } elsif ($aref[0][2] eq $params[$ARROWHEAD]){ + $aref[0][0]{$params[$INPUT]} = $params[$STOC]; + $found = 1; + last; + } + } + + if ($found == 0) { + my @input = [{$params[$INPUT]=>$params[$STOC]}, $params[$TYPE], $params[$ARROWHEAD]]; + push(@{$promoters{$params[$PROMOTER]}[1]}, @input); + } + $promoters{$params[$PROMOTER]}[$OUTPUT]{$params[$OUTPUT]}=$params[$OUTPUT]; + } +} + +#Removes all duplicate biochemical reactions +#Might not work if there's more than 1 reaction something can go to +#or if one reaction uses the same proteins as another +sub build_reactions { + #cycle through each promoter and check to see if there is a biochemical reaction + foreach $key (keys %promoters) { + for ($i = 0; $i <= $#{$promoters{$key}[$INPUT]}; $i++) { + my @temp = $promoters{$key}[$INPUT][$i]; + if ($temp[0][1] eq "biochemical") { + my @reactants; + foreach $t (keys %{@{$temp[0]}[0]}) {push(@reactants, $t);} + $complex = get_complex(@reactants); + if ($complex eq "") { + $complex = ""; + foreach $ref (@reactants) {$complex = "$complex\_$ref";} + $complex = "Complex$complex"; + push(@{$biochem{$complex}},@reactants); + + } + } + } + } +} + +sub get_num_act { + my $key = $_[0]; + my $num = 0; + for ($i = 0; $i <= $#{$promoters{$key}[$INPUT]}; $i++) { + my @temp = $promoters{$key}[$INPUT][$i]; + if ($temp[0][2] eq "vee") {$num++;} + } + return $num; +} + +sub get_num_rep { + my $key = $_[0]; + my $num = 0; + for ($i = 0; $i <= $#{$promoters{$key}[$INPUT]}; $i++) { + my @temp = $promoters{$key}[$INPUT][$i]; + if ($temp[0][2] eq "tee") {$num++;} + } + return $num; +} + +sub get_complex { + @params = @_; + print "Passed: @params\n"; + foreach $key (keys %biochem) { + my $all_found = 0; + foreach $ref (@params) { + $all_found = 1; + if (not ($key =~ m/$ref/)){ + print "Couldn't find $ref in $key\n"; + $all_found = 0; + last; + } + } + if ($all_found == 1) { + print "Found $key\n"; + return $key; + last; + } + } + print "Couldn't find @params\n"; + return ""; +} + +sub print_all_info { + print "State index: $STATE"; + print "Printing Protein Structure\n"; + foreach $key (keys %proteins) { + print "\nProteins{$key}: @{$proteins{$key}}\n"; + } + + print "Printing Promoter Structure\n"; + foreach $key (keys %promoters) { + print "\nPromoter{$key}:\n"; + for ($i = 0; $i <= $#{$promoters{$key}[$INPUT]}; $i++) { + my @temp = $promoters{$key}[$INPUT][$i]; + print "---------------\n\tInputs:\n"; + foreach $ref (keys %{$temp[0][0]}) {print "\t\t$ref,$temp[0][0]{$ref}\n";}; + print "\tType: $temp[0][1]\n"; + print "\tArrow: $temp[0][2]\n"; + } + print "---------------\n\tOutput:\n"; + foreach $ref (keys %{$promoters{$key}[$OUTPUT]}) { + print "\t\t$ref\n"; + } + } + + print "Printing Reactions\n"; + foreach $key (keys %biochem) { + print "\nReactions{$key}:\n"; + foreach $ref (@{$biochem{$key}}) { + print "\t$ref\n"; + } + } +} + +sub make_input{ + my @params = @_; + + my $binds = ""; + + if ($params[0][1] eq "biochemical") { + my @reactants; + foreach my $t (keys %{@{$params[0]}[0]}) {push(@reactants, $t);} +# print "LOOKING: @reactants\n"; + $binds = get_complex(@reactants); +# print "FOUND: $binds\n"; + } + else { + foreach my $ref (keys %{$params[0][0]}) { + my $stoc = $params[0][0]{$ref}; + if ($stoc > 1) { + $binds = "$ref\_$stoc,$binds"; + } else { + $binds = "$ref,$binds"; + } + } + } + return $binds; +} + +sub create_real_network{ +# print "Building Real Network\n------------------------------------\n"; + + print OUT "\n\n\n\n \n\n\n\n"; + + #Print the proteins in the network + foreach $key (keys %proteins){ + print OUT "\t\n"; + } + + #Print each dimer + foreach $key (keys %dimers) { + print OUT "\t\n"; + } + + if (!$opt_c) { + #Print each biochem reaction + foreach $key (keys %biochem) { + print OUT "\t\n"; + } + } + + #Print each promoter, bound promoter, unbound promoter + foreach my $key (keys %promoters){ + print OUT "\t\n"; + print OUT "\t\n"; + for ($i = 0; $i <= $#{$promoters{$key}[$INPUT]}; $i++) { + my @temp = $promoters{$key}[$INPUT][$i]; + my $binds = make_input(@temp); + my @protein = split (/,/,$binds); + foreach my $ref (@protein) { + if ($temp[0][2] eq "vee") { + print OUT "\t\n"; + } + elsif ($temp[0][2] eq "tee") { + print OUT "\t\n"; + } + } + } + } + + #print the rnap + print OUT "\t\n"; + #begin printing out reactions + print OUT "\n\n\n"; + + #setup the dedgadations + foreach $key (keys %proteins) { + if ($proteins{$key}[$PROTEIN] =~ m/spastic/){ + print OUT < + + + + + + k_deg + + + + + + +END + } + elsif ($proteins{$key}[$CONST] != 1) { + print OUT < + + + + + + + + k_deg + $proteins{$key}[$PROTEIN] + + + + + + + +END + } + } +# If dimers are allowed to degrade, then degrade them + if ($opt_d) { + foreach $key (keys %dimers) { + if ($proteins{$key} [$CONST] != 1) { + print OUT < + + + + + + + + k_deg + $proteins{$key}[1]\_$dimers{$key} + + + + + + + +END + } + } +} + +# #set up degradations for dimers +# foreach $key (keys %dimers) { +# print OUT < +# +# +# +# +# +# +# +# k_deg +# $proteins{$key}[1]\_$dimers{$key} +# +# +# +# +# +# +# +# +# END +# } +# +# #set up degradations for biochem reaction +# foreach $key (keys %biochem) { +# print OUT < +# +# +# +# +# +# +# +# k_deg +# $key +# +# +# +# +# +# +# +# +# END +# } + +#setup the dimers +foreach $key (keys %dimers){ +print OUT < + + + + + + + + + + + + + kf_d + + + $proteins{$key}[1] + 2 + + + + + kr + $proteins{$key}[1]\_$dimers{$key} + + + + + + + + + + +END +} + +#set up biochem reactions, if there is no +#abstraction +if (!$opt_c) { +foreach $key (keys %biochem){ +print OUT < + +END + foreach $ref (@{$biochem{$key}}) { + print OUT " \n"; + } +print OUT < + + + + + + + + + + kf_d +END +foreach $ref (@{$biochem{$key}}) { +print OUT <$ref +END +} +print OUT < + + + kr + $key + + + + + + + + + + +END +}} + +foreach $name (keys %spastics) { +print OUT < + + + + + + kf + + + + + + +END +} + +#cycle through each promoter and build each reaction +foreach $promoter (keys %promoters) { +#setup main gene generation pathways rnap binding and then ocr +print OUT < + + + + + + + + + + + + + + kf + $promoter + rnap + + + + kr + rnap_$promoter + + + + + + + + + + + + + + + + +END +foreach $output (keys %{$promoters{$promoter}[2]}) { +print OUT< +END +} + +#figure out how to handle a promoter that acts and reps +if (get_num_act($promoter) >= get_num_rep($promoter)) { + $my_ocr = $unactived_production; +} else { + $my_ocr = $ocr; +} + +print OUT< + + + + + koc + rnap_$promoter + + + + + + + +END + +#now set up any activated production or repression by cycling through the +#possible inputs + for ($i = 0; $i <= $#{$promoters{$promoter}[$INPUT]}; $i++) { + my @temp = $promoters{$promoter}[$INPUT][$i]; + #First, take care of repression + if ($temp[0][2] eq "tee") { + #Check for biochemical reaction + if ($temp[0][1] eq "biochemical") { + my @reactants; + foreach my $t (keys %{@{$temp[0]}[0]}) {push(@reactants, $t);} + $binds = get_complex(@reactants); +if (!$opt_c) { +print OUT< + + + + + + + + + + + + + + kf + $promoter + $binds + + + + kr + bound_$binds\_$promoter + + + + + + + + + +END +} else { +print OUT< + +END; +foreach my $t (@reactants) { +print OUT< +END; +} +print OUT< + + + + + + + + + + + KComplex + kf + $promoter +END; +foreach my $t (@reactants) { +print OUT<$t +END; +} +my $K = $kf_complex/$kr_complex; +print OUT< + + + kr + bound_$binds\_$promoter + + + + + + + + + + +END +} + } + else { +#Regular repression + foreach $binds (keys %{@{$temp[0]}[0]}) { + my $kf = $kf_rep; + my $kr = $kr_rep; + if ($temp[0][0]{$binds} > 1) { + $binds = "$binds\_$temp[0][0]{$binds}"; + $kf = $kf_bind_dimer; + $kr = $kr_bind_dimer; + } +print OUT< + + + + + + + + + + + + + + kf + $promoter + $binds + + + + kr + bound_$binds\_$promoter + + + + + + + + + +END + } + } + } + else { + #Take care of activation + #Check for biochemical reaction + if ($temp[0][1] eq "biochemical") { + my @reactants; + foreach my $t (keys %{@{$temp[0]}[0]}) {push(@reactants, $t);} + $binds = get_complex(@reactants); +if (!$opt_c) { +print OUT< + + + + + + + + + + + + + + + kf + $promoter + $binds + rnap + + + + kr + rnap_$binds\_a$promoter + + + + + + + + + + + + + + + + +END +foreach $output (keys %{$promoters{$promoter}[2]}) { +print OUT< +END +} +print OUT< + + + + + koc + rnap_$binds\_a$promoter + + + + + + + +END +} else { +print OUT< + +END +foreach my $t (@reactants) { +print OUT< +END +} +print OUT< + + + + + + + + + + + + KComplex + kf + $promoter +END +foreach my $t (@reactants) { +print OUT<$t +END +} +my $K = $kf_complex/$kr_complex; +print OUT<rnap + + + + kr + rnap_$binds\_a$promoter + + + + + + + + + + + + + + + + + +END +foreach $output (keys %{$promoters{$promoter}[2]}) { +print OUT< +END +} +print OUT< + + + + + koc + rnap_$binds\_a$promoter + + + + + + + +END +}} + else { + #Take care of activation, no biochemical +foreach my $binds (keys %{$temp[0][0]}) { +#check to make sure that it's not a dimer + my $kf = $kf_act; + my $kr = $kr_act; + if ($temp[0][0]{$binds} > 1) { + $binds = "$binds\_$temp[0][0]{$binds}"; + $kf = $kf_bind_dimer*$kf; + $kr = $kr_bind_dimer*$kr; + } +print OUT< + + + + + + + + + + + + + + + kf + $promoter + $binds + rnap + + + + kr + rnap_$binds\_a$promoter + + + + + + + + + + + + + + + + +END +foreach $output (keys %{$promoters{$promoter}[2]}) { +print OUT< +END +} +print OUT< + + + + + koc + rnap_$binds\_a$promoter + + + + + + + +END +}} + + + } + } +} + + +print OUT < + + +END +} + + + +main(); \ No newline at end of file diff --git a/bin/genBackgroundGCM.pl b/bin/genBackgroundGCM.pl new file mode 100755 index 000000000..9a9b2f1fe --- /dev/null +++ b/bin/genBackgroundGCM.pl @@ -0,0 +1,41 @@ +#!/usr/bin/perl +#******************************************************************************* +# +# This file is part of iBioSim. Please visit +# for the latest version of iBioSim. +# +# Copyright (C) 2017 University of Utah +# +# This library is free software; you can redistribute it and/or modify it +# under the terms of the Apache License. A copy of the license agreement is provided +# in the file named "LICENSE.txt" included with this software distribution +# and also available online at . +# +#******************************************************************************* + +open (IN, "run-1.tsd"); +@in = ; +close IN; + +open (OUT, ">background.gcm"); +$in = join("",@in); +@in = split (/\),\(/,$in); +$in = $in[0]; +$in =~ s/^(.*?)\),\(/$1/; +$in =~ s/\"//g; +$in =~ s/\(|\)//g; + +print "got '$in'\n"; + +@in = split (/,/,$in); + + + +print OUT "diagraph G {\n"; + +for ($i = 1; $i <= $#in; $i++){ + my $a = $in[$i]; + print OUT "$a [ID=$a,Name=\"$a\",Type=normal,shape=ellipse,label=\"$a\"]\n"; + +} +print OUT "}\nGlobal {\n}\nPromoters {\n}\nSBML file=\"\"\n" diff --git a/bin/gen_GeneNet_report.pl b/bin/gen_GeneNet_report.pl new file mode 100755 index 000000000..a77c56954 --- /dev/null +++ b/bin/gen_GeneNet_report.pl @@ -0,0 +1,339 @@ +#!/usr/bin/perl +#******************************************************************************* +# +# This file is part of iBioSim. Please visit +# for the latest version of iBioSim. +# +# Copyright (C) 2017 University of Utah +# +# This library is free software; you can redistribute it and/or modify it +# under the terms of the Apache License. A copy of the license agreement is provided +# in the file named "LICENSE.txt" included with this software distribution +# and also available online at . +# +#******************************************************************************* + + +$genenet_dir = $ARGV[0]; +$reports_dir = $ARGV[1]; +$file_name_to_use = $ARGV[2]; +$out_name = $ARGV[3]; + +#remove the last / in dir +$reports_dir =~ s/\/$//; + + +sub main{ + my @files = `ls $genenet_dir*/*/*/$file_name_to_use`; + + print "Sorting dir\n"; + @files = dir_sort(\@files); + print "Done sorting dir\n"; + if ($#files < 1){ + print "Error, no files found\n"; + exit(1); + } + + open (OUT, ">$reports_dir/$out_name") or die "Cannot open out file '$reports_dir/$out_name'\n"; + print OUT ",,,,,GeneNet,,GeneNet,,,GeneNet Time,,,,,,,\n"; + #print OUT "Name,# Genes,# Experiments,Sample Interval,Exp Duration,R,P,R,P,R/R,P/P, # Correct (R P), Total Arcs (R), Reported Arcs (P), # Correct (R P), Total Arcs (R), Reported Arcs (P),\n"; + print OUT "Name,Genes,#Exp,S Size,Dur,R,P,# Correct (R P), Total Arcs (R), Reported Arcs (P),user,system,elapsed,CPU,major pagefaults,minor pagefaults, swaps\n"; + + my $exp_name = $files[0]; + my @running_genenet; + + for (my $i = 0; $i <= $#files; $i++){ + $file = $files[$i]; + $file =~ s/[.]dot//; + $file =~ s/\n//; + print "Checking $file\n"; + if (not_matching($file,$exp_name)){ + add_overview($exp_name); + $exp_name = $file; + + print OUT ",,,,"; + write_final(@running_genenet); + print OUT "\n"; + undef @running_genenet; + } + + + @tmp1 = check_correctness("$file"); + @running_genenet = addit(\@running_genenet,\@tmp1); + write_out_file($file); + write_initial(@tmp1); + if ($tmp1[0] != $tmp1[2]){ + print OUT ",ERROR: $tmp1[0] $tmp1[2],$tmp1[1],$tmp1[3]"; + } + else{ + print OUT ",$tmp1[0],$tmp1[1],$tmp1[3]"; + } + write_time(); + print OUT "\n"; + #print "Done with $file\n"; + + } + + print "Adding overview\n"; + add_overview($file); + + print OUT ",,,,"; + write_final(@running_genenet); + print OUT "\n\n"; + print OUT "Overview:\n$overview\n\n"; +} + +sub add_overview{ + my $exp_name = shift; + if ($exp_name =~ m/^.*\/([^\/]*)_[0-9]+\/[^\/]*_([0-9]+)_([0-9]+)_([0-9]+)_([0-9]+)\//){ + $overview = "$overview$1,$3,$4,$5,$6"; + } + else{ + $exp_name =~ s/.*?\/(.*?)\/.*/$1/; + $exp_name =~ s/[.]*//; + $overview = "$overview$exp_name,,,,"; + } + +} + + + +sub not_matching{ + my $a = shift; + my $b = shift; + if ($a =~ m/^(.*)_([0-9]+)\/[^\/]*_([0-9]+)_([0-9]+)_([0-9]+)_([0-9]+)\//){ + my @a = ($1,$2, $3, $4, $5,$6); + if ($b =~ m/^(.*)_([0-9]+)\/[^\/]*_([0-9]+)_([0-9]+)_([0-9]+)_([0-9]+)\//){ + my @b = ($1,$2, $3, $4, $5, $6); + if ($a[0] eq $b[0]){ + my @cmp = (5,4,3); + for (my $i = 0; $i <= $#cmp; $i++){ + my $ind = $cmp[$i]; + if (not ($a[$ind] == $b[$ind])){ + return 1; + } + } + return 0; + } + } + } + return 1; +} + +sub addit{ + $a1 = shift; + $a2 = shift; + @a1 = @$a1; + @a2 = @$a2; + for (my $i = 0; $i <= $#a2; $i++){ + $a1[$i] += $a2[$i]; + } + return @a1; +} + +sub write_out_file{ + my $file = shift; + if ($file =~ m/^.*\/(.*_[0-9]+)\/[^\/]*_([0-9]+)_([0-9]+)_([0-9]+)_([0-9]+)\//){ + my $name = $1; + my $num_genes = $2; + my $experiments = $3; + my $interval = $4; + my $ending_time = $5; + print OUT "$name,$num_genes,$experiments,$interval,$ending_time"; + } + else{ + #print "Error matching $file\n"; + $file =~ s/.*?\/(.*?)\/.*/$1/; + print OUT "$file,,,,"; + } +} + +sub write_final{ + my $a0 = shift; + my $a1 = shift; + my $a2 = shift; + my $a3 = shift; + $tmp_name = write_double($a0,$a1); + print OUT $tmp_name; + $overview = "$overview$tmp_name"; + + $tmp_name = write_double($a2,$a3); + print OUT $tmp_name; + $overview = "$overview$tmp_name\n"; + print OUT "\n"; +} + +sub write_initial{ + my $a0 = shift; + my $a1 = shift; + my $a2 = shift; + my $a3 = shift; + + print OUT write_double($a0,$a1); + print OUT write_double($a2,$a3); +} + +sub write_double{ + my $a = shift; + my $b = shift; + if ($b != 0){ + return ",=$a/$b"; + } + else { + return ",u $a/$b"; + } +} + +sub write_time{ +#0.51user 0.00system 0:00.52elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k +#0inputs+0outputs (0major+853minor)pagefaults 0swaps + my $f = "$file"; + my $tmp = $file_name_to_use; + $tmp =~ s/(.*)[.].*/$1\_time.txt/; + $f =~ s/(.*)\/.*/$1\/$tmp/; + if (-e "$f"){ + open (A, "$f") or die "Cannot open time file $f\n"; + my @a = ; + close A; + + my $a = join ("",@a); + $a =~ s/\n//g; + if ($a =~ m/([0-9]+[.]*[0-9]*)user ([0-9]+[.]*[0-9]*)system ([0-9]+[:][0-9]+[.:]*[0-9]*)elapsed ([0-9]+[.]*[0-9]*).CPU .0avgtext.0avgdata 0maxresident.k0inputs.0outputs .([0-9]+)major.([0-9]+)minor.pagefaults ([0-9]+)swaps/){ + my $out = ",$1,$2,$3,$4,$5,$6,$7"; + print OUT $out; + } + else{ + print "Unable to match\n'$a'\n"; + exit(1); + } + + } + else{ + print "ERROR: Cannot find time file '$f'\n"; + exit(1); + } + +} + +sub check_correctness{ + my $filename = shift; + $filename = "$filename.dot"; + + if (not -e "$filename"){ + print "ERROR: unable to check correctness for non exsistant? file '$filename'\n"; + exit(1); + } + open (IN, "$filename") or die "I cannot check correctness for $filename\n"; + + my @in = ; + close IN; + + my $in = join ("",@in); + + $in =~ s/sp_//g; + + my $not_found_arcs = 0; + my $correct_arcs = 0; + my $wrong_influence_arcs = 0; + my $extra_arcs = 0; + + while ($in =~ m/s([0-9]+) -> s([0-9]+) (.*)/g){ + my $left = $3; + #print "Matched with '$left'\n"; + if ($left =~ m/black/){ #should not have been reported + $extra_arcs++; + #$precision_total++; + } + elsif ($left =~ m/dotted/){ #It is there, but not found + $not_found_arcs++; + #$recall_total++; + } + elsif ($left =~ m/dashed/){ #wrong influence type + print "Extra arcs"; + $wrong_influence_arcs++; + #$precision_total++; + #$recall_total++; + } + else{ #there and reported + $correct_arcs++; + #$precision_correct++; + #$precision_total++; + #$recall_correct++; + #$recall_total++; + } + } + + my $num_genes = 0; + while ($in =~ m/s[0-9]+ \[/g){ + $num_genes++; + } + my $total_possible_arcs = $num_genes * ($num_genes-1); + my $total_influence_arcs = $not_found_arcs + $wrong_influence_arcs + $correct_arcs; + my $total_absent_arcs = $total_possible_arcs - $total_influence_arcs; + my $correct_absent_arcs = $total_absent_arcs - $extra_arcs; + + + my $r_c = $correct_arcs; + my $r_t = $total_influence_arcs; + my $p_c = $correct_arcs; + my $p_t = $correct_arcs + $wrong_influence_arcs + $extra_arcs; + return ($r_c,$r_t,$p_c,$p_t); + +} + +sub dir_sort_b{ + my $a = shift; + my $b = shift; + if ($a =~ m/(.*?)_([0-9]+)_/){ + my $n1 = $1; + my $i1 = $2; + if ($b =~ m/(.*?)_([0-9]+)_/){ + my $n2 = $1; + my $i2 = $2; + if ($n1 eq $n2 and $1 != $i2){ + return $i1 <=> $i2; + } + } + } + return $a cmp $b; +} + +sub dir_sort_a{ + #order is 0 5 4 3 1 - 2 is the # genes which should match + # cmp = = = = + my $a = shift; + my $b = shift; + + if ($a =~ m/^(.*)_([0-9]+)\/[^\/]*_([0-9]+)_([0-9]+)_([0-9]+)_([0-9]+)\//){ + my @a = ($1,$2, $3, $4, $5,$6); + if ($b =~ m/^(.*)_([0-9]+)\/[^\/]*_([0-9]+)_([0-9]+)_([0-9]+)_([0-9]+)\//){ + my @b = ($1,$2, $3, $4, $5, $6); + if ($a[0] eq $b[0]){ + my @cmp = (5,4,3,1); + for (my $i = 0; $i <= $#cmp; $i++){ + my $ind = $cmp[$i]; + if (not ($a[$ind] == $b[$ind])){ + return $a[$ind] <=> $b[$ind]; + } + } + return $a[2] <=> $b[2]; + } + else{ + return $a[0] cmp $b[0]; + } + } + } + return dir_sort_b($a,$b); +} + +sub dir_sort{ + my $d = shift; + my @d = @$d; + @d = sort {dir_sort_a($a,$b)} (@d); + return @d; +} + + + +main(); + diff --git a/bin/iBioSim b/bin/iBioSim new file mode 100755 index 000000000..e053a0957 --- /dev/null +++ b/bin/iBioSim @@ -0,0 +1,12 @@ +#!/bin/sh +# +# run-time wrapper for BioSim gui +export DYLD_LIBRARY_PATH=$BIOSIM/lib64:$DYLD_LIBRARY_PATH +CLASSPATH=$BIOSIM/gui/dist/classes:$BIOSIM/gui + +for jarFile in $BIOSIM/gui/lib/*.jar +do + CLASSPATH=$CLASSPATH:$jarFile +done + +exec java -Xmx2048M -Xms2048M -XX:+UseSerialGC -classpath $CLASSPATH -Dapple.laf.useScreenMenuBar=true -Xdock:name="iBioSim" -Xdock:icon=$BIOSIM/gui/icons/iBioSim.jpg main.Gui diff --git a/bin/iBioSim.jar b/bin/iBioSim.jar new file mode 100644 index 000000000..4d20aaaf2 Binary files /dev/null and b/bin/iBioSim.jar differ diff --git a/bin/reb2sac b/bin/reb2sac new file mode 100755 index 000000000..4397160b2 Binary files /dev/null and b/bin/reb2sac differ diff --git a/bin/reb2sac.mac64 b/bin/reb2sac.mac64 new file mode 100755 index 000000000..4397160b2 Binary files /dev/null and b/bin/reb2sac.mac64 differ