Bio-Maxd

 view release on metacpan or  search on metacpan

lib/Bio/Maxd.pm  view on Meta::CPAN

package Bio::Maxd;

require 5.005_62;
use strict;
use warnings;
use File::Basename;

require Exporter;
use AutoLoader qw(AUTOLOAD);

our @ISA = qw(Exporter);

our %EXPORT_TAGS = ( 'all' => [ qw(
) ] );

our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );

our @EXPORT = qw(
);
our $VERSION = '0.04';

sub new {
  my $self=shift;
  my $class=ref($self) || $self;
  my(%data,$tag);
  while (@_) {$tag = shift; if ($tag =~ /^-/) {$tag =~ s/^-//;$data{lc($tag)} = shift;}}
  $data{'dbase'} = "maxd" if (!$data{'dbase'});
  if (!$data{'host'}) {
    use Sys::Hostname;
    my $hostname = hostname();
    $data{'host'} = $data{'host'} || $ENV{'MAXD_HOSTDB'} || $hostname || "localhost";
  }
  if (!$data{'user'} || !$data{'pass'}) { 
    ($data{'user'},$data{'pass'}) = split(/\//,$ENV{'MAXD_USERID'});
  }
  $data{'dbh'} = _dbconnect ($data{'host'},$data{'dbase'},$data{'user'},$data{'pass'}); 
  # verify special tables
  my($ok,$tname);
  my $st = "show tables";
  my $sh = $data{'dbh'}->prepare($st);
  my $rv = $sh->execute;
  while($tname= $sh->fetchrow_array) {
    if ($tname =~ /^Image_Seq$/i) { $ok = 1; last; }
  }
  if (!$ok) {
    print STDERR "WARNING: Run 'extendMaxD' to configure database\n";
    $data{'dbh'} = undef;
  }
  $self = bless {} => $class;
  foreach $tag (keys %data) { $self->{$tag} = $data{$tag}; }
  return $self;
}

sub export { 
  my $self=shift;
  my(%data,$tag);
  foreach $tag (keys %{$self}) { $data{$tag} = $self->{$tag};}
  while (@_) {$tag = shift; if ($tag =~ /^-/) {$tag =~ s/^-//;$data{lc($tag)} = shift;}}
  return 0 if (ref($data{'dbh'}) ne "DBI::db");

  # valid submitter ?
  ($data{'submitter_id'},$data{'submitter_name'}) =
            _submitterFromSubmitterData($data{'dbh'},$data{'submitter'});
  return (_error(501,$data{'submitter'})) if ($data{'submitter_id'}< 0);
  print "Submitter:\tname:$data{'submitter_name'}\tID:$data{'submitter_id'}\n"
        if ($data{'verbose'});

  # valid repository URL ?
  $data{'repository_url'} = "." if (!-d $data{'repository_url'});
  $data{'repository_url'} .= "/" . $data{'submitter_name'};
  $data{'repository_url'} =~ s/ +/_/g;
  mkdir($data{'repository_url'},0755);

  # valid experiment ?  
  return 0 if (!$data{'experiment'});
  ($data{'experiment_id'},$data{'experiment_name'})
       = _experimentIDfromExperiment($data{'dbh'},$data{'experiment'},
       $data{'submitter_id'});
  return (_error(502,"experiment $data{'experiment'} unknown"))
        if ($data{'experiment_id'} < 0);
  print "Experiment:\tname:$data{'experiment_name'}\tID:$data{'experiment_id'}\n"
        if ($data{'verbose'});

  # valid array type ?
  return 0 if (not defined $data{'array_type'});
  $data{'array_name'} = $data{'array_type'} if (!$data{'array_name'});
  $data{'array_id'} = $data{'array_type'} if ($data{'array_type'} =~ /^\d+/);
  $data{'array_id'} = _arrayIDfromArrayType($data{'dbh'},$data{'array_type'})
                      if (!$data{'array_id'});
  return (_error(502,"array $data{'array_type'} unknown")) if ($data{'array_id'} < 0);
  print "Array Type:\tname:$data{'array_type'}\tID:$data{'array_id'}\n"
        if ($data{'verbose'});

  #valid export format ?
  $data{'format'} = lc($data{'format'});
  $data{'format'} = "genespring" if (!$data{'format'});
  return (_error(501,"unknown export format $data{'format'}"))
    if ($data{'format'} !~ /\bgenespring\b/);
  my $templateDir = $ENV{'MAXD_TEMPLATES'} || ".";
  return (_error(501,"unable to find template for $data{'format'}"))
    if (!-f "$templateDir/$data{'format'}\.tmpl");
  print "Export format:\t$data{'format'}\n" if ($data{'verbose'});

  print "collecting hybridisation\n" if ($data{'verbose'});
  my %hybD = _hybridisationByExperimentIDArrayID($data{'dbh'},
              $data{'experiment_id'},$data{'array_id'});
  print "collecting tissue\n" if ($data{'verbose'});
  my(%TisSrc) = _sourceNameTissueByExperiment($data{'dbh'},\%hybD);
  my $numOfExp = scalar(keys %hybD);

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.061 second using v1.00-cache-1.14-grep-28634ff-cpan-ac32402124b )