<commit_before>package CoGe::Accessory::chaos_report;

use strict;
use warnings;
use CoGe::Accessory::parse_report::HSP;
use base qw(Class::Accessor);

use Data::Dumper;


BEGIN
  {
    use vars qw($VERSION);
    $VERSION = "0.01";
  }
__PACKAGE__->mk_accessors qw(file hsps hsp_count query subject qlength slength gotname);

###############################################################################
# chaos_report -- <NAME>  UC Berkeley
###############################################################################
sub new {
	my $proto = shift;
	my $opts = shift;
	$opts = {} unless $opts;
	my $class = ref($proto) || $proto;
	my $self = bless ({%$opts}, $class);
	$self->hsp_count(0) unless $self->hsp_count;;
	$self->process_file();
	return $self;
      }

sub process_file
  {
    my $self = shift;
    my $file = shift || $self->file;
    my $tmp;
    my @data;
    open (IN, $file) || die "can't open $file for reading: $!";
    while (<IN>)
    {
     $tmp .= $_;
     if (/perc/)
     {push @data,$tmp;$tmp="";}
    }
    close IN;
    foreach my $alignments (@data)
    {
      my $hsp = $self->get_hsp($alignments);
      push @hsps,$hsps if $hsps;
    }
    $self->hsps(\@hsps);
    return $self;
}


sub _parseReport {
	my $self = shift;
	my $data = shift;
	my $hsp_count = $self->hsp_count();
	$hsp_count++;
	$self->hsp_count($hsp_count);
	my ($locs,$scores) = ("","");
	my ($sq1,$align,$sq2) = ("","","");
	my ($score,$nmatches,$nga,$ngb,$nletters,$perc) = (0,0,0,0,0,0);
        my ($name1,$start1,$stop1,$name2,$start2,$stop2,$score_plus) = (0,0,0,0,0,0,0);
	foreach my $things (split /\n/,$data)
	{ 
         next unless $things;
         $locs = $things if $things =~/;/;
      	 $scores = $things if $things =~/,/;
         push @aligns,$things if $things =~/([ATGC]|:)/;
	}
	for (my $i=0;$i<scalar(@$ref);$i+=3)
	{
   	  $sq1 .= $ref->[$i];
   	  $align .= $ref->[$i+1];
   	  $sq2 .= $ref->[$i+2];
   	  }
   	my $gaps1 = $sq1 =~tr/-/-/;
   	my $gaps2 = $sq2 =~tr/-/-/;
   	$align =~s/:/|/g;
	while ($align !~ /^\|/)
        	{$sq1 =~s/^.//;$sq2 =~s/^.//;$align =~s/^.//;}
  	while ($align !~ /\|$/)
       		{$sq1 =~s/.$//;$sq2 =~s/.$//;$align =~s/.$//;}
  	if ($locs =~/^(\w+\.?\d*)\s(\d+)\s(\d+).\s(\w+\.?\d*)\s(\d+)\s(\d+).+(\d+\.\d+)/)
    	{
    		($name1,$start1,$stop1,$name2,$start2,$stop2,$score_plus) = ($1,$2,$3,$4,$5,$6,$7);
   	}
	if ($scores =~/^\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+).+(0?\.\d+)/)
    	{
      		($score,$nmatches,$nga,$ngb,$nletters,$perc) = ($1,$2,$3,$4,$5,$6);
    	}
  	$self->_getNames($name1,$name2) unless $self->gotname();
  	$perc *=100;
   	my $hsp = new CoGe::Accessory::parse_report::HSP
        ({
   	  score=>$score,
    	  match=>$nmatches,
    	  length=>$nletters,
    	  query_start=>$start1,
    	  query_stop=>$stop2,
    	  subject_start=>$start2,
    	  subject_stop=>$stop2,
    	  query_alignment=>$sq1,
    	  subject_alignment=>$sq2,
    	  alignment=>$align,
    	  query_gaps=>$gaps1,
    	  subject_gaps=>$gaps2,
    	  nga=>$nga,
    	  ngb=>$ngb,
    	  percent_id=>$perc,
    	  number=>$count,
        });
    return $hsp;
 }
 
sub _getNames {
	my $self = shift;
	my $query = shift;
	my $subject = shift;
	$self->query($query);
	$self->subject($subject);
	$self->gotname(1);
	return $self;
}
	

1;<commit_msg>removed gaps variables, replace with nga,ngb. added regex,strand variable to grab +/-.<commit_after>package CoGe::Accessory::chaos_report;

use strict;
use warnings;
use CoGe::Accessory::parse_report::HSP;
use base qw(Class::Accessor);

use Data::Dumper;


BEGIN
  {
    use vars qw($VERSION);
    $VERSION = "0.01";
  }
__PACKAGE__->mk_accessors qw(file hsps hsp_count query subject qlength slength gotname);

###############################################################################
# chaos_report -- <NAME>  UC Berkeley
###############################################################################
sub new {
	my $proto = shift;
	my $opts = shift;
	$opts = {} unless $opts;
	my $class = ref($proto) || $proto;
	my $self = bless ({%$opts}, $class);
	$self->hsp_count(0) unless $self->hsp_count;;
	$self->process_file();
	return $self;
      }

sub process_file
  {
    my $self = shift;
    my $file = shift || $self->file;
    my $tmp;
    my @data;
    open (IN, $file) || die "can't open $file for reading: $!";
    while (<IN>)
    {
     $tmp .= $_;
     if (/perc/)
     {push @data,$tmp;$tmp="";}
    }
    close IN;
    foreach my $alignments (@data)
    {
      my $hsp = $self->get_hsp($alignments);
      push @hsps,$hsps if $hsps;
    }
    $self->hsps(\@hsps);
    return $self;
}


sub _parseReport {
	my $self = shift;
	my $data = shift;
	my $hsp_count = $self->hsp_count();
	$hsp_count++;
	$self->hsp_count($hsp_count);
	my ($locs,$scores) = ("","");
	my ($sq1,$align,$sq2) = ("","","");
	my ($score,$nmatches,$nga,$ngb,$nletters,$perc) = (0,0,0,0,0,0);
        my ($name1,$start1,$stop1,$name2,$start2,$stop2,$score_plus,$strand) = (0,0,0,0,0,0,0,0);
	foreach my $things (split /\n/,$data)
	{ 
         next unless $things;
         $locs = $things if $things =~/;/;
      	 $scores = $things if $things =~/,/;
         push @aligns,$things if $things =~/([ATGC]|:)/;
	}
	for (my $i=0;$i<scalar(@$ref);$i+=3)
	{
   	  $sq1 .= $ref->[$i];
   	  $align .= $ref->[$i+1];
   	  $sq2 .= $ref->[$i+2];
   	  }
   	$align =~s/:/|/g;
	while ($align !~ /^\|/)
        	{$sq1 =~s/^.//;$sq2 =~s/^.//;$align =~s/^.//;}
  	while ($align !~ /\|$/)
       		{$sq1 =~s/.$//;$sq2 =~s/.$//;$align =~s/.$//;}
  	if ($locs =~/^(\w+\.?\d*)\s(\d+)\s(\d+).\s(\w+\.?\d*)\s(\d+)\s(\d+).+(\d+\.\d+)\s.(.)/)
    	{
    		($name1,$start1,$stop1,$name2,$start2,$stop2,$score_plus,$strand) = ($1,$2,$3,$4,$5,$6,$7,$8);
   	}
	if ($scores =~/^\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+).+(0?\.\d+)/)
    	{
      		($score,$nmatches,$nga,$ngb,$nletters,$perc) = ($1,$2,$3,$4,$5,$6);
    	}
  	$self->_getNames($name1,$name2) unless $self->gotname();
  	$perc *=100;
   	my $hsp = new CoGe::Accessory::parse_report::HSP
        ({
   	  score=>$score,
    	  match=>$nmatches,
    	  length=>$nletters,
    	  query_start=>$start1,
    	  query_stop=>$stop1,
    	  subject_start=>$start2,
    	  subject_stop=>$stop2,
    	  query_alignment=>$sq1,
    	  subject_alignment=>$sq2,
    	  alignment=>$align,
    	  query_gaps=>$nga,
    	  subject_gaps=>$ngb,
    	  percent_id=>$perc,
    	  number=>$count,
        });
    return $hsp;
 }
 
sub _getNames {
	my $self = shift;
	my $query = shift;
	my $subject = shift;
	$self->query($query);
	$self->subject($subject);
	$self->gotname(1);
	return $self;
}
	

1;
{'fraction_non_alphanumeric': 0.288135593220339, 'fraction_numerical': 0.021791767554479417, 'mean_word_length': 2.950388523610281, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 71, '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': '130990', 'n_tokens_mistral': 2874, 'n_tokens_neox': 2773, 'n_words': 464}