<commit_before>#!/usr/bin/env perl

use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/../perl5", "$FindBin::Bin/../../perl5", "$FindBin::Bin/../../../perl5";

use Error qw(:try);

# uses below here might come from ../perl5 if available
use Unison::WWW;
use Unison::WWW::Page;

use Bio::Prospect::Options;
use Bio::Prospect::LocalClient;
use Bio::Prospect::Exceptions;

my $p = new Unison::WWW::Page;
my $u = $p->{unison};
my $v = $p->Vars();
$p->ensure_required_params(qw(pseq_id params_id templates viewer));

my ($pdb_fh, $pdb_fn, $pdb_urn) = $p->tempfile(SUFFIX => '.pdb' );

my $seq = $u->get_sequence_by_pseq_id( $v->{pseq_id} );
if (not defined $seq) {
  $p->die("couldn't fetch sequence for pseq_id=$v->{pseq_id}"); 
}

my @templates = split(/[\0,]/,$v->{templates});
my $template = $templates[0];

my $po = $u->get_p2options_by_params_id( $v->{params_id} );
if (not defined $po) {
  $p->die("The params_id parameter ($v->{params_id}) is invalid."); 
}
$po->{templates} = \@templates;
$po->{"3d"} = 1;

try {
  my $pf = new Bio::Prospect::LocalClient( {options=>$po} );

  my $thr = ($pf->thread( $seq ))[0];

  if($v->{viewer} eq 'rasmol') {
    print("Content-type: application/x-rasmol\n",
	  sprintf("Content-disposition: attachment; filename=%s-%s-%s.rasmol\n",
		  $v->{pseq_id},$template,$v->{params_id}),
	  "\n",
	  $thr->output_rasmol_script(),
	 );
  }
  elsif($v->{viewer} eq 'pymol') {

    $thr->qname($v->{pseq_id});
    my $root = sprintf("%s-%s-%s",$v->{pseq_id},$template,$v->{params_id});
    my $filename = "$root.pml";
    print("Content-type: application/x-pymol\n",
	  "Content-disposition: attachment; filename=$filename\n",
	  "\n",
	  $thr->output_pymol_script($root ),
	 );
  }
} catch Bio::Prospect::RuntimeError with {
  $p->die("couldn't generate $v->{viewer} script",$@)
};

exit(0);
<commit_msg>enabled jmol viewing again, this time without temp pdb files<commit_after>#!/usr/bin/env perl

use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/../perl5", "$FindBin::Bin/../../perl5", "$FindBin::Bin/../../../perl5";

use Error qw(:try);

# uses below here might come from ../perl5 if available
use Unison::WWW;
use Unison::WWW::Page;
use Unison::Jmol;

use Bio::Prospect::Options;
use Bio::Prospect::LocalClient;
use Bio::Prospect::Exceptions;

my $p = new Unison::WWW::Page;
my $u = $p->{unison};
my $v = $p->Vars();
$p->ensure_required_params(qw(pseq_id params_id templates viewer));

my $seq = $u->get_sequence_by_pseq_id( $v->{pseq_id} );
if (not defined $seq) {
  $p->die("couldn't fetch sequence for pseq_id=$v->{pseq_id}"); 
}

my @templates = split(/[\0,]/,$v->{templates});
my $template = $templates[0];

my $po = $u->get_p2options_by_params_id( $v->{params_id} );
if (not defined $po) {
  $p->die("The params_id parameter ($v->{params_id}) is invalid."); 
}
$po->{templates} = \@templates;
$po->{"3d"} = 1;

try {
  my $pf = new Bio::Prospect::LocalClient( {options=>$po} );

  my $thr = ($pf->thread( $seq ))[0];

  if($v->{viewer} eq 'rasmol') {
    print("Content-type: application/x-rasmol\n",
	  sprintf("Content-disposition: attachment; filename=%s-%s-%s.rasmol\n",
		  $v->{pseq_id},$template,$v->{params_id}),
	  "\n",
	  $thr->output_rasmol_script(),
	 );
  }
  elsif($v->{viewer} eq 'pymol') {

    $thr->qname($v->{pseq_id});
    my $root = sprintf("%s-%s-%s",$v->{pseq_id},$template,$v->{params_id});
    my $filename = "$root.pml";
    print("Content-type: application/x-pymol\n",
	  "Content-disposition: attachment; filename=$filename\n",
	  "\n",
	  $thr->output_pymol_script($root ),
	 );
  }
  elsif($v->{viewer} eq 'jmol') {
      my $jmol = new Unison::Jmol(600,300);
      $p->add_html($jmol->script_header());
      print $p->render("Threading model for Unison:$v->{pseq_id}",
		       $p->best_annotation($v->{pseq_id}),
		       $jmol->initialize_inline($thr->output_jmol_script),
		       "<center>Threading alignment : Identities are colored <font color=blue>blue</font>, similarities are colored <font color=cyan>cyan</font> and mismatches are colored <font color=red>red</font>. Insertions are shown in <font color=green>>number of insertions<</font>. Deletions are colored <font color=grey>grey</font>. All Cysteines are colored <font color=yellow>yellow</font> and conserved cysteines are spacefilled.</center>"
		      );

    }
}
  catch Bio::Prospect::Exception with {
    $p->die("No threading result!",$_[0]);
  }
  catch Bio::Prospect::RuntimeError with {
    $p->die("couldn't generate $v->{viewer} script",$@)
  };
exit(0);

{'fraction_non_alphanumeric': 0.2214868740348555, 'fraction_numerical': 0.0063975292300904475, 'mean_word_length': 4.423444976076555, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 86, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3574162', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1753, 'n_words': 346}