-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
192847e
commit a4b27e3
Showing
7 changed files
with
223 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
|
||
my $line = 'chr1 388172 401149 NM_001099460;Vom2r3 0 + 388172 401149 0 6 206,283,804,225,124,884, 0,2845,3556,5212,10804,12093,'; | ||
|
||
|
||
# ... or use subroutine references. | ||
=head | ||
cmpthese(1000000, { | ||
'Split' => '&parseLineOld($line)', | ||
'Substr' => '&parseLineNew($line)', | ||
}); | ||
=cut | ||
my $res = mysplit($line, "\t", 12); | ||
my $ex = mysplit($res->[-1], ",",$res->[9]); | ||
print join(";", @{$res}),"\n"; | ||
print join(";", @{$ex}),"\n"; | ||
sub parseLineOld() | ||
{ | ||
my $line = 'chr1 388172 401149 NM_001099460;Vom2r3 0 + 388172 401149 0 6 206,283,804,225,124,884, 0,2845,3556,5212,10804,12093,'; | ||
my @res = split('\t', $line, 12); | ||
return \@res; | ||
} | ||
sub parseLineNew() | ||
{ | ||
my $line = 'chr1 388172 401149 NM_001099460;Vom2r3 0 + 388172 401149 0 6 206,283,804,225,124,884, 0,2845,3556,5212,10804,12093,'; | ||
my @res = (0) x 12; | ||
my $pos_prev = -1; | ||
my $pos_next = 0; | ||
my $line_siz = length($line); | ||
my $i = 0; | ||
while($pos_next < $line_siz) | ||
{ | ||
$pos_next = index($line,"\t", $pos_prev + 1); | ||
$pos_next = $line_siz if($pos_next == -1); | ||
my $txt = substr($line, $pos_prev + 1, $pos_next - $pos_prev - 1); | ||
$res[$i] = $txt; | ||
#print $i,"\t",$txt,"\n"; | ||
$i++; | ||
$pos_prev = $pos_next; | ||
} | ||
#print $i,"\t",join(";",@res),"\n"; | ||
return \@res; | ||
} | ||
sub mysplit($$$) | ||
{ | ||
my $line = $_[0]; | ||
my $delim = $_[1]; | ||
my $count = $_[2]; | ||
# allocate result array | ||
my @vals = (0) x $count; | ||
my $char_prev = -1; | ||
my $char_next = -1; | ||
my $line_siz = length($line); | ||
my $idx = 0; | ||
while ($char_next < $line_siz) | ||
{ | ||
# find delimiter | ||
$char_next = index($line, $delim, $char_prev + 1); | ||
$char_next = $line_siz if($char_next == - 1); | ||
# splice line | ||
my $str = substr($line, $char_prev + 1, $char_next - $char_prev - 1); | ||
# fill array | ||
$vals[$idx] = $str; | ||
# update counters | ||
$idx++; | ||
$char_prev = $char_next; | ||
} | ||
return \@vals; | ||
} | ||
#print $line,"\n",index($line,"\t"),"\n"; | ||
#print $cnt,"\n"; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package PassParser; | ||
|
||
use warnings; | ||
use strict; | ||
use IO::Zlib; | ||
use Bio::DB::HTS::Tabix; | ||
use Benchmark; | ||
|
||
use lib "$FindBin::Bin/lib"; | ||
use Record::Pass; | ||
|
||
# constructor | ||
sub new | ||
{ | ||
my $class = shift; | ||
my $filename = shift; | ||
my $fileann = shift; | ||
|
||
my $self = {}; | ||
bless ($self, $class); | ||
|
||
# open file handle | ||
my $fileHandle = (); | ||
if ($filename =~ m/\.gz$/) | ||
{ | ||
$fileHandle = IO::Zlib->new($filename, "rb"); | ||
if (!defined($fileHandle)) | ||
{ | ||
$fileHandle->close(); | ||
die $!; | ||
} | ||
|
||
} | ||
else | ||
{ | ||
open($fileHandle, "<", $filename) or die $!; | ||
} | ||
|
||
# open tabix index of annotation | ||
$self->{annotation} = Bio::DB::HTS::Tabix->new(filename => $fileann); | ||
$self->{handle} = $fileHandle; | ||
|
||
return $self; | ||
} | ||
|
||
# destructor | ||
sub DESTROY { | ||
my $self = shift; | ||
$self->{handle}->close() if($self->{handle}); | ||
$self->{annotation}->close() if($self->{annotation}); | ||
} | ||
|
||
# read | ||
sub read | ||
{ | ||
my $self = shift; | ||
|
||
my $line = readline($self->{handle}); | ||
|
||
return $line; | ||
} | ||
|
||
# parse | ||
sub parse | ||
{ | ||
my $self = shift; | ||
my $count = 0; | ||
|
||
my $t0 = Benchmark->new(); | ||
|
||
while(my $line = $self->read()) | ||
{ | ||
chomp($line); | ||
|
||
# create pass object | ||
my $pass = Pass->new($line); | ||
|
||
# count no tail | ||
if ($pass->ispoly() == 0) | ||
{ | ||
$notail += $pass->{readsSumCoverage}; | ||
} | ||
elsif ($pass->ischrom('chrM')) | ||
{ | ||
$mito += $pass->{readsSumCoverage}; | ||
} | ||
|
||
|
||
print $pass->{name},"\n"; | ||
last; | ||
|
||
|
||
$count++; | ||
} | ||
my $t1 = Benchmark->new(); | ||
my $td = timediff($t1, $t0); | ||
print "benchmark :: ",timestr($td),"\n"; | ||
print $count,"\n"; | ||
|
||
} | ||
|
||
1; # return true value |