From 21ae8a4a90a4ba3e7990eefa38b1ef09a43d6308 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Mon, 14 Dec 2009 13:56:40 +0000 Subject: [PATCH] added BGB_list git-svn-id: http://biopieces.googlecode.com/svn/trunk@806 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/BGB_list | 120 +++++++++++ bp_conf/bashrc | 4 + code_perl/Maasha/BGB/Common.pm | 355 +++++++++++++++++++++++++++++++++ 3 files changed, 479 insertions(+) create mode 100755 bp_bin/BGB_list create mode 100644 code_perl/Maasha/BGB/Common.pm diff --git a/bp_bin/BGB_list b/bp_bin/BGB_list new file mode 100755 index 0000000..1cc1c0b --- /dev/null +++ b/bp_bin/BGB_list @@ -0,0 +1,120 @@ +#!/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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# List all tracks availible in a local installation of the Biopieces Genome Browser. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +use warnings; +use strict; +use Data::Dumper; +use Maasha::Biopieces; +use Maasha::BGB::Common; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +my ( $user, $options, $in, $out, $record, $dir_hash, $clade, $genome, $assembly, $contig, $track ); + +$user = Maasha::Biopieces::biopiecesrc( "BPB_USER" ); + +$options = Maasha::Biopieces::parse_options( + [ + { long => 'user', short => 'u', type => 'string', mandatory => 'yes', default => $user, 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 ); +} + +Maasha::Common::error( qq(Bad user: "$options->{ 'user' }") ) if not grep /^$options->{ 'user' }$/, Maasha::BGB::Common::list_users(); + +foreach $clade ( Maasha::BGB::Common::list_clades( $options->{ 'user' } ) ) +{ + foreach $genome ( Maasha::BGB::Common::list_genomes( $options->{ 'user' }, $clade ) ) + { + foreach $assembly ( Maasha::BGB::Common::list_assemblies( $options->{ 'user' }, $clade, $genome ) ) + { + foreach $contig ( Maasha::BGB::Common::list_contigs( $options->{ 'user' }, $clade, $genome, $assembly ) ) + { + foreach $track ( Maasha::BGB::Common::list_tracks( $options->{ 'user' }, $clade, $genome, $assembly, $contig ) ) { + $dir_hash->{ $options->{ 'user' } }->{ $clade }->{ $genome }->{ $assembly }->{ $track } = 1; + } + } + } + } +} + +foreach $clade ( keys %{ $dir_hash->{ $options->{ 'user' } } } ) +{ + foreach $genome ( keys %{ $dir_hash->{ $options->{ 'user' } }->{ $clade } } ) + { + foreach $assembly ( keys %{ $dir_hash->{ $options->{ 'user' } }->{ $clade }->{ $genome } } ) + { + foreach $track ( keys %{ $dir_hash->{ $options->{ 'user' } }->{ $clade }->{ $genome }->{ $assembly } } ) + { + $record = { + USER => $options->{ 'user' }, + CLADE => $clade, + GENOME => $genome, + ASSEMBLY => $assembly, + TRACK => $track, + }; + + Maasha::Biopieces::put_record( $record, $out ); + } + } + } +} + + +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_conf/bashrc b/bp_conf/bashrc index 0a113ae..62e6d22 100644 --- a/bp_conf/bashrc +++ b/bp_conf/bashrc @@ -16,6 +16,10 @@ export BP_C="$BP_DIR/code_c" # Direcotory with C code. export BP_PYTHON="$BP_DIR/code_python" # Direcotory with Pyton code. export BP_RUBY="$BP_DIR/code_ruby" # Direcotory with Ruby code. +### This is the directory with the document root fro the Biopieces Genome Browser: + +export BP_WWW="$BP_DIR/www" # Direcotory with Biopieces Genome Browser. + ### Here we add the biopiece variable to the existing PATH. export PATH="$PATH:$BP_BIN" diff --git a/code_perl/Maasha/BGB/Common.pm b/code_perl/Maasha/BGB/Common.pm new file mode 100644 index 0000000..aa5842c --- /dev/null +++ b/code_perl/Maasha/BGB/Common.pm @@ -0,0 +1,355 @@ +package Maasha::BGB::Common; + +# Copyright (C) 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +# Common routines for manipulating the Biopieces Genome Browser. + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +use warnings; +use strict; +use Data::Dumper; +use Maasha::Common; +use Maasha::Filesys; +use Maasha::Biopieces; + +use vars qw( @ISA @EXPORT ); + +@ISA = qw( Exporter ); + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +sub list_user_dir +{ + # Martin A. Hansen, December 2009. + + # List all users directories in the ~/Data/Users + # directory with full path. + + # Returns a list. + + my ( @dirs, @users ); + + Maasha::Common::error( 'BP_WWW not set in environment' ) if not $ENV{ 'BP_WWW' }; + + @dirs = Maasha::Filesys::ls_dirs( "$ENV{ 'BP_WWW' }/Data/Users" ); + + @users = grep { $_ !~ /\/\.\.?$/ } @dirs; + + return wantarray ? @users : \@users; +} + + +sub list_users +{ + # Martin A. Hansen, December 2009. + + # List all users in ~/Data/Users + + # Returns a list. + + my ( @dirs, $dir, @users ); + + @dirs = list_user_dir(); + + foreach $dir ( @dirs ) { + push @users, ( split "/", $dir )[ -1 ]; + } + + return wantarray ? @users : \@users; +} + + +sub list_clade_dir +{ + # Martin A. Hansen, December 2009. + + # List all clades for a given user in ~/Data/Users + + my ( $user, # user for which to return clades + ) = @_; + + # Returns a list. + + my ( @dirs, @clades ); + + Maasha::Common::error( 'BP_WWW not set in environment' ) if not $ENV{ 'BP_WWW' }; + Maasha::Common::error( 'no user specified' ) if not $user; + + @dirs = Maasha::Filesys::ls_dirs( "$ENV{ 'BP_WWW' }/Data/Users/$user" ); + + @clades = grep { $_ !~ /\/\.\.?$/ } @dirs; + + return wantarray ? @clades : \@clades; +} + + +sub list_clades +{ + # Martin A. Hansen, December 2009. + + # List all clades for a given user in ~/Data/Users + + my ( $user, # user for which to return clades + ) = @_; + + # Returns a list. + + my ( @dirs, $dir, @clades ); + + @dirs = list_clade_dir( $user ); + + foreach $dir ( @dirs ) { + push @clades, ( split "/", $dir )[ -1 ]; + } + + return wantarray ? @clades : \@clades; +} + + +sub list_genome_dir +{ + # Martin A. Hansen, December 2009. + + # List all genomes for a given user and clade in ~/Data/Users + + my ( $user, # user for which to return genomes + $clade, # clade for which to return genomes + ) = @_; + + # Returns a list. + + my ( @dirs, @genomes ); + + Maasha::Common::error( 'BP_WWW not set in environment' ) if not $ENV{ 'BP_WWW' }; + Maasha::Common::error( 'no user specified' ) if not $user; + Maasha::Common::error( 'no clade specified' ) if not $clade; + + @dirs = Maasha::Filesys::ls_dirs( "$ENV{ 'BP_WWW' }/Data/Users/$user/$clade" ); + + @genomes = grep { $_ !~ /\/\.\.?$/ } @dirs; + + return wantarray ? @genomes : \@genomes; +} + + +sub list_genomes +{ + # Martin A. Hansen, December 2009. + + # List all genomes for a given user and clade in ~/Data/Users + + my ( $user, # user for which to return genomes + $clade, # clade for which to return genomes + ) = @_; + + # Returns a list. + + my ( @dirs, $dir, @genomes ); + + @dirs = list_genome_dir( $user, $clade ); + + foreach $dir ( @dirs ) { + push @genomes, ( split "/", $dir )[ -1 ]; + } + + return wantarray ? @genomes : \@genomes; +} + + +sub list_assembly_dir +{ + # Martin A. Hansen, December 2009. + + # List all assemblies for a given user and clade and genome in ~/Data/Users + + my ( $user, # user for which to return assemblies + $clade, # clade for which to return assemblies + $genome, # genome for which to return assemblies + ) = @_; + + # Returns a list. + + my ( @dirs, @assemblies ); + + Maasha::Common::error( 'BP_WWW not set in environment' ) if not $ENV{ 'BP_WWW' }; + Maasha::Common::error( 'no user specified' ) if not $user; + Maasha::Common::error( 'no clade specified' ) if not $clade; + Maasha::Common::error( 'no genome specified' ) if not $genome; + + @dirs = Maasha::Filesys::ls_dirs( "$ENV{ 'BP_WWW' }/Data/Users/$user/$clade/$genome" ); + + @assemblies = grep { $_ !~ /\/\.\.?$/ } @dirs; + + return wantarray ? @assemblies : \@assemblies; +} + + +sub list_assemblies +{ + # Martin A. Hansen, December 2009. + + # List all assemblies for a given user and clade and genome in ~/Data/Users + + my ( $user, # user for which to return assemblies + $clade, # clade for which to return assemblies + $genome, # genome for which to return assemblies + ) = @_; + + # Returns a list. + + my ( @dirs, $dir, @assemblies ); + + @dirs = list_assembly_dir( $user, $clade, $genome ); + + foreach $dir ( @dirs ) { + push @assemblies, ( split "/", $dir )[ -1 ]; + } + + return wantarray ? @assemblies : \@assemblies; +} + + +sub list_contig_dir +{ + # Martin A. Hansen, December 2009. + + # List all assemblies for a given user->clade->genome->assembly in ~/Data/Users + + my ( $user, # user for which to return contigs + $clade, # clade for which to return contigs + $genome, # genome for which to return contigs + $assembly, # assembly for which to return contigs + ) = @_; + + # Returns a list. + + my ( @dirs, @contigs ); + + Maasha::Common::error( 'BP_WWW not set in environment' ) if not $ENV{ 'BP_WWW' }; + Maasha::Common::error( 'no user specified' ) if not $user; + Maasha::Common::error( 'no clade specified' ) if not $clade; + Maasha::Common::error( 'no genome specified' ) if not $genome; + Maasha::Common::error( 'no assembly specified' ) if not $assembly; + + @dirs = Maasha::Filesys::ls_dirs( "$ENV{ 'BP_WWW' }/Data/Users/$user/$clade/$genome/$assembly" ); + + @contigs = grep { $_ !~ /\/\.\.?$/ } @dirs; + + return wantarray ? @contigs : \@contigs; +} + + +sub list_contigs +{ + # Martin A. Hansen, December 2009. + + # List all contigs for a given user->clade->genome->assembly in ~/Data/Users + + my ( $user, # user for which to return contigs + $clade, # clade for which to return contigs + $genome, # genome for which to return contigs + $assembly, # assembly for which to return contigs + ) = @_; + + # Returns a list. + + my ( @dirs, $dir, @contigs ); + + @dirs = list_contig_dir( $user, $clade, $genome, $assembly ); + + foreach $dir ( @dirs ) { + push @contigs, ( split "/", $dir )[ -1 ]; + } + + return wantarray ? @contigs : \@contigs; +} + + +sub list_track_dir +{ + # Martin A. Hansen, December 2009. + + # List all tracks for a given user->clade->genome->assembly->contig in ~/Data/Users + + my ( $user, # user for which to return tracks + $clade, # clade for which to return tracks + $genome, # genome for which to return tracks + $assembly, # assembly for which to return tracks + $contig, # contig for which to return tracks + ) = @_; + + # Returns a list. + + my ( @dirs, @tracks ); + + Maasha::Common::error( 'BP_WWW not set in environment' ) if not $ENV{ 'BP_WWW' }; + Maasha::Common::error( 'no user specified' ) if not $user; + Maasha::Common::error( 'no clade specified' ) if not $clade; + Maasha::Common::error( 'no genome specified' ) if not $genome; + Maasha::Common::error( 'no assembly specified' ) if not $assembly; + Maasha::Common::error( 'no contig specified' ) if not $contig; + + if ( -d "$ENV{ 'BP_WWW' }/Data/Users/$user/$clade/$genome/$assembly/$contig/Tracks" ) { + @dirs = Maasha::Filesys::ls_dirs( "$ENV{ 'BP_WWW' }/Data/Users/$user/$clade/$genome/$assembly/$contig/Tracks" ); + } + + @tracks = grep { $_ !~ /\/\.\.?$/ } @dirs; + + return wantarray ? @tracks : \@tracks; +} + + +sub list_tracks +{ + # Martin A. Hansen, December 2009. + + # List all tracks for a given user->clade->genome->assembly->contig in ~/Data/Users + + my ( $user, # user for which to return tracks + $clade, # clade for which to return tracks + $genome, # genome for which to return tracks + $assembly, # assembly for which to return tracks + $contig, # contig for which to return tracks + ) = @_; + + # Returns a list. + + my ( @dirs, $dir, @tracks ); + + @dirs = list_track_dir( $user, $clade, $genome, $assembly, $contig ); + + foreach $dir ( @dirs ) { + push @tracks, ( split "/", $dir )[ -1 ]; + } + + return wantarray ? @tracks : \@tracks; +} +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +1; -- 2.39.2