[Bio] / FigKernelPackages / FIGMODELweb.pm Repository:
ViewVC logotype

View of /FigKernelPackages/FIGMODELweb.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (download) (as text) (annotate)
Mon Aug 30 02:42:06 2010 UTC (9 years, 3 months ago) by chenry
Branch: MAIN
CVS Tags: rast_rel_2010_0928, rast_rel_2010_1206
Changes since 1.14: +93 -57 lines
Adding code to support model curation via upload.

package FIGMODELweb;
use strict;

use FIG_Config;

use WebComponent::WebGD;
use WebColors;

=head1

=head2 Introduction
Module for generating of the model-associated webpages

=head2 Core Object Methods

=head3 new
Definition:
	FIGMODELweb = FIGMODELweb->new();
Description:
	This is the constructor for the FIGMODELweb object.
=cut

sub new {
	my ($class,$figmodel) = @_;
	my $self;
	$self->{"_figmodel"}->[0] = $figmodel;
	bless $self;

	return $self;
}

=head3 figmodel
Definition:
	FIGMODEL = FIGMODELweb->figmodel();
Description:
	Returns a FIGMODEL object
=cut
sub figmodel {
	my ($self) = @_;
	return $self->{"_figmodel"}->[0];
}

=head3 config
Definition:
	ref::key value = FIGMODELweb->config(string::key);
Description:
	Trying to avoid using calls that assume configuration data is stored in a particular manner.
	Call this function to get file paths etc.
=cut
sub config {
	my ($self,$key) = @_;
	return $self->figmodel()->config($key);
}

=head3 get_model_overview_tbl()
Definition:
	string = FIGMODELweb->get_model_overview_tbl();
Description:
=cut
sub get_model_overview_tbl {
	my ($self,$model_ids,$mgrast) = @_;
    my $colors = WebColors::get_palette( 'varied' );
    my $download_link = "http://bioseed.mcs.anl.gov/~chenry/SBMLModels/";
    #Getting the user name
    my $username = "";
    my $userid = "NONE";
    if ($self->figmodel()->user() ne "PUBLIC") {
		$userid = $self->figmodel()->user();
		$username = "&username=".$self->figmodel()->user();
    }
	#Getting all models and determining if the upload column should appear
	my $uploadColumn = 0;
    my $rows = '';
    my $modelList;
    for (my $i=0; $i < @$model_ids; $i++) {
        my $model = $self->figmodel()->get_model($model_ids->[$i]);
		if (defined($model)) {
			push(@{$modelList},$model);
			if ($model->owner() eq $userid) {
				$uploadColumn = 1;
			}
		}
    }
    if (!defined($modelList)) {
    	return "";
    }
    #Creating the header for the overview table
    my $header = "<tr><th style='width: 100px;'>Model ID</th>";
	if (defined($mgrast) && $mgrast == 1) {
		$header .= "<th style='width: 150px;'>Metagenome/organism</th>";
	} else {
		$header .= "<th style='width: 150px;'>Organism</th>";
	}
	$header .= "<th style='width: 80px;' >Version</th><th style='width: 80px;' >Source</th>";
	if (!defined($mgrast) || $mgrast != 1) {
		$header .= "<th style='width: 80px;'>Class</th>";
	}
	$header .= "<th style='width: 80px;' >Genome size</th><th style='width: 80px;' >Model genes</th><th style='width: 80px;' >Reactions with genes </th><th style='width: 80px;' >Gapfilling Reactions</th>".
	"<th style='width: 80px;' >Gapfilling Media</th><th style='width: 80px;' >Compounds</th><th style='width: 80px;' >Download</th>";
	if ($uploadColumn == 1) {
		$header .= "<th style='width: 80px;' >Upload</th>";
	}
    if( @$modelList > 1 ) {
        $header .= "<td style='width: 80px; padding-top:5px'><small>(<a href=\"javascript:removeAllModels();\">clear all</a>)</small></td></tr>";
    } else {
        $header .= "<td style='width: 80px; padding-top:5px'></td></tr>";
    }
    #Filling in the rows of the model overview table
    for (my $i=0; $i < @$modelList; $i++) {
	    #Loading summary data for the models
	    my $model = $modelList->[$i];
	    my $total_genes = $model->genome_genes();
	    my $genes_with_rxn = $model->model_genes();
	    my $total_rxn = $model->total_reactions();
	    my $gapfilling = $model->gapfilling_reactions();
	    my $rxn_with_genes = $model->gene_reactions();
	    my $cpds = $model->total_compounds();
	    my $size = $model->genome_size();
	    my $gapfillingmedia = "Complete";
	    my $mediacompounds = "All transportable nutrients available";
	    my $media_row = $self->figmodel()->database()->GetDBTable("MINIMAL MEDIA TABLE")->get_row_by_key($model->genome(),"Organism");
	    if (defined($media_row)) {
			$gapfillingmedia = $media_row->{"Minimal media"}->[0];
			$mediacompounds = "Unknown";
			my $mediarow = $self->figmodel()->database()->get_media($gapfillingmedia);
			if (defined($mediarow)) {
			    $mediacompounds = join(", ",@{$mediarow->{NAMES}});
			}
	    }
	    
	    #Adding commas to the large numbers to make them more readable
	    while($genes_with_rxn =~ s/(\d+)(\d{3})+/$1,$2/){};
	    while($total_genes =~ s/(\d+)(\d{3})+/$1,$2/){};
	    while($rxn_with_genes =~ s/(\d+)(\d{3})+/$1,$2/){};
	    while($total_rxn =~ s/(\d+)(\d{3})+/$1,$2/){};
	    while($cpds =~ s/(\d+)(\d{3})+/$1,$2/){};
	    while($size =~ s/(\d+)(\d{3})+/$1,$2/){};
	    
	    # Generate a color key for the rest of the page
	    my $box = new WebGD( 12, 12 );
	    $box->colorResolve( @{$colors->[$i]} );

	    #Adding data column to the overview table
	    my $row = "<tr><td><img src='".$box->image_src()."'>&nbsp;".$model->id()."</td>" .
		"<td> ".$model->name()."<br>(<a href=?page=Organism&organism=".$model->genome()." target=\"_blank\">".$model->genome()."</a>)</td><td>".$model->version()."</td>" .
		(($model->source() =~ m/PMID(\d+)/) ? ("<td><a href=http://www.ncbi.nlm.nih.gov/pubmed/".$1.">".$model->source()."</a></td>") : ("<td>".$model->source()."</td>"));
		if (!defined($mgrast) || $mgrast != 1) {
			$row .= "<td>".$model->class()."</td>";
		}
		$row .= "<td>".substr($size,0,length($size)-4)." KB</td><td title='Model genes/Total genes'>" . $genes_with_rxn. "<br>/".$total_genes. "</td>" .
		"<td title='Reactions with genes/Total reactions'>" .  $rxn_with_genes ."<br>/".$total_rxn . "</td><td title='Gap filling reactions/Total reactions'>" . $gapfilling ."/".$total_rxn. "</td>" .
		"<td title='".$mediacompounds."'>".$gapfillingmedia."</td><td>" .$cpds . "</td><td><small>".$self->create_model_download_link($model->id())."</small></td>";
		if ($uploadColumn == 1) {
			$row .= "<td>".$self->create_model_upload_link($model->id())."</td>";
		}
		$row .= "<td style='padding-top:5px;'><small>(<a href='javascript:removeModelParam(\"".$model->id()."\")'>remove</a>)</small></td></tr>";
	    $rows .= $row;
    }
    #Returning the completed table
    my $model_overview = "<div><table>" . $header . $rows . "</table></div>";
    return $model_overview;
}

sub reaction_table_model_column {
	my ($self,$modelid,$rxnid) = @_;

	#Loading or retrieving the model object
	my $model = $self->figmodel()->get_model($modelid);
	if (!defined($model)) {
		return $modelid." MODEL NOT FOUND";
	}

	#Getting the reaction row
	my $rxn = $model->get_reaction_data($rxnid);
	if (!defined($rxn)) {
		return "Not in model";
	}

	#Getting the reaction class
	my $output;
	my $rxnclass = $model->get_reaction_class($rxnid);
	if (defined($rxnclass)) {
		$output = $rxnclass."<br>";
	}

	#Handling genes
    if (!defined($rxn->{"ASSOCIATED PEG"})) {
		$output .= "UNKNOWN";
		return $output;
	}

	#Handling MGRAST models
	if ($model->source() =~ m/^MGRAST/ && defined($rxn->{REFERENCE}) && defined($rxn->{CONFIDENCE})) {
		my $RoleHash;
		for (my $m=0;$m < @{$rxn->{REFERENCE}}; $m++) {
		  my @Pair = split(/:/,$rxn->{REFERENCE}->[$m]);
		  my @Escores = split(/,/,$rxn->{CONFIDENCE}->[$m]);
		  if (!defined($RoleHash->{$Pair[1]}->{fragments})) {
			$RoleHash->{$Pair[1]}->{fragments} = 0;
			$RoleHash->{$Pair[1]}->{gene} = $rxn->{"ASSOCIATED PEG"}->[$m];
			$RoleHash->{$Pair[1]}->{escore} = $Escores[0];
			if ($Escores[0] =~ m/^(\d+)\.\d+e(\-\d+)/) {
			  $RoleHash->{$Pair[1]}->{escore} = $2;
			  $RoleHash->{$Pair[1]}->{coeff} = $1;
			}
		  }
		  for (my $j=0; $j < @Escores; $j++) {
			if ($Escores[$j] =~ m/^(\d+)\.\d+e(\-\d+)/) {
			  if ($2 < $RoleHash->{$Pair[1]}->{escore}) {
				$RoleHash->{$Pair[1]}->{escore} = $2;
				$RoleHash->{$Pair[1]}->{coeff} = $1;
			  }
			}
		  }
		  $RoleHash->{$Pair[1]}->{fragments} += @Escores;
		}
		my @Roles = keys(%{$RoleHash});
		for (my $j=0; $j < @Roles; $j++) {
		  if ($j > 0) {
			$output .= "<br>";
		  }
		  my $Score = $RoleHash->{$Roles[$j]}->{coeff}."e".$RoleHash->{$Roles[$j]}->{escore};
		  $output .= '<a href="http://www.theseed.org/linkin.cgi?id=fig|'.$RoleHash->{$Roles[$j]}->{gene}.'" title="'.$Roles[$j].'" target="_blank">'.$RoleHash->{$Roles[$j]}->{fragments}." fragments:".$Score."</a>";
		}
		return $output;
	}

	#Handling normal genomes
	if ($model->source() !~ m/^MGRAST/) {
		if ($rxn->{"ASSOCIATED PEG"}->[0] !~ m/\d/ && $rxn->{"ASSOCIATED PEG"}->[0] !~ m/SPONT/) {
			$rxn->{"ASSOCIATED PEG"}->[0] = "Gap filling:".$rxn->{"ASSOCIATED PEG"}->[0];
		}
		my $PegString = join("|",@{$rxn->{"ASSOCIATED PEG"}});
		$PegString =~ s/\+/|/g;
		#$PegString =~ s/\s//g;
		$PegString =~ s/,/|/g;
		my @PegList = split(/\|/,$PegString);
		my $PegHash;
		for (my $n=0; $n < @PegList; $n++) {
		  $PegHash->{$PegList[$n]} = 1;
		}
		$PegString = join(", <br>",keys(%{$PegHash}));
		$output .= $self->figmodel()->ParseForLinks($PegString,$modelid);
		$output =~ s/\(\s/(/g;
		$output =~ s/\s\)/)/g;
		return $output;
	}
}

=head3 ModelSelectTable()
Definition:
	[[string]]::table data = FIGMODELweb->ModelSelectTable([string]::columns,string::user id);
Description:
	Returns a two dimensional array with the contents for a model select table with the input columns and the specified user ID
=cut
sub ModelSelectTable {
	my ($self,$columns,$userid) = @_;

	#If the user ID is not defined, we assume it is master
	my $modelList;
	if (!defined($userid)) {
		$modelList = $self->figmodel()->get_user_models("master");
	} else {
		for (my $i=0; $i < @{$userid}; $i++) {
			my $templist = $self->figmodel()->get_user_models($userid->[$i]);
			if (defined($templist)) {
				push(@{$modelList},@{$templist});
			}
		}
	}

	#Getting the table row associated with each user model
	my $allrows;
	if (defined($modelList)) {
		for (my $i=0; $i < @{$modelList}; $i++) {
			if ($modelList->[$i]->source() !~ /MGRAST/) {
				push(@{$allrows},$self->ModelSelectTableRow($columns,$modelList->[$i]));
			}
		}
	}
	return $allrows;
}

=head3 ModelSelectTableRow()
Definition:
	[string]::table row = FIGMODELweb->ModelSelectTableRow([string]::columns,FIGMODELmodel::model);
Description:
	Returns the one dimensional row for the model select table for the input model object
=cut
sub ModelSelectTableRow {
	my ($self,$columns,$model) = @_;

	my $output;
	for (my $i=0; $i < @{$columns}; $i++) {
		$output->[$i] = "";
		if ($columns->[$i] eq "id") {
			$output->[$i] = $self->create_model_id_link($model->id());
		} elsif ($columns->[$i] eq "genome") {
			$output->[$i] = $self->create_genome_link($model->genome());
		} elsif ($columns->[$i] eq "message") {
			$output->[$i] = $model->message();
		} elsif ($columns->[$i] eq "sbml") {
			$output->[$i] = $self->create_sbml_link($model);
		} elsif ($columns->[$i] eq "version") {
			$output->[$i] = $model->version();
		} elsif ($columns->[$i] eq "moddata") {
			$output->[$i] = $self->figmodel()->date($model->modification_time());
		} elsif ($columns->[$i] eq "name") {
			$output->[$i] = $model->name();
		} elsif ($columns->[$i] eq "class") {
			$output->[$i] = $model->class();
		} elsif ($columns->[$i] eq "genes") {
			$output->[$i] = $model->model_genes()."/".$self->figmodel()->get_genome_stats($model->genome())->{"TOTAL GENES"}->[0];
		} elsif ($columns->[$i] eq "reactions") {
			$output->[$i] = $model->total_reactions();
		} elsif ($columns->[$i] eq "gapfilling") {
			$output->[$i] = $model->gapfilling_reactions();
		} elsif ($columns->[$i] eq "compounds") {
			$output->[$i] = $model->total_compounds();
		} elsif ($columns->[$i] eq "source") {
			if ($model->source() =~ m/PMID\d\d\d\d\d\d\d\d/) {
				$output->[$i] = '<a style="text-decoration:none" href="http://www.ncbi.nlm.nih.gov/pubmed/'.substr($model->source(),4).'" target="_blank">'.$model->source()."</a>";
			} else {
				$output->[$i] = $model->source();
			}
		}

	}
	return $output;
}

=head3 media_table
Definition:
	[[string]]::table columns and rows = FIGMODELweb->media_table([string]::columns,string::user id);
Description:
	Returns a two dimensional array of the data that should be displayed in the media table columns and rows
=cut
sub media_table {
	my ($self,$columns,$tabletype) = @_;

	#First use the table type to determine what media formulations should appear in the table
	my $medialist;
	if ($tabletype eq "ALL") {
		push(@{$medialist},{NAME => ["Complete"], NAMES => ["All compounds"],COMPOUNDS => ["All compounds"]});
		for (my $i=0; $i < $self->figmodel()->database()->get_media_number(); $i++) {
			push(@{$medialist},$self->figmodel()->database()->get_media($i));
		}
	}

	#Now creating the table matrix
	my $rows;
	for (my $j=0; $j < @{$medialist}; $j++) {
		my $output;
		my $media = $medialist->[$j];
		for (my $i=0; $i < @{$columns}; $i++) {
			$output->[$i] = "";
			if ($columns->[$i] eq "id") {
				$output->[$i] = $media->{NAME}->[0];
			} elsif ($columns->[$i] eq "cpdname") {
				if (defined($media->{NAMES})) {
					$output->[$i] = join(", ",$self->create_compound_link(@{$media->{NAMES}}));
				}
			} elsif ($columns->[$i] eq "cpdid") {
				if (defined($media->{COMPOUNDS})) {
					$output->[$i] = join(", ",$self->create_compound_link(@{$media->{COMPOUNDS}}));
				}
			} elsif ($columns->[$i] eq "acselect") {
				$output->[$i] = '<input type="button" value="Select" onClick="select_ac_media('.$media.');">';
			}
		}
		push(@{$rows},$output);
	}

	return $rows;
}

=head3 create_model_upload_link
Definition:
	string:link = FIGMODELweb->create_model_upload_link(string:model id);
=cut
sub create_model_upload_link {
	my ($self,$id) = @_;
	if ($self->figmodel()->get_model($id)->owner() eq $self->figmodel()->user()) {
		return "<a href=?page=ModelEdit&m=".$id.">Upload curated model file</a>";
	} else {
		return "No curation permissions";	
	}
}

=head3 create_compound_link
Definition:
	(string)::array of links = FIGMODELweb->create_compound_link((string)::list of compounds);
Description:
	Returns an html encoded list of compound links
=cut
sub create_compound_link {
	my ($self,@Compounds) = @_;

	my @Output;
	for (my $i=0; $i < @Compounds; $i++) {
		push(@Output,'<a href="?page=CompoundViewer&compound='.$Compounds[$i].'">'.$Compounds[$i]."</a>");
	}

	return @Output;
}

=head3 create_kegg_link
Definition:
	(string)::array of links = FIGMODELweb->create_kegg_link((string)::list of compounds);
Description:
	Returns an html encoded list of compound link
=cut
sub create_kegg_link {
	my ($self,$compounds) = @_;

	return '<a href="http://www.genome.jp/dbget-bin/www_bget?cpd:'.$compounds.'" target="_blank">'.$compounds."</a>";
}

=head3 print_compound_kegg_maps
Definition:
	string::map link = FIGMODELweb->print_compound_kegg_maps(string::compound ID);
Description:
	Returns an html encoded list of compound map link
=cut
sub print_compound_kegg_maps {
	my ($self,$id,@args) = @_;
	my $modelString = "";
	if (@args > 0 ** $args[0] ne "NONE") {
		$modelString = "&model=".join(",",@args);
	}
	my $tbl = $self->figmodel()->database()->GetDBTable("Map data");
	my @rows = $tbl->get_row_by_key($id,"COMPOUNDS");
	my $output = "";
	for (my $i=0; $i < @rows;$i++) {
		if ($i > 0) {
			$output .= "<br>";
		}
		$output .= "<a title=\"".$rows[$i]->{NAME}->[0]."\" href=\"javascript:execute_ajax('build_map','modelmap_target','pathway=".$rows[$i]->{ID}->[0].$modelString."', 'Loading KEGG pathway ".$rows[$i]->{ID}->[0]."...', 0, 'post_hook', 'ModelMap|viewmap');\">".$rows[$i]->{ID}->[0]."</a>"; 
	}
	return $output;
}

=head3 create_reaction_link
Definition:
	string:link = FIGMODELweb->create_reaction_link(string:reaction ID,string:tooltip);
Description:
	Returns the link for the input reaction ID
=cut
sub create_reaction_link {
	my ($self,$reaction,$tooltip,$models) = @_;
	if (!defined($tooltip)) {
		$tooltip = "";
	}
	return '<a style="text-decoration:none" href="seedviewer.cgi?page=ReactionViewer&model='.$models.'&reaction='.$reaction.'" title="'.$tooltip.'" target="_blank">'.$reaction."</a>";
}

=head3 create_feature_link
Definition:
	string:link = FIGMODELweb->create_feature_link(string:feature ID);
Description:
	Returns an html encoded link to the feature
=cut
sub create_feature_link {
	my ($self,$feature) = @_;
	my $genome;
	my $id = $feature->{ID}->[0];
	if ($feature->{ID}->[0] =~ m/fig\|(\d+\.\d+)\.(\D+\.\d+)/) {
		$genome = $1;
		$id = $2;
	}
	if ($feature->{SOURCE}->[0] ne "SEED") {
		return '<a href="http://rast.nmpdr.org/seedviewer.cgi?page=Annotation&feature='.$feature->{ID}->[0].'" title="'.join("<br>",@{$feature->{ROLES}}).'" target="_blank">'.$id."</a>";
	}
	return '<a href="http://www.theseed.org/linkin.cgi?id='.$feature->{ID}->[0].'" title="'.join("<br>",@{$feature->{ROLES}}).'" target="_blank">'.$id."</a>";
}

=head3 create_sbml_link
Definition:
	string::link to SBML file = FIGMODELweb->create_sbml_link(FIGMODELmodel::model);
Description:
	Returns a string with the link to the SBML file for the input model object
=cut
sub create_sbml_link {
	my ($self,$id,$type,$title,$name) = @_;
	if (!defined($type)) {
		$type = "SBML";
	}
	if (!defined($title)) {
		$title = "This is the SBML file for the model, useful for running the model in the COBRA toolkit.";
	}
	if (!defined($name)) {
		$name = "SBML format";
	}
	my $model = $self->figmodel()->get_model($id);
	my $username = "";
	if ($self->figmodel()->user() ne "PUBLIC") {
		$username = "&username=".$self->figmodel()->user();
	}
	my $Link = '<a  href="ModelSEEDdownload.cgi?model='.$model->id().'&file='.$type.$username.'" target="_blank" title="'.$title.'">'.$name.'</a>';
	return $Link;
}

=head3 create_model_download_link
Definition:
	string::links to downloadable files = FIGMODELweb->create_model_download_link(string::model ID);
Description:
	Returns a string with the link to the downloadable files for the input model object
=cut
sub create_model_download_link {
	my ($self,$id) = @_;
	my $downloadLinks = "<small>".$self->create_sbml_link($id,"SBML")."<br>";
	$downloadLinks .= $self->create_sbml_link($id,"DB","This is the file used in the Model SEED to completely define each model. Eventually you can download this file, modify it, and upload it to curate your personal models.","Model SEED format")."<br>";
	$downloadLinks .= $self->create_sbml_link($id,"LP","This file can be used directly with any linear optimization software (e.g. GLPK-gnu linear programming kit) to run flux balance analysis on the models.","LP format")."<br></small>";
	return $downloadLinks;
}

=head3 create_genome_link
Definition:
	string::html for link to genome = FIGMODELweb->create_genome_link(string:genome ID);
Description:
	Given a genome ID, this function returns a link to the genome page and includes the genome name
	Used by the GeneTable component.
=cut
sub create_genome_link {
	my ($self,$genome) = @_;
	return '<a style="text-decoration:none" href="?page=Organism&organism='.$genome.'" title="'.$self->figmodel()->get_genome_name($genome).'" target="_blank">'.$genome."</a>";
}

=head3 create_model_id_link
Definition:
	string::link to model viewer = FIGMODELweb->create_model_id_link(string::id);
Description:
	Returns a string with the link to the genome page
=cut
sub create_model_id_link {
	my ($self,$id) = @_;

	return '<a href="javascript:select_model('."'".$id."'".');">'.$id.'</a>';
}

=head3 joboutput
Definition:
	string::links to job output = FIGMODELweb->joboutput(object:job object);
Description:
	Given a job object, this function returns links to the job output and error files.
	Used by the QueueManager webpage.
=cut
sub joboutput {
	my ($self,$object) = @_;
	
	my $output = "";
	if (-e "/vol/model-prod/FIGdisk/log/QSubOutput/ModelDriver.sh.o".$object->PROCESSID()) {
		$output =  "<a href=\"?page=QueueManager&file=o".$object->PROCESSID()."\">Output</a>";
	}
	if (-e "/vol/model-prod/FIGdisk/log/QSubError/ModelDriver.sh.e".$object->PROCESSID()) {
		if (length($output) > 0) {
			$output .= "<br>";
		}
		$output .= "<a href=\"?page=QueueManager&file=e".$object->PROCESSID()."\">Errors</a>";
	}
	return $output;
}

=head3 jobcontrols
Definition:
	string::html for ajax controls = FIGMODELweb->jobcontrols(object:job object);
Description:
	Given a job object, this function returns the html for the ajax controls associated with that job.
	Used by the QueueManager webpage.
=cut
sub jobcontrols {
	my ($self,$object) = @_;
	
	if ($object->STATE() == 1) {
		return "<a href=\"javascript:execute_ajax('print_running_tab','0_content_1','job=".$object->ID()."','Loading...','0','post_hook','')\">Kill job</a>";
	} elsif ($object->STATE() == 0) {
		return "<a href=\"javascript:execute_ajax('print_queue_tab','0_content_0','job=".$object->ID()."','Loading...','0','post_hook','')\">Remove job</a><br><a href=\"javascript:execute_ajax('print_queue_tab','0_content_0','top=".$object->ID()."','Loading...','0','post_hook','')\">Move to top</a>";
	}
}

=head3 format_essentiality
Definition:
	string::html for essentiality data = FIGMODELweb->format_essentiality(object:feature object);
Description:
	Given a feature object, this function returns the html for the feature essentiality data.
=cut
sub format_essentiality {
	my ($self,$feature) = @_;
	my $output;
	if (defined($feature->{ESSENTIALITY})) {
		my $essentialityData;
		for (my $i=0; $i < @{$feature->{ESSENTIALITY}};$i++) {
			my @temp = split(/:/,$feature->{ESSENTIALITY}->[$i]);
			push(@{$essentialityData->{$temp[1]}},$temp[0]);
		}
		foreach my $key (keys(%{$essentialityData})) {
			my $string = $key;
			$string = ucfirst($string); 
			push(@{$output},'<span title="'.join(", ",@{$essentialityData->{$key}}).'">'.$string.'</span>');
		}
		return join("<br>",@{$output});
	}
	return "Unknown";
}

sub model_source {
	my ($self,$source) = @_;
	if ($source =~ m/PMID\d\d\d\d\d\d\d\d/) {
		return '<a style="text-decoration:none" href="http://www.ncbi.nlm.nih.gov/pubmed/'.substr($source,4).'" target="_blank">'.$source."</a>";
	}
	return $source;
}

sub model_genes {
	my ($self,$id) = @_;
	my $model = $self->figmodel()->get_model($id);
	if (defined($model)) {
		return $model->model_genes()."/".$self->figmodel()->get_genome_stats($model->genome())->{"TOTAL GENES"}->[0];
	}
	return "";
}

sub model_version {
	my ($self,$object) = @_;
	my $model = $self->figmodel()->get_model($object->{id}->[0]);
	if (defined($model)) {
		return $model->version();
	}
	return "";
}

sub print_reaction_equation {
	my ($self,$equation) = @_;
    return $self->figmodel()->EquationLinks($equation,"=>");
}

sub print_biomass_models {
	my ($self,$id) = @_;
	my $tbl = $self->figmodel()->database()->GetLinkTable("MODEL","BOF");
	if (defined($tbl)) {
		my @rows = $tbl->get_rows_by_key($id,"BOF");
		my $output;
		for (my $i=0; $i < @rows; $i++) {
			if ($i > 0) {
				$output .= ", ";
			}
			$output .= $rows[$i]->{"MODEL"}->[0];
		}
		return $output;
	}
	return "NONE";
}

sub call_model_function {
	my ($self,$id,@args) = @_;
	my $function = $args[0];
	my $model = $self->figmodel()->get_model($id);
	if (!defined($model)) {
		return "";
	}
	return $model->$function();
}

sub model_modification_time {
	my ($self,$id) = @_;
	my $model = $self->figmodel()->get_model($id);
	if (!defined($model)) {
		return "unknown";
	}
	return $self->figmodel()->date($model->modification_time());
}

sub load_html_from_file {
	my ($self,$filename,$altmessage) = @_;
	my $html = $self->figmodel()->database()->load_single_column_file($filename);
	if (defined($html->[0])) {
		return join("\n",@{$html});
	}
	return "<p>".$altmessage."</p>";
}

sub print_compound_biomass_coef {
	my ($self,$id,@args) = @_;
	my $cpd = $self->figmodel()->database()->get_object("cpdbof",{COMPOUND=>$id,BIOMASS=>$args[0]});
	if (defined($cpd)) {
		my $coef = $cpd->coefficient();
		if ($coef < 0) {
			$coef = -1*$coef;
		}
		return $self->figmodel()->convert_number_for_viewing($coef);
	}
	return "NOT FOUND";
}

sub print_compound_kegg_ids {
	my ($self,$id) = @_;
	my $objs = $self->figmodel()->database()->get_objects("cpdals",{COMPOUND=>$id,type=>"KEGG"});
	my $result = "";
	for (my $i=0; $i < @{$objs}; $i++) {
		if (length($result) > 0) {
			$result .= "<br>";	
		}
		$result .= $self->create_kegg_link($objs->[$i]->alias());
	}
	return $result;
}

sub print_compound_names {
	my ($self,$id) = @_;
	
	my $objs = $self->figmodel()->database()->get_objects("cpdals",{COMPOUND=>$id,type=>"name"});
	my $result = "";
	for (my $i=0; $i < @{$objs}; $i++) {
		if (length($result) > 0) {
			$result .= "<br>";	
		}
		$result .= $objs->[$i]->alias();
	}
	return $result;
}

sub print_compound_group {
	my ($self,$id,@args) = @_;
	return $id;
}

1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3