Bio-BioStudio
view release on metacpan or search on metacpan
lib/Bio/BioStudio/GBrowse.pm view on Meta::CPAN
sub _path_in_repository
{
my ($chromosome) = @_;
my $path = _dir_in_repository($chromosome);
$path .= $chromosome->name . ".conf";
return $path;
}
=head2 _create_chromosome_conf()
=cut
sub _create_chromosome_conf
{
my ($chromosome) = @_;
my $name = $chromosome->name();
#Grab chromosome configuration template
my $template_p = _gbrowse_template();
open (my $BSCONF, '<', $template_p)
|| croak "BSERROR: Can't open configuration template $template_p : $OS_ERROR";
my $BSref = do {local $/ = <$BSCONF>};
close $BSCONF;
#make edits
#my $dbengine = $chromosome->db_engine();
#if ($dbengine ne 'memory')
#{
# my $adaptor = 'DBI::' . $dbengine;
# my $handlestring = '-dsn ' . _connectstring($name, $dbengine);
# my $userstring = '-user ' . _user($dbengine);
# my $passstring = '-pass ' . _pass($dbengine);
# $BSref =~ s{\*ENGINE\*}{$adaptor}msixg;
# $BSref =~ s{\*DBARG2\*}{$handlestring}msixg;
# $BSref =~ s{\*DBARG3\*}{$userstring}msixg;
# $BSref =~ s{\*DBARG4\*}{$passstring}msixg;
#}
#else
#{
my $adaptor = 'DBI::SQLite';
my $dsn = '-dsn dbi:SQLite:database=' . $chromosome->path_to_DB();
$BSref =~ s{\*ENGINE\*}{$adaptor}msixg;
$BSref =~ s{\*DBARG2\*}{$dsn}msixg;
$BSref =~ s{\*DBARG3\*}{}msixg;
$BSref =~ s{\*DBARG4\*}{}msixg;
#}
my $seqid = $chromosome->seq_id();
my $landmark = $seqid . q{:1..} . $chromosome->len();
$BSref =~ s{\*LANDMARK\*}{$landmark}msixg;
$BSref =~ s{\*VERSION\*}{$name}msixg;
#$BSref =~ s{\*VERSIONNOTE\*}{}msixg;
#Compute chromosome confpath, create directories if path is new
my $conf_p = _path_in_repository($chromosome);
#Write out chromosome configuration file
open (my $CONF, '>', $conf_p);
system "chmod 777 $conf_p";
print $CONF $BSref;
close $CONF;
return $conf_p;
}
=head2 _add_to_GBrowse_conf()
=cut
sub _add_to_GBrowse_conf
{
my ($chromosome) = @_;
my $chrname = $chromosome->name();
my $conf_p = _path_in_repository($chromosome);
my $gbconf_p = _path_to_conf();
#Read GBrowse conf file;
open (my $CONFIN, '<', $gbconf_p)
|| croak "BSERROR: Can't open GBrowse conf $gbconf_p : $OS_ERROR";
my $GBref = do {local $/ = <$CONFIN>};
close $CONFIN;
#if it doesn't have the chromosome, add a section
if ($GBref !~ m{\[$chrname\]}msix)
{
open (my $CONFOUT, '>>', $gbconf_p)
|| croak "BSERROR: can't write GBrowse conf $gbconf_p : $OS_ERROR";
print $CONFOUT "\n[$chrname]\n";
print $CONFOUT "description = $chrname\n";
print $CONFOUT "path = $conf_p\n";
close $CONFOUT;
}
return 1;
}
=head2 _parse_gbrowse_colors()
=cut
sub _parse_gbrowse_colors
{
my $bs_dir = Bio::BioStudio::ConfigData->config('conf_path') . 'gbrowse/';
my $path = $bs_dir . 'GBrowse_colors.yaml';
my $colorhref = {};
return $colorhref unless (-e $path);
my $yaml = YAML::Tiny->read($path);
foreach my $tag (keys %{$yaml->[0]})
{
$colorhref->{$tag} = $yaml->[0]->{$tag};
}
return $colorhref;
}
=head2 get_cache_handle
=cut
sub get_cache_handle
( run in 2.733 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )