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

use strict;
use POSIX;
use CoGe::Accessory::blastz_report::seq;
use CoGe::Accessory::blastz_report::segment;
use CoGe::Accessory::parse_report::HSP;
use base qw(Class::Accessor);
use Carp;
use Data::Dumper;


BEGIN
  {
    use vars qw($VERSION);
    $VERSION = "0.01";
  }
__PACKAGE__->mk_accessors qw(hsps hsp_count file _params seq_info file_base query subject match);


###############################################################################
# blastz report parser -- <NAME> All rights and lefts reserved!
###############################################################################
#################### subroutine header begin ####################

=head2 new

 Usage     : my $blastz_report = new CoGe::Accessory::blastz_report($blastz_file);
 Purpose   : parse a blastz report, generate this object
 Returns   : a blastz_report object
 Argument  : a string that points to a blastz file
 Throws    : lots of errors and warnings if the blastz file is missing or can't be read
 Comment   : 
           : 

See Also   : 

=cut

#################### subroutine header end ####################

sub new 
  {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $file = "";
    if ( @_ ) {
      ($file) = shift;
    } 
    unless (-r $file)
      {
	croak " error: new needs a file name!\n";
      }
    my $opts = shift;
    $opts = {} unless defined $opts;
    my $self = bless ($opts, $class);
    $self->file($file);
    $self->hsp_count(0);
    $self->hsps([]);
    $self->process_file($file);
    unless ($self->file_base())
      {
	my ($base) = $file =~ /^(.*?)[^\/]*$/;
	$base = "./".$base unless $base =~ /^\//;
	$self->file_base($base);
      }
    return $self;
}


sub process_file
  {
    my $self = shift;
    my $file = shift || $self->file;
    unless (-r $file)
      {
	warn "can't read $file in blastz_report.pm.  nothing to process\n";
	return;
      }
    open (IN, $file);
    $/ = "}\n";
    while (<IN>)
      {
	s/#.*\n//g;
	$self->parse_params($_) if /^d/;
	$self->parse_file_names($_) if /^s/;
	$self->parse_fasta_header($_) if /^h/;
	$self->parse_alignment($_) if /^a/;
      }	
    $self->parse_sequences(); #let's see if we get lucky with finding sequence files
    close IN;
  }<commit_msg>updated obj creation<commit_after>package CoGe::Accessory::blastz_report;

use strict;
use POSIX;
use CoGe::Accessory::blastz_report::seq;
use CoGe::Accessory::blastz_report::segment;
use CoGe::Accessory::parse_report::HSP;
use base qw(Class::Accessor);
use Carp;
use Data::Dumper;


BEGIN
  {
    use vars qw($VERSION);
    $VERSION = "0.01";
  }
__PACKAGE__->mk_accessors qw(hsps hsp_count file _params seq_info file_base query subject match);


###############################################################################
# blastz report parser -- <NAME> All rights and lefts reserved!
###############################################################################
#################### subroutine header begin ####################

=head2 new

 Usage     : my $blastz_report = new CoGe::Accessory::blastz_report($blastz_file);
 Purpose   : parse a blastz report, generate this object
 Returns   : a blastz_report object
 Argument  : a string that points to a blastz file
 Throws    : lots of errors and warnings if the blastz file is missing or can't be read
 Comment   : 
           : 

See Also   : 

=cut

#################### subroutine header end ####################

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);
    $self->hsps([]);
    $self->process_file();
    unless ($self->file_base())
      {
	my ($base) = $self->file =~ /^(.*?)[^\/]*$/;
	$base = "./".$base unless $base =~ /^\//;
	$self->file_base($base);
      }
    return $self;
}


sub process_file
  {
    my $self = shift;
    my $file = shift || $self->file;
    unless (-r $file)
      {
	warn "can't read $file in blastz_report.pm.  nothing to process\n";
	return;
      }
    open (IN, $file);
    $/ = "}\n";
    while (<IN>)
      {
	s/#.*\n//g;
	$self->parse_params($_) if /^d/;
	$self->parse_file_names($_) if /^s/;
	$self->parse_fasta_header($_) if /^h/;
	$self->parse_alignment($_) if /^a/;
      }	
    $self->parse_sequences(); #let's see if we get lucky with finding sequence files
    close IN;
  }
{'fraction_non_alphanumeric': 0.2502813414359667, 'fraction_numerical': 0.0022507314877335135, 'mean_word_length': 3.3956478733926807, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, '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': '526119', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1456, 'n_words': 393}