From: martinahansen Date: Tue, 2 Jun 2009 18:37:28 +0000 (+0000) Subject: bleh blah X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=bd27b1017ee7cdfde9f7d93fbe1b0ef97312edd6;p=biopieces.git bleh blah git-svn-id: http://biopieces.googlecode.com/svn/trunk@472 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/read_mysql b/bp_bin/read_mysql index fdf5bd2..0033207 100755 --- a/bp_bin/read_mysql +++ b/bp_bin/read_mysql @@ -1,6 +1,92 @@ -#!/usr/bin/env perl +#!/usr/bin/env perl -w + +# 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Read records from a MySQL query. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use warnings; use strict; +use Maasha::Biopieces; +use Maasha::SQL; +use Maasha::UCSC; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $run_time_beg, $run_time_end, $default_user, $default_password, $options, $in, $out, $record, $dbh, $results ); + +$default_user = Maasha::UCSC::ucsc_get_user(); +$default_password = Maasha::UCSC::ucsc_get_password(); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'database', short => 'd', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'query', short => 'q', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'user', short => 'u', type => 'string', mandatory => 'no', default => $default_user, allowed => undef, disallowed => undef }, + { long => 'password', short => 'p', type => 'string', mandatory => 'no', default => $default_password, 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 ); +} + +$dbh = Maasha::SQL::connect( $options->{ "database" }, $options->{ "user" }, $options->{ "password" } ); + +$results = Maasha::SQL::query_hashref_list( $dbh, $options->{ "query" } ); + +Maasha::SQL::disconnect( $dbh ); + +map { Maasha::Biopieces::put_record( $_ ) } @{ $results }; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +BEGIN +{ + $run_time_beg = Maasha::Biopieces::run_time(); + + Maasha::Biopieces::log_biopiece(); +} + +END +{ + Maasha::Biopieces::close_stream( $in ); + Maasha::Biopieces::close_stream( $out ); + + $run_time_end = Maasha::Biopieces::run_time(); + + Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options ); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + -use Maasha::BioRun; +__END__ diff --git a/bp_bin/read_phastcons b/bp_bin/read_phastcons deleted file mode 100755 index 9449a0d..0000000 --- a/bp_bin/read_phastcons +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env perl -w - -# 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - -# Read FASTA entries from one or more files. - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -use strict; -use Maasha::Biopieces; -use Maasha::Filesys; -use Maasha::Fasta; - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $data_in, $num, $entry ); - -$options = Maasha::Biopieces::parse_options( - [ - { long => 'data_in', short => 'i', type => 'files!', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'num', short => 'n', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => '0' }, - ] -); - -$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 ); -} - -if ( $options->{ 'data_in' } ) -{ - $data_in = Maasha::Filesys::files_read_open( $options->{ 'data_in' } ); - - $num = 1; - - while ( $entry = Maasha::Fasta::get_entry( $data_in ) ) - { - if ( $record = Maasha::Fasta::fasta2biopiece( $entry ) ) { - Maasha::Biopieces::put_record( $record, $out ); - } - - last if $options->{ "num" } and $num == $options->{ "num" }; - - $num++; - } - - close $data_in; -} - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -BEGIN -{ - $run_time_beg = Maasha::Biopieces::run_time(); - - Maasha::Biopieces::log_biopiece(); -} - -END -{ - Maasha::Biopieces::close_stream( $in ); - Maasha::Biopieces::close_stream( $out ); - - $run_time_end = Maasha::Biopieces::run_time(); - - Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options ); -} - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -__END__ diff --git a/code_perl/Maasha/BioRun.pm b/code_perl/Maasha/BioRun.pm index 3f4fb1c..16b6df9 100644 --- a/code_perl/Maasha/BioRun.pm +++ b/code_perl/Maasha/BioRun.pm @@ -112,8 +112,6 @@ sub run_script if ( $script eq "print_usage" ) { script_print_usage( $in, $out, $options ) } elsif ( $script eq "read_stockholm" ) { script_read_stockholm( $in, $out, $options ) } - elsif ( $script eq "read_phastcons" ) { script_read_phastcons( $in, $out, $options ) } - elsif ( $script eq "read_mysql" ) { script_read_mysql( $in, $out, $options ) } elsif ( $script eq "uppercase_seq" ) { script_uppercase_seq( $in, $out, $options ) } elsif ( $script eq "complexity_seq" ) { script_complexity_seq( $in, $out, $options ) } elsif ( $script eq "get_genome_align" ) { script_get_genome_align( $in, $out, $options ) } @@ -158,26 +156,6 @@ sub get_options num|n=s ); } - elsif ( $script eq "read_phastcons" ) - { - @options = qw( - data_in|i=s - num|n=s - min|m=s - dist|d=s - threshold|t=f - gap|g=s - ); - } - elsif ( $script eq "read_mysql" ) - { - @options = qw( - database|d=s - query|q=s - user|u=s - password|p=s - ); - } elsif ( $script eq "get_genome_align" ) { @options = qw( @@ -467,94 +445,6 @@ sub script_read_stockholm } -sub script_read_phastcons -{ - # Martin A. Hansen, December 2007. - - # Read PhastCons format. - - my ( $in, # handle to in stream - $out, # handle to out stream - $options, # options hash - ) = @_; - - # Returns nothing. - - my ( $data_in, $file, $num, $entry, @records, $record ); - - $options->{ "min" } ||= 10; - $options->{ "dist" } ||= 25; - $options->{ "threshold" } ||= 0.8; - $options->{ "gap" } ||= 5; - - while ( $record = Maasha::Biopieces::get_record( $in ) ) { - Maasha::Biopieces::put_record( $record, $out ); - } - - $num = 1; - - foreach $file ( @{ $options->{ "files" } } ) - { - $data_in = Maasha::Common::read_open( $file ); - - while ( $entry = Maasha::UCSC::fixedstep_get_entry( $data_in ) ) - { - @records = Maasha::UCSC::phastcons_parse_entry( $entry, $options ); - - foreach $record ( @records ) - { - $record->{ "REC_TYPE" } = "BED"; - $record->{ "BED_LEN" } = $record->{ "CHR_END" } - $record->{ "CHR_BEG" } + 1; - - Maasha::Biopieces::put_record( $record, $out ); - - goto NUM if $options->{ "num" } and $num == $options->{ "num" }; - - $num++; - } - } - - close $data_in; - } - - NUM: - - close $data_in if $data_in; -} - - -sub script_read_mysql -{ - # Martin A. Hansen, May 2008. - - # Read a MySQL query into stream. - - my ( $in, # handle to in stream - $out, # handle to out stream - $options, # options hash - ) = @_; - - # Returns nothing. - - my ( $record, $dbh, $results ); - - $options->{ "user" } ||= Maasha::UCSC::ucsc_get_user(); - $options->{ "password" } ||= Maasha::UCSC::ucsc_get_password(); - - while ( $record = Maasha::Biopieces::get_record( $in ) ) { - Maasha::Biopieces::put_record( $record, $out ); - } - - $dbh = Maasha::SQL::connect( $options->{ "database" }, $options->{ "user" }, $options->{ "password" } ); - - $results = Maasha::SQL::query_hashref_list( $dbh, $options->{ "query" } ); - - Maasha::SQL::disconnect( $dbh ); - - map { Maasha::Biopieces::put_record( $_ ) } @{ $results }; -} - - sub script_complexity_seq { # Martin A. Hansen, May 2008. diff --git a/code_perl/Maasha/UCSC.pm b/code_perl/Maasha/UCSC.pm index 7445807..fad1401 100644 --- a/code_perl/Maasha/UCSC.pm +++ b/code_perl/Maasha/UCSC.pm @@ -1216,6 +1216,11 @@ sub phastcons_parse_entry # Given a PhastCons entry converts this to a # list of super blocks. +# $options->{ "min" } ||= 10; +# $options->{ "dist" } ||= 25; +# $options->{ "threshold" } ||= 0.8; +# $options->{ "gap" } ||= 5; + my ( $lines, # list of lines $args, # argument hash ) = @_; @@ -1638,9 +1643,13 @@ sub ucsc_get_user # Returns a string. - my ( $fh, $line, $user ); + my ( $file, $fh, $line, $user ); + + $file = "$ENV{ 'HOME' }/.hg.conf"; + + return if not -f $file; - $fh = Maasha::Common::read_open( "$ENV{ 'HOME' }/.hg.conf" ); + $fh = Maasha::Common::read_open( $file ); while ( $line = <$fh> ) { @@ -1669,9 +1678,13 @@ sub ucsc_get_password # Returns a string. - my ( $fh, $line, $password ); + my ( $file, $fh, $line, $password ); + + $file = "$ENV{ 'HOME' }/.hg.conf"; + + return if not -f $file; - $fh = Maasha::Common::read_open( "$ENV{ 'HOME' }/.hg.conf" ); + $fh = Maasha::Common::read_open( $file ); while ( $line = <$fh> ) {