#!/usr/bin/perl use strict; use subs; use POSIX; use Data::Dumper; use constant LINE_SIZE => 60; use constant UNGAPPED_ALIGNMENT_INDEX_DENSITY => 10; # Print an index every n pip lines my %args = getParams(); my $alignment = 0; my $alignment_offset=0; my $human_start=0; my $human_end=0; my $species_start=0; my $species_end=0; my $fasta_name = ""; my $fasta_file = ""; my $offset = 0; my $pip_location; my $desc_location; my $location = 0; my $pip_count; my $description; my $pip_string=""; my @results; my $temp_var = 0; open (BLASTZ, $args{file}); while () { if (($_ =~ m/^#:lav/) && ($location != 0)) { push @results, [$human_start, $human_end, $desc_location, $location,$pip_string]; $human_end = 0; $human_start = 0; $desc_location = 0; $location = 0; $pip_string = ""; } if ($_ =~ m/^h {/) { $_ = ; $desc_location = tell(BLASTZ); next; } next if !($_ =~ m/^[h ] [{bel] \d/); # Only lines that need processing are here if ($_ =~ m/^ *b /) { if ($human_end ne 0) { push @results, [$human_start, $human_end, $desc_location, $location,$pip_string]; $pip_string = ""; $temp_var++; } ($human_start) = ($_ =~ m/^ *b *(\d+) /); } elsif ($_ =~ m/^ *e /) { ($human_end) = ($_ =~ m/^ *e *(\d+) /); $location = tell(BLASTZ); $pip_count=0; } else { $pip_count++; # Only create actual offset for every nth pip if ($pip_count >= UNGAPPED_ALIGNMENT_INDEX_DENSITY) { $pip_count = 0; (my $pip_start) = ($_ =~ m/^ *l (\d+) /); $pip_string .= "," if ($pip_string ne ""); $pip_string .= "$pip_start,$pip_location"; } $pip_location = tell(BLASTZ); } } push @results, [$human_start, $human_end, $desc_location, $location,$pip_string] if ($human_end != 0); @results = sort { $a->[0] <=> $b->[0] } @results; for (my $i=0; $i<@results; $i++) { print "$results[$i][0]"; print ",$results[$i][1]"; print ",$results[$i][2]"; print ",$results[$i][3]"; print ",$results[$i][4]" if ($results[$i][4] ne ""); print "\n"; } sub getParams { my %opts; my $errstr = ""; use Getopt::Long; GetOptions(\%opts, 'file=s'); if (!defined($opts{file})) { $errstr .= "ERROR : No blastz file to index\n"; } if ($errstr) { print <<"END_USAGE"; Usage: index_blastz.pl -file Description: This will create an index to the blsatz file for quick searching. The index will be printed to stdout. Usage: Probe Sources: -file Blastz file to be index END_USAGE print "\n$errstr" if ($errstr); die("\n"); } return (file => $opts{file}); }