From: martinahansen Date: Tue, 1 Dec 2009 10:17:08 +0000 (+0000) Subject: renamed KISS browser to Biopiece browser X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=f1fa4478e76cb0ab70ee38d2281415ac4c6a0b6d;p=biopieces.git renamed KISS browser to Biopiece browser git-svn-id: http://biopieces.googlecode.com/svn/trunk@784 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/read_kiss b/bp_bin/read_kiss index 043f08a..74720af 100755 --- a/bp_bin/read_kiss +++ b/bp_bin/read_kiss @@ -30,7 +30,7 @@ use warnings; use strict; use Maasha::Biopieces; use Maasha::Filesys; -use Maasha::KISS::IO; +use Maasha::KISS; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @@ -58,9 +58,9 @@ if ( $options->{ 'data_in' } ) $num = 1; - while ( $entry = Maasha::KISS::IO::kiss_entry_get( $data_in ) ) + while ( $entry = Maasha::KISS::kiss_entry_get( $data_in ) ) { - if ( $record = Maasha::KISS::IO::kiss2biopiece( $entry ) ) { + if ( $record = Maasha::KISS::kiss2biopiece( $entry ) ) { Maasha::Biopieces::put_record( $record, $out ); } diff --git a/bp_bin/upload_to_KISS b/bp_bin/upload_to_KISS index bb5c208..2a700f1 100755 --- a/bp_bin/upload_to_KISS +++ b/bp_bin/upload_to_KISS @@ -29,7 +29,7 @@ use warnings; use strict; use Maasha::Common; -use Maasha::KISS::IO; +use Maasha::KISS; use Maasha::Biopieces; use Maasha::Fasta; use Maasha::Filesys; @@ -74,7 +74,7 @@ if ( $options->{ 'track_name' } ) while ( $record = Maasha::Biopieces::get_record( $in ) ) { - if ( $entry = Maasha::KISS::IO::biopiece2kiss( $record ) ) + if ( $entry = Maasha::KISS::biopiece2kiss( $record ) ) { if ( not exists $fh_hash{ $entry->{ 'S_ID' } } ) { $fh_hash{ $entry->{ 'S_ID' } } = Maasha::Filesys::file_write_open( "$tmp_dir/$entry->{ 'S_ID' }" ); @@ -82,7 +82,7 @@ if ( $options->{ 'track_name' } ) $fh_out = $fh_hash{ $entry->{ 'S_ID' } }; - Maasha::KISS::IO::kiss_entry_put( $entry, $fh_out ); + Maasha::KISS::kiss_entry_put( $entry, $fh_out ); } Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" }; @@ -118,8 +118,8 @@ if ( $options->{ 'track_name' } ) Maasha::Filesys::file_copy( "$tmp_dir/$key", "$dst_dir/track_data.kiss" ); - Maasha::KISS::IO::kiss_sort( "$dst_dir/track_data.kiss" ); - Maasha::KISS::IO::kiss_index( "$dst_dir/track_data.kiss" ); + Maasha::KISS::kiss_sort( "$dst_dir/track_data.kiss" ); + Maasha::KISS::kiss_index( "$dst_dir/track_data.kiss" ); unlink "$tmp_dir/$key"; } diff --git a/bp_bin/upload_to_bbrowser b/bp_bin/upload_to_bbrowser new file mode 100755 index 0000000..aac4928 --- /dev/null +++ b/bp_bin/upload_to_bbrowser @@ -0,0 +1,252 @@ +#!/usr/bin/env perl + +# Copyright (C) 2007-2009 Martin A. Hansen. + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# http://www.gnu.org/copyleft/gpl.html + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Upload data to local UCSC Genome Browser Database. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +use warnings; +use strict; +use Maasha::Common; +use Maasha::Biopieces; +use Maasha::Filesys; +use Maasha::UCSC; +use Maasha::UCSC::Wiggle; +use Maasha::UCSC::PSL; +use Maasha::UCSC::BED; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $options, $in, $out, $record, $tmp_dir, $file, $wib_file, $wig_file, $wib_dir, $fh_out, $i, $first, $format, $type, $columns, $append, $entry ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'database', short => 'd', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'table', short => 't', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'no_stream', short => 'x', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'short_label', short => 's', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'long_label', short => 'l', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'group', short => 'g', type => 'string', mandatory => 'no', default => $ENV{ 'LOGNAME' }, allowed => undef, disallowed => undef }, + { long => 'priority', short => 'p', type => 'float', mandatory => 'no', default => 1, allowed => undef, disallowed => undef }, + { long => 'use_score', short => 'u', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'visibility', short => 'V', type => 'string', mandatory => 'no', default => 'pack', allowed => 'hide,dense,squish,pack,full', disallowed => undef }, + { long => 'color', short => 'c', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'check', short => 'C', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + ] +); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +$tmp_dir = Maasha::Biopieces::get_tmpdir(); + +$options->{ "short_label" } ||= $options->{ 'table' }; +$options->{ "long_label" } ||= $options->{ 'table' }; +$options->{ "color" } ||= join( ",", int( rand( 255 ) ), int( rand( 255 ) ), int( rand( 255 ) ) ); +$options->{ "chunk_size" } ||= 10_000_000_000; # Due to 32-bit UCSC compilation really large tables cannot be loaded in one go. + +$file = "$tmp_dir/ucsc_upload.tmp"; +$append = 0; +$first = 1; +$i = 0; + +$fh_out = Maasha::Filesys::file_write_open( $file ); + +while ( $record = Maasha::Biopieces::get_record( $in ) ) +{ + Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" }; + + if ( $record->{ "REC_TYPE" } eq "fixed_step" ) + { + $format = "WIGGLE"; + + if ( $entry = Maasha::UCSC::Wiggle::biopiece2fixedstep( $record ) ) { + Maasha::UCSC::Wiggle::fixedstep_entry_put( $entry, $fh_out ); + } + } + elsif ( $record->{ "REC_TYPE" } eq "PSL" ) + { + $format = "PSL"; + + Maasha::UCSC::PSL::psl_put_header( $fh_out ) if $first; + Maasha::UCSC::PSL::psl_put_entry( $record, $fh_out ); + + $first = 0; + } + elsif ( $record->{ "REC_TYPE" } eq "BED" and $record->{ "SEC_STRUCT" } ) + { + # chrom chromStart chromEnd name score strand size secStr conf + + $format = "BED_SS"; + + print $fh_out join ( "\t", + $record->{ "CHR" }, + $record->{ "CHR_BEG" }, + $record->{ "CHR_END" } + 1, + $record->{ "Q_ID" }, + $record->{ "SCORE" }, + $record->{ "STRAND" }, + $record->{ "SIZE" }, + $record->{ "SEC_STRUCT" }, + $record->{ "CONF" }, + ), "\n"; + } + elsif ( $record->{ "REC_TYPE" } eq "BED" ) + { + $format = "BED"; + $columns = $record->{ "BED_COLS" }; + + if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) { + Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } ); + } + } + elsif ( $record->{ "REC_TYPE" } eq "PATSCAN" and $record->{ "CHR" } ) + { + $format = "BED"; + $columns = 6; + + if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) { + Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } ); + } + } + elsif ( $record->{ "REC_TYPE" } eq "BLAST" and $record->{ "S_ID" } =~ /^chr/ ) + { + $format = "BED"; + $columns = 6; + + $record->{ "SCORE" } = $record->{ "BIT_SCORE" } * 1000; + + if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) { + Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } ); + } + } + elsif ( $record->{ "REC_TYPE" } eq "VMATCH" and $record->{ "S_ID" } =~ /^chr/i ) + { + $format = "BED"; + $columns = 6; + + if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) { + Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } ); + } + } + + if ( $i == $options->{ "chunk_size" } ) + { + close $fh_out; + + if ( $format eq "BED" ) { + Maasha::UCSC::bed_upload_to_ucsc( $tmp_dir, $file, $options, $append ); + } elsif ( $format eq "PSL" ) { + Maasha::UCSC::psl_upload_to_ucsc( $file, $options, $append ); + } + + unlink $file; + + $first = 1; + + $append = 1; + + $fh_out = Maasha::Filesys::file_write_open( $file ); + } + + $i++; +} + +close $fh_out; + +if ( $format eq "BED" ) +{ + $type = "bed $columns"; + + Maasha::UCSC::bed_upload_to_ucsc( $tmp_dir, $file, $options, $append ); +} +elsif ( $format eq "BED_SS" ) +{ + $type = "type bed 6 +"; + + Maasha::UCSC::bed_upload_to_ucsc( $tmp_dir, $file, $options, $append ); +} +elsif ( $format eq "PSL" ) +{ + $type = "psl"; + + Maasha::UCSC::psl_upload_to_ucsc( $file, $options, $append ); +} +elsif ( $format eq "WIGGLE" ) +{ + $options->{ "visibility" } = "full"; + + $wig_file = "$options->{ 'table' }.wig"; + $wib_file = "$options->{ 'table' }.wib"; + + $wib_dir = "$ENV{ 'HOME' }/ucsc/wib"; + + Maasha::Filesys::dir_create_if_not_exists( $wib_dir ); + + if ( $options->{ 'verbose' } ) { + `cd $tmp_dir && wigEncode $file $wig_file $wib_file`; + } else { + `cd $tmp_dir && wigEncode $file $wig_file $wib_file > /dev/null 2>&1`; + } + + Maasha::Common::run( "mv", "$tmp_dir/$wib_file $wib_dir" ); + + unlink $file; + + $file = $wig_file; + + $type = "wig 0"; + + Maasha::UCSC::wiggle_upload_to_ucsc( $tmp_dir, $wib_dir, $file, $options ); +} + +unlink $file; + +Maasha::UCSC::ucsc_update_config( $options, $type ); + +Maasha::Biopieces::close_stream( $in ); +Maasha::Biopieces::close_stream( $out ); + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +BEGIN +{ + Maasha::Biopieces::status_set(); +} + + +END +{ + Maasha::Biopieces::status_log(); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +__END__ diff --git a/bp_bin/upload_to_ucsc b/bp_bin/upload_to_ucsc deleted file mode 100755 index aac4928..0000000 --- a/bp_bin/upload_to_ucsc +++ /dev/null @@ -1,252 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2007-2009 Martin A. Hansen. - -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -# http://www.gnu.org/copyleft/gpl.html - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - -# Upload data to local UCSC Genome Browser Database. - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -use warnings; -use strict; -use Maasha::Common; -use Maasha::Biopieces; -use Maasha::Filesys; -use Maasha::UCSC; -use Maasha::UCSC::Wiggle; -use Maasha::UCSC::PSL; -use Maasha::UCSC::BED; - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -my ( $options, $in, $out, $record, $tmp_dir, $file, $wib_file, $wig_file, $wib_dir, $fh_out, $i, $first, $format, $type, $columns, $append, $entry ); - -$options = Maasha::Biopieces::parse_options( - [ - { long => 'database', short => 'd', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, - { long => 'table', short => 't', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, - { long => 'no_stream', short => 'x', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'short_label', short => 's', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'long_label', short => 'l', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'group', short => 'g', type => 'string', mandatory => 'no', default => $ENV{ 'LOGNAME' }, allowed => undef, disallowed => undef }, - { long => 'priority', short => 'p', type => 'float', mandatory => 'no', default => 1, allowed => undef, disallowed => undef }, - { long => 'use_score', short => 'u', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'visibility', short => 'V', type => 'string', mandatory => 'no', default => 'pack', allowed => 'hide,dense,squish,pack,full', disallowed => undef }, - { long => 'color', short => 'c', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'check', short => 'C', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - ] -); - -$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); -$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); - -$tmp_dir = Maasha::Biopieces::get_tmpdir(); - -$options->{ "short_label" } ||= $options->{ 'table' }; -$options->{ "long_label" } ||= $options->{ 'table' }; -$options->{ "color" } ||= join( ",", int( rand( 255 ) ), int( rand( 255 ) ), int( rand( 255 ) ) ); -$options->{ "chunk_size" } ||= 10_000_000_000; # Due to 32-bit UCSC compilation really large tables cannot be loaded in one go. - -$file = "$tmp_dir/ucsc_upload.tmp"; -$append = 0; -$first = 1; -$i = 0; - -$fh_out = Maasha::Filesys::file_write_open( $file ); - -while ( $record = Maasha::Biopieces::get_record( $in ) ) -{ - Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" }; - - if ( $record->{ "REC_TYPE" } eq "fixed_step" ) - { - $format = "WIGGLE"; - - if ( $entry = Maasha::UCSC::Wiggle::biopiece2fixedstep( $record ) ) { - Maasha::UCSC::Wiggle::fixedstep_entry_put( $entry, $fh_out ); - } - } - elsif ( $record->{ "REC_TYPE" } eq "PSL" ) - { - $format = "PSL"; - - Maasha::UCSC::PSL::psl_put_header( $fh_out ) if $first; - Maasha::UCSC::PSL::psl_put_entry( $record, $fh_out ); - - $first = 0; - } - elsif ( $record->{ "REC_TYPE" } eq "BED" and $record->{ "SEC_STRUCT" } ) - { - # chrom chromStart chromEnd name score strand size secStr conf - - $format = "BED_SS"; - - print $fh_out join ( "\t", - $record->{ "CHR" }, - $record->{ "CHR_BEG" }, - $record->{ "CHR_END" } + 1, - $record->{ "Q_ID" }, - $record->{ "SCORE" }, - $record->{ "STRAND" }, - $record->{ "SIZE" }, - $record->{ "SEC_STRUCT" }, - $record->{ "CONF" }, - ), "\n"; - } - elsif ( $record->{ "REC_TYPE" } eq "BED" ) - { - $format = "BED"; - $columns = $record->{ "BED_COLS" }; - - if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) { - Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } ); - } - } - elsif ( $record->{ "REC_TYPE" } eq "PATSCAN" and $record->{ "CHR" } ) - { - $format = "BED"; - $columns = 6; - - if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) { - Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } ); - } - } - elsif ( $record->{ "REC_TYPE" } eq "BLAST" and $record->{ "S_ID" } =~ /^chr/ ) - { - $format = "BED"; - $columns = 6; - - $record->{ "SCORE" } = $record->{ "BIT_SCORE" } * 1000; - - if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) { - Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } ); - } - } - elsif ( $record->{ "REC_TYPE" } eq "VMATCH" and $record->{ "S_ID" } =~ /^chr/i ) - { - $format = "BED"; - $columns = 6; - - if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) { - Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } ); - } - } - - if ( $i == $options->{ "chunk_size" } ) - { - close $fh_out; - - if ( $format eq "BED" ) { - Maasha::UCSC::bed_upload_to_ucsc( $tmp_dir, $file, $options, $append ); - } elsif ( $format eq "PSL" ) { - Maasha::UCSC::psl_upload_to_ucsc( $file, $options, $append ); - } - - unlink $file; - - $first = 1; - - $append = 1; - - $fh_out = Maasha::Filesys::file_write_open( $file ); - } - - $i++; -} - -close $fh_out; - -if ( $format eq "BED" ) -{ - $type = "bed $columns"; - - Maasha::UCSC::bed_upload_to_ucsc( $tmp_dir, $file, $options, $append ); -} -elsif ( $format eq "BED_SS" ) -{ - $type = "type bed 6 +"; - - Maasha::UCSC::bed_upload_to_ucsc( $tmp_dir, $file, $options, $append ); -} -elsif ( $format eq "PSL" ) -{ - $type = "psl"; - - Maasha::UCSC::psl_upload_to_ucsc( $file, $options, $append ); -} -elsif ( $format eq "WIGGLE" ) -{ - $options->{ "visibility" } = "full"; - - $wig_file = "$options->{ 'table' }.wig"; - $wib_file = "$options->{ 'table' }.wib"; - - $wib_dir = "$ENV{ 'HOME' }/ucsc/wib"; - - Maasha::Filesys::dir_create_if_not_exists( $wib_dir ); - - if ( $options->{ 'verbose' } ) { - `cd $tmp_dir && wigEncode $file $wig_file $wib_file`; - } else { - `cd $tmp_dir && wigEncode $file $wig_file $wib_file > /dev/null 2>&1`; - } - - Maasha::Common::run( "mv", "$tmp_dir/$wib_file $wib_dir" ); - - unlink $file; - - $file = $wig_file; - - $type = "wig 0"; - - Maasha::UCSC::wiggle_upload_to_ucsc( $tmp_dir, $wib_dir, $file, $options ); -} - -unlink $file; - -Maasha::UCSC::ucsc_update_config( $options, $type ); - -Maasha::Biopieces::close_stream( $in ); -Maasha::Biopieces::close_stream( $out ); - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -BEGIN -{ - Maasha::Biopieces::status_set(); -} - - -END -{ - Maasha::Biopieces::status_log(); -} - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -__END__ diff --git a/code_perl/Maasha/KISS.pm b/code_perl/Maasha/KISS.pm index 290468a..f15dc88 100644 --- a/code_perl/Maasha/KISS.pm +++ b/code_perl/Maasha/KISS.pm @@ -123,20 +123,23 @@ sub kiss_entry_put defined $entry->{ 'S_END' } ) { + Maasha::Common::error( qq(Bad S_BEG value: $entry->{ 'S_BEG' } < 0 ) ) if $entry->{ 'S_BEG' } < 0; + Maasha::Common::error( qq(Bad S_END value: $entry->{ 'S_END' } < $entry->{ 'S_BEG' }) ) if $entry->{ 'S_END' } < $entry->{ 'S_BEG' }; + $fh ||= \*STDOUT; $fields[ S_ID ] = $entry->{ 'S_ID' }; $fields[ S_BEG ] = $entry->{ 'S_BEG' }; $fields[ S_END ] = $entry->{ 'S_END' }; - $fields[ Q_ID ] = $entry->{ 'Q_ID' }; - $fields[ SCORE ] = $entry->{ 'SCORE' }; - $fields[ STRAND ] = $entry->{ 'STRAND' }; - $fields[ HITS ] = $entry->{ 'HITS' }; - $fields[ ALIGN ] = $entry->{ 'ALIGN' }; - $fields[ BLOCK_COUNT ] = $entry->{ 'BLOCK_COUNT' }; - $fields[ BLOCK_BEGS ] = $entry->{ 'BLOCK_BEGS' }; - $fields[ BLOCK_LENS ] = $entry->{ 'BLOCK_LENS' }; - $fields[ BLOCK_TYPE ] = $entry->{ 'BLOCK_TYPE' }; + $fields[ Q_ID ] = $entry->{ 'Q_ID' } || "."; + $fields[ SCORE ] = $entry->{ 'SCORE' } || "."; + $fields[ STRAND ] = $entry->{ 'STRAND' } || "."; + $fields[ HITS ] = $entry->{ 'HITS' } || "."; + $fields[ ALIGN ] = $entry->{ 'ALIGN' } || "."; + $fields[ BLOCK_COUNT ] = $entry->{ 'BLOCK_COUNT' } || "."; + $fields[ BLOCK_BEGS ] = $entry->{ 'BLOCK_BEGS' } || "."; + $fields[ BLOCK_LENS ] = $entry->{ 'BLOCK_LENS' } || "."; + $fields[ BLOCK_TYPE ] = $entry->{ 'BLOCK_TYPE' } || "."; print $fh join( "\t", @fields ), "\n"; } @@ -447,7 +450,52 @@ sub kiss_index_get_blocks } -sub kiss_align +sub kiss_align_enc +{ + # Martin A. Hansen, November 2009. + + # Encodes alignment descriptors for two + # aligned sequences. + + my ( $s_seq, # Subject sequence reference + $q_seq, # Query sequence reference + $offset, # alternate offset - OPTIONAL + ) = @_; + + # Returns a list + + my ( $i, $s, $q, @align ); + + Maasha::Common::error( "Sequence lengths don't match" ) if length ${ $s_seq } != length ${ $q_seq }; + + $offset ||= 0; + + for ( $i = 0; $i < length ${ $s_seq }; $i++ ) + { + $s = uc substr ${ $s_seq }, $i, 1; + $q = uc substr ${ $q_seq }, $i, 1; + + if ( $s eq '-' and $q eq '-' ) + { + # do nothing + } + elsif ( $s eq $q ) + { + $offset++; + } + else + { + push @align, "$offset:$s>$q"; + + $offset++ if not $s eq '-'; + } + } + + return wantarray ? @align : \@align; +} + + +sub kiss_align_dec { # Martin A. Hansen, November 2009.