Bio-DB-GFF
view release on metacpan or search on metacpan
bin/bp_bulk_load_gff view on Meta::CPAN
sub insert_sequence {
my $self = shift;
my ($id,$offset,$seq) = @_;
print "$id\t$offset\t$seq\n";
}
package main;
$main::VERSION = '1.7.4';
eval "use Time::HiRes"; undef $@;
my $timer = defined &Time::HiRes::time;
my $bWINDOWS = 0; # Boolean: is this a MSWindows operating system?
if ($^O =~ /MSWin32/i) {
$bWINDOWS = 1;
}
my ($DSN,$ADAPTOR,$FORCE,$USER,$PASSWORD,$FASTA,$LOCAL,$MAX_BIN,$GROUP_TAG,$LONG_LIST,$MUNGE,$TMPDIR);
GetOptions ('database:s' => \$DSN,
'adaptor:s' => \$ADAPTOR,
bin/bp_bulk_load_gff view on Meta::CPAN
my $FEATURES = 0;
my %tmpfiles; # keep track of temporary fasta files
my $count;
my $fasta_sequence_id;
my $gff3;
my $current_file; #used to reset GFF3 flag in mix of GFF and GFF3 files
$db->preferred_groups(split (/[,\s]+/,$GROUP_TAG)) if defined $GROUP_TAG;
my $last = Time::HiRes::time() if $timer;
my $start = $last;
# avoid hanging on standalone --fasta load
if (!@ARGV) {
$FH{NULL} = IO::File->new(">$tmpdir/null");
push @ARGV, "$tmpdir/null";
}
my ($cmap_db);
if ($use_mysqlcmap){
bin/bp_bulk_load_gff view on Meta::CPAN
$FH{ FTYPE() }->print( join("\t",$ftypeid,$method,$source),"\n" ) unless $DONE{"T$ftypeid"}++;
foreach (@$attributes) {
my ($key,$value) = @$_;
my $attributeid = $ATTRIBUTEID{$key} ||= $ATTRIBUTEID++;
$FH{ FATTRIBUTE() }->print( join("\t",$attributeid,$key),"\n" ) unless $DONE{"A$attributeid"}++;
$FH{ FATTRIBUTE_TO_FEATURE() }->print( join("\t",$fid,$attributeid,$value),"\n");
}
if ( $fid % 1000 == 0) {
my $now = Time::HiRes::time() if $timer;
my $elapsed = $timer ? sprintf(" in %5.2fs",$now - $last) : '';
$last = $now;
print STDERR "$fid features parsed$elapsed...";
print STDERR -t STDOUT && !$ENV{EMACS} ? "\r" : "\n";
}
}
}
$FH{FASTA}->close if exists $FH{FASTA};
for my $file (@fasta) {
bin/bp_bulk_load_gff view on Meta::CPAN
if ($use_pg) {
$FH{FDATA() }->print("\\.\n\n");
$FH{FTYPE() }->print("\\.\n\n");
$FH{FGROUP() }->print("\\.\n\n");
$FH{FATTRIBUTE() }->print("\\.\n\n");
$FH{FATTRIBUTE_TO_FEATURE()}->print("\\.\n\n");
}
$_->close foreach values %FH;
printf STDERR "Total parse time %5.2fs\n",(Time::HiRes::time() - $start) if $timer;
warn "Loading feature data and analyzing tables. You may see RDBMS messages here...\n";
if ($use_pg){
warn "Loading feature data. You may see Postgres comments...\n";
foreach (@files) {
my $file = "$tmpdir/$_.$$";
$AUTH ? system("psql $AUTH -f $file $DBNAME")
: system('psql','-f', $file, $DBNAME);
bin/bp_bulk_load_gff view on Meta::CPAN
my $sql = join ('; ',
"lock tables $table write",
"delete from $table",
"load data $LOCAL infile '$tmpdir/$f.$$' replace into table $table $TERMINATEDBY",
"unlock tables");
my $command = MYSQL . qq[$AUTH -s -e "$sql"];
$command =~ s/\n/ /g;
$success &&= system($command) == 0;
unlink "$tmpdir/$f.$$";
}
printf STDERR "Total load time %5.2fs\n",(time() - $start) if $timer;
print STDERR "done...\n";
print STDERR "Analyzing/optimizing tables. You will see database messages...\n";
$start = time();
my $sql = '';
for my $f (@files) {
my $table = function_to_table($f,$ADAPTOR);
$sql .= "analyze table $table;";
}
my $command = MYSQL . qq[$AUTH -N -s -e "$sql"];
bin/bp_fast_load_gff view on Meta::CPAN
sub insert_sequence {
my $self = shift;
my ($id,$offset,$seq) = @_;
print join "\t",$id,$offset,$seq,"\n";
}
package main;
$main::VERSION = '1.7.4';
eval "use Time::HiRes"; undef $@;
my $timer = defined &Time::HiRes::time;
my ($DSN,$CREATE,$USER,$PASSWORD,$FASTA,$FAILED,$LOCAL,%PID,$MAX_BIN,$GROUP_TAG,$LONG_LIST,$MUNGE,$TMPDIR,$SUMMARY_STATS);
if ($DO_FAST) {
$SIG{CHLD} = sub {
while ((my $child = waitpid(-1,&WNOHANG)) > 0) {
delete $PID{$child} or next;
$FAILED++ if $? != 0;
}
}
bin/bp_fast_load_gff view on Meta::CPAN
print STDERR "opening load file for writing...";
$FH{$_} = IO::File->new($file,'>') or die $_,": $!";
print STDERR "ok\n";
$FH{$_}->autoflush;
}
print STDERR "Fast loading enabled\n" if $DO_FAST;
my ($count,$gff3,$last,$start,$beginning,$current_file);
$last = Time::HiRes::time() if $timer;
$beginning = $start = $last;
# avoid hanging on standalone --fasta load
if (!@ARGV) {
$FH{NULL} = IO::File->new(">$tmpdir/null");
push @ARGV, "$tmpdir/null";
}
while (<>) {
bin/bp_fast_load_gff view on Meta::CPAN
$FH{ FTYPE() }->print( join("\t",$ftypeid,$method,$source),"\n" ) unless $DONE{"ftype$;$ftypeid"}++;
foreach (@$attributes) {
my ($key,$value) = @$_;
my $attributeid = $ATTRIBUTEID{lc $key} ||= $ATTRIBUTEID++;
$FH{ FATTRIBUTE() }->print( join("\t",$attributeid,$key),"\n" ) unless $DONE{"fattribute$;$attributeid"}++;
$FH{ FATTRIBUTE_TO_FEATURE() }->print( join("\t",$fid,$attributeid,$value),"\n");
}
if ( $FEATURES % 1000 == 0) {
my $now = Time::HiRes::time() if $timer;
my $elapsed = $timer ? sprintf(" in %5.2fs",$now - $last) : '';
$last = $now;
print STDERR "$fid features parsed$elapsed...";
print STDERR -t STDOUT && !$ENV{EMACS} ? "\r" : "\n";
}
}
}
$FH{FASTA}->close if exists $FH{FASTA};
printf STDERR "Feature load time %5.2fs\n",(Time::HiRes::time() - $start) if $timer;
$start = time();
for my $fasta (@fasta) {
warn "Loading fasta ",(-d $fasta?"directory":"file"), " $fasta\n";
my $old = select($FH{FDNA()});
my $loaded = $db->load_fasta($fasta);
warn "$fasta: $loaded records loaded\n";
select $old;
}
printf STDERR "Fasta load time %5.2fs\n",(Time::HiRes::time() - $start) if $timer;
$start = time();
my $success = 1;
if ($DO_FAST) {
warn "Indexing and analyzing tables. This may take some time (you may see database messages during the process)...\n";
}
$_->close foreach values %FH;
if (!$DO_FAST) {
bin/bp_fast_load_gff view on Meta::CPAN
}
# wait for children
while (%PID) {
sleep;
}
$success &&= !$FAILED;
cleanup();
printf STDERR "Total parse & load time %5.2fs\n",(Time::HiRes::time() - $beginning) if $timer;
if ($success) {
print "SUCCESS: $FEATURES features successfully loaded\n";
exit 0;
} else {
print "FAILURE: Please see standard error for details\n";
exit -1;
}
if ($SUMMARY_STATS) {
( run in 1.432 second using v1.01-cache-2.11-cpan-87723dcf8b7 )