<commit_before>
package CXGN::Blast::Parse::Plugin::Table;

use Moose;
use File::Slurp qw | read_file |;

sub name { 
    return "Table";
}

sub priority { 
    return 12;
}

sub prereqs { 
}

sub parse { 
  my $self = shift;
  my $c = shift;
  my $file = shift;
  my $bdb = shift;
  
  my $db_id = $bdb->blast_db_id();
  
  my $query = "";
  my $subject = "";
  my $id = 0.0;
  my $aln = 0;
  my $mm = 0;
  my $gaps = 0;
  my $qstart = 0;
  my $qend = 0;
  my $sstart = 0;
  my $send = 0;
  my $evalue = 0.0;
  my $score = 0;
  my $desc = "";

  my $one_hsp = 0;
  
  my $blast_table_file = $file."_tabular.txt";
  my $blast_table_html = $file."_tabular.html";
  
  open (my $blast_fh, "<", $file);
  open (my $table_fh, ">", $blast_table_file);
  open (my $table_html_fh, ">", $blast_table_html);
  
  print $table_html_fh "<style>\n#blast_table_div {\nwidth: 750px;\noverflow: scroll;\nborder:solid #ccf 1px;\n}\n#blast_table {\ntext-align:right;\nwhite-space: nowrap;\npadding:5px\n}\n#blast_table td {\npadding-left: 5px;\n}\n</style>\n";
  print $table_html_fh "<div id=\"blast_table_div\">\n<table id=\"blast_table\" border=\"0\"><tr>\n";
  
  while (my $line = <$blast_fh>) {
    chomp($line);

    if ($line =~ /Query\=\s*(\S+)/) {
      $query = $1;
    }

    if ($line =~ /^>/) {
  
      if ($subject) {
        print $table_fh "$query\t$subject\t$id\t$aln\t$mm\t$gaps\t$qstart\t$qend\t$sstart\t$send\t$evalue\t$score\t$desc\n";
        print $table_html_fh "<tr><td>$query</td><td><a href=\"/tools/blast/show_match_seq.pl?blast_db_id=$db_id;id=$subject;hilite_coords=$sstart-$send\">$subject</a></td><td>$id</td><td>$aln</td><td>$mm</td><td>$gaps</td><td>$qstart</td><td>$qend</td><td>$sstart</td><td>$send</td><td>$evalue</td><td>$score</td><td>$desc</td></tr>\n";
      }
      $subject = "";
      $id = 0.0;
      $aln = 0;
      $mm = 0;
      $gaps = 0;
      $qstart = 0;
      $qend = 0;
      $sstart = 0;
      $send = 0;
      $evalue = 0.0;
      $score = 0;
      $desc = "";
      $one_hsp = 0;
  
      if ($line =~ /^>(\S+)\s+(.+)/) {<commit_msg>Blast table header<commit_after>
package CXGN::Blast::Parse::Plugin::Table;

use Moose;
use File::Slurp qw | read_file |;

sub name { 
    return "Table";
}

sub priority { 
    return 12;
}

sub prereqs { 
}

sub parse { 
  my $self = shift;
  my $c = shift;
  my $file = shift;
  my $bdb = shift;
  
  my $db_id = $bdb->blast_db_id();
  
  my $query = "";
  my $subject = "";
  my $id = 0.0;
  my $aln = 0;
  my $mm = 0;
  my $gaps = 0;
  my $qstart = 0;
  my $qend = 0;
  my $sstart = 0;
  my $send = 0;
  my $evalue = 0.0;
  my $score = 0;
  my $desc = "";

  my $one_hsp = 0;
  
  my $blast_table_file = $file."_tabular.txt";
  my $blast_table_html = $file."_tabular.html";
  
  open (my $blast_fh, "<", $file);
  open (my $table_fh, ">", $blast_table_file);
  open (my $table_html_fh, ">", $blast_table_html);
  
  print $table_html_fh "<style>\n#blast_table_div {\nwidth: 750px;\noverflow: scroll;\nborder:solid #ccf 1px;\n}\n#blast_table {\ntext-align:right;\nwhite-space: nowrap;\npadding:5px\n}\n#blast_table td {\npadding-left: 5px;\n}\n</style>\n";
  print $table_html_fh "<div id=\"blast_table_div\">\n<table id=\"blast_table\" border=\"0\"><tr>\n";
  print $table_html_fh "<tr><th>QueryId</th><th>SubjectId</th><th>id%</th><th>Aln</th><th>Mm</th><th>Gaps</th><th>qstart</th><th>qend</th><th>sstart</th><th>send</th><th>e-value</th><th>Score</th><th>Description</th></tr>\n";
  
  while (my $line = <$blast_fh>) {
    chomp($line);

    if ($line =~ /Query\=\s*(\S+)/) {
      $query = $1;
    }

    if ($line =~ /^>/) {
  
      if ($subject) {
        print $table_fh "$query\t$subject\t$id\t$aln\t$mm\t$gaps\t$qstart\t$qend\t$sstart\t$send\t$evalue\t$score\t$desc\n";
        print $table_html_fh "<tr><td>$query</td><td><a href=\"/tools/blast/show_match_seq.pl?blast_db_id=$db_id;id=$subject;hilite_coords=$sstart-$send\">$subject</a></td><td>$id</td><td>$aln</td><td>$mm</td><td>$gaps</td><td>$qstart</td><td>$qend</td><td>$sstart</td><td>$send</td><td>$evalue</td><td>$score</td><td>$desc</td></tr>\n";
      }
      $subject = "";
      $id = 0.0;
      $aln = 0;
      $mm = 0;
      $gaps = 0;
      $qstart = 0;
      $qend = 0;
      $sstart = 0;
      $send = 0;
      $evalue = 0.0;
      $score = 0;
      $desc = "";
      $one_hsp = 0;
  
      if ($line =~ /^>(\S+)\s+(.+)/) {
{'fraction_non_alphanumeric': 0.23568332192562172, 'fraction_numerical': 0.01642710472279261, 'mean_word_length': 2.9782214156079854, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 113, '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': '1349268', 'n_tokens_mistral': 2054, 'n_tokens_neox': 1917, 'n_words': 325}