From: martinahansen Date: Wed, 29 Jul 2009 14:21:54 +0000 (+0000) Subject: added embl_index X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=f146952d5fd4de5d4eebdb7e7e54cfa7d8497f9b;p=biopieces.git added embl_index git-svn-id: http://biopieces.googlecode.com/svn/trunk@614 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/embl_index b/bp_bin/embl_index new file mode 100755 index 0000000..35499e8 --- /dev/null +++ b/bp_bin/embl_index @@ -0,0 +1,111 @@ +#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Scan EMBL files and output a file index. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +use warnings; +use strict; +use Data::Dumper; +use Maasha::Biopieces; +use Maasha::Filesys; +use Maasha::EMBL; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $options, $in, $out, $record, $file, $data_in, $entry, $id, $offset ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'data_in', short => 'i', type => 'files!', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + ] +); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +while ( $record = Maasha::Biopieces::get_record( $in ) ) { + Maasha::Biopieces::put_record( $record, $out ); +} + +foreach $file ( @{ $options->{ 'data_in' } } ) +{ + Maasha::Common::error( qq(File "$file" is gzipped) ) if Maasha::Filesys::is_gzipped( $file ); + + $data_in = Maasha::Filesys::file_read_open( $file ); + + $offset = 0; + + while ( $entry = Maasha::EMBL::get_embl_entry( $data_in ) ) + { + if ( $entry =~ /^ID ([^;]+)/ ) + { + $id = $1; + + $record = { + FILE => "$ENV{ 'PWD' }/$file", + ID => $id, + OFFSET => $offset, + LEN => length $entry, + }; + + Maasha::Biopieces::put_record( $record, $out ); + + $offset += length $entry; + } + else + { + Maasha::Common::error( "Bad EMBL entry" ); + } + } + + close $data_in; +} + +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/write_mysql b/bp_bin/write_mysql index aa2c5a4..2d0a214 100755 --- a/bp_bin/write_mysql +++ b/bp_bin/write_mysql @@ -122,6 +122,10 @@ if ( Maasha::SQL::table_exists( $dbh, $options->{ 'table' } ) ) create_table( $dbh, $options->{ 'table' }, $type_hash, $options->{ 'index' }, $options->{ 'verbose' } ); } } +else +{ + create_table( $dbh, $options->{ 'table' }, $type_hash, $options->{ 'index' }, $options->{ 'verbose' } ); +} Maasha::SQL::bulk_load_file( $dbh, $tmp_file, $options->{ 'table' }, "\t" ) if Maasha::SQL::table_exists( $dbh, $options->{ 'table' } ); diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index d9af0f1..566664c 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -687,35 +687,36 @@ sub check_disallowed } -sub getopt_files -{ - # Martin A. Hansen, November 2007. - - # Extracts files from an explicit GetOpt::Long argument - # allowing for the use of glob. E.g. - # --data_in=test.fna - # --data_in=test.fna,test2.fna - # --data_in=*.fna - # --data_in=test.fna,/dir/*.fna - - my ( $option, # option from GetOpt::Long - ) = @_; - - # Returns a list. - - my ( $elem, @files ); - - foreach $elem ( split ",", $option ) - { - if ( -f $elem ) { - push @files, $elem; - } elsif ( $elem =~ /\*/ ) { - push @files, glob( $elem ); - } - } - - return wantarray ? @files : \@files; -} +# marked for deletion - obsolete? +#sub getopt_files +#{ +# # Martin A. Hansen, November 2007. +# +# # Extracts files from an explicit GetOpt::Long argument +# # allowing for the use of glob. E.g. +# # --data_in=test.fna +# # --data_in=test.fna,test2.fna +# # --data_in=*.fna +# # --data_in=test.fna,/dir/*.fna +# +# my ( $option, # option from GetOpt::Long +# ) = @_; +# +# # Returns a list. +# +# my ( $elem, @files ); +# +# foreach $elem ( split ",", $option ) +# { +# if ( -f $elem ) { +# push @files, $elem; +# } elsif ( $elem =~ /\*/ ) { +# push @files, glob( $elem ); +# } +# } +# +# return wantarray ? @files : \@files; +#} sub sig_handler diff --git a/code_perl/Maasha/EMBL.pm b/code_perl/Maasha/EMBL.pm index bd465f4..acd7070 100644 --- a/code_perl/Maasha/EMBL.pm +++ b/code_perl/Maasha/EMBL.pm @@ -60,7 +60,7 @@ sub get_embl_entry my ( $entry ); - $/ = "//\n"; + local $/ = "//\n"; $entry = <$fh>;