]> git.donarmstrong.com Git - biopieces.git/commitdiff
added embl_index
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 29 Jul 2009 14:21:54 +0000 (14:21 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 29 Jul 2009 14:21:54 +0000 (14:21 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@614 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/embl_index [new file with mode: 0755]
bp_bin/write_mysql
code_perl/Maasha/Biopieces.pm
code_perl/Maasha/EMBL.pm

diff --git a/bp_bin/embl_index b/bp_bin/embl_index
new file mode 100755 (executable)
index 0000000..35499e8
--- /dev/null
@@ -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__
index aa2c5a431cc703814f7441c7ad93f9957263ed3b..2d0a2142f83ea0cc15f7efa38fe94f4d6f7a4280 100755 (executable)
@@ -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' } );
 
index d9af0f1a53875f5b5b6b710fc5b54eba106de43c..566664c9316a9049a5f4ccfe351bc5dfaaefef45 100644 (file)
@@ -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
index bd465f4f998dcea8641dcc5dc1e6568e0a9cb36a..acd707023cc34de625b4c035422ea49be0d75581 100644 (file)
@@ -60,7 +60,7 @@ sub get_embl_entry
     
     my ( $entry );
 
-    $/ = "//\n";
+    local $/ = "//\n";
 
     $entry = <$fh>;