Guest User

Untitled

a guest
Jul 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3.  
  4. use Bio::EnsEMBL::Gene;
  5. use Bio::EnsEMBL::Registry;
  6. use Bio::EnsEMBL::Utils::SqlHelper;
  7. use Benchmark qw(cmpthese);
  8.  
  9. Bio::EnsEMBL::Registry->load_registry_from_db(
  10. -HOST => 'mysql.ebi.ac.uk',
  11. -PORT => 4157,
  12. -USER => 'anonymous',
  13. -DB_VERSION => 60
  14. );
  15.  
  16. my $count = 50;
  17.  
  18. my $dba = Bio::EnsEMBL::Registry->get_DBAdaptor('arabidopsis_thaliana', 'core');
  19. my $h = Bio::EnsEMBL::Utils::SqlHelper->new(-DB_CONNECTION => $dba->dbc());
  20.  
  21. my $sql = <<'SQL';
  22. select gene_id, seq_region_start, seq_region_end, seq_region_strand, biotype, canonical_transcript_id
  23. from gene
  24. SQL
  25.  
  26. my $callbacks = sub {
  27. my $genes = $h->execute(
  28. -SQL => $sql,
  29. -CALLBACK => sub {
  30. my ($row) = @_;
  31.  
  32. my ($gene_id, $seq_region_start, $seq_region_end,
  33. $seq_region_strand, $biotype, $canonical_transcript_id) = @{$row};
  34.  
  35. my $data = {
  36. biotype => $biotype,
  37. start => $seq_region_start,
  38. end => $seq_region_end,
  39. strand => $seq_region_strand,
  40. dbID => $gene_id,
  41. canonical_transcript_id => $canonical_transcript_id
  42. };
  43. return Bio::EnsEMBL::Gene->new_fast($data);
  44. }
  45. );
  46. };
  47.  
  48. my $manually = sub {
  49. my $genes = $h->execute_with_sth(
  50. -SQL => $sql,
  51. -CALLBACK => sub {
  52. my ($sth) = @_;
  53. my @genes;
  54. $sth->execute();
  55.  
  56. while(my $row = $sth->fetchrow_arrayref()) {
  57.  
  58. my ($gene_id, $seq_region_start, $seq_region_end,
  59. $seq_region_strand, $biotype, $canonical_transcript_id) = @{$row};
  60.  
  61. my $data = {
  62. biotype => $biotype,
  63. start => $seq_region_start,
  64. end => $seq_region_end,
  65. strand => $seq_region_strand,
  66. dbID => $gene_id,
  67. canonical_transcript_id => $canonical_transcript_id
  68. };
  69. my $gene = Bio::EnsEMBL::Gene->new_fast($data);
  70.  
  71. push(@genes, $gene);
  72. }
  73.  
  74. return \@genes;
  75. }
  76. );
  77. };
  78.  
  79. cmpthese($count, {
  80. 'Using Callbacks' => $callbacks,
  81. 'Manually' => $manually,
  82. });
Add Comment
Please, Sign In to add comment