BioPerl

 view release on metacpan or  search on metacpan

Bio/DB/TFBS/transfac_pro.pm  view on Meta::CPAN

=head2 get_matrix_ids

 Title   : get_matrix_ids
 Usage   : my @ids = $obj->get_matrix_ids(-key => $value);
 Function: Get all the matrix ids that are associated with the supplied
           args.
 Returns : list of strings (ids)
 Args    : -key => value, where value is a string id, and key is one of:
           -id -name -site -factor -reference

=cut

sub get_matrix_ids {
    my $self = shift;
    return $self->_get_ids('matrix', @_);
}

=head2 get_factor_ids

 Title   : get_factor_ids
 Usage   : my @ids = $obj->get_factor_ids(-key => $value);
 Function: Get all the factor ids that are associated with the supplied
           args.
 Returns : list of strings (ids)
 Args    : -key => value, where value is a string id, and key is one of:
           -id -name -species -interactors -gene -matrix -site -reference
           NB: -gene only gets factor ids for genes that encode factors

=cut

sub get_factor_ids {
    my $self = shift;
    return $self->_get_ids('factor', @_);
}

=head2 get_fragment_ids

 Title   : get_fragment_ids
 Usage   : my @ids = $obj->get_fragment_ids(-key => $value);
 Function: Get all the fragment ids that are associated with the supplied
           args.
 Returns : list of strings (ids)
 Args    : -key => value, where value is a string id, and key is one of:
           -id -species -gene -factor -reference

=cut

sub get_fragment_ids {
    my $self = shift;
    return $self->_get_ids('fragment', @_);
}

=head2 Helper methods 

=cut

# internal method which does the indexing
sub _build_index {
    my ($self, $dat_dir, $force) = @_;
    
    # MLDBM would give us transparent complex data structures with DB_File,
    # allowing just one index file, but its yet another requirement and we
    # don't strictly need it
    
    my $index_dir = $self->index_directory;
    my $gene_index      = "$index_dir/gene.dat.index";
    my $reference_index = "$index_dir/reference.dat.index";
    my $matrix_index    = "$index_dir/matrix.dat.index";
    my $factor_index    = "$index_dir/factor.dat.index";
    my $fragment_index  = "$index_dir/fragment.dat.index";
    my $site_index      = "$index_dir/site.dat.index";
    
    my $reference_dat = "$dat_dir/reference.dat";
    if (! -e $reference_index || $force) {
        open my $REF, '<', $reference_dat or $self->throw("Could not read reference file '$reference_dat': $!");
        
        my %references;
        unlink $reference_index;
        my $ref = tie(%references, 'DB_File', $reference_index, O_RDWR|O_CREAT, 0644, $DB_HASH)
            or $self->throw("CCould not open file '$reference_index': $!");
        
        my %pubmed;
        my $reference_pubmed = $reference_index.'.pubmed';
        unlink $reference_pubmed;
        my $pub = tie(%pubmed, 'DB_File', $reference_pubmed, O_RDWR|O_CREAT, 0644, $DB_BTREE)
            or $self->throw("Could not open file '$reference_pubmed': $!");
        
        my %gene;
        my $reference_gene = $gene_index.'.reference';
        unlink $reference_gene;
        my $gene = tie(%gene, 'DB_File', $reference_gene, O_RDWR|O_CREAT, 0644, $DB_BTREE)
            or $self->throw("Could not open file '$reference_gene': $!");
        
        my %site;
        my $reference_site = $site_index.'.reference';
        unlink $reference_site;
        my $site = tie(%site, 'DB_File', $reference_site, O_RDWR|O_CREAT, 0644, $DB_BTREE)
            or $self->throw("Could not open file '$reference_site': $!");
        
        my %fragment;
        my $reference_fragment = $fragment_index.'.reference';
        unlink $reference_fragment;
        my $fragment = tie(%fragment, 'DB_File', $reference_fragment, O_RDWR|O_CREAT, 0644, $DB_BTREE)
            or $self->throw("Could not open file '$reference_fragment': $!");
        
        my %factor;
        my $reference_factor = $factor_index.'.reference';
        unlink $reference_factor;
        my $factor = tie(%factor, 'DB_File', $reference_factor, O_RDWR|O_CREAT, 0644, $DB_BTREE)
            or $self->throw("Could not open file '$reference_factor': $!");
        
        my %matrix;
        my $reference_matrix = $matrix_index.'.reference';
        unlink $reference_matrix;
        my $matrix = tie(%matrix, 'DB_File', $reference_matrix, O_RDWR|O_CREAT, 0644, $DB_BTREE)
            or $self->throw("Could not open file '$reference_matrix': $!");
        
        # skip the first three header lines
        <$REF>; <$REF>; <$REF>;
        
        my @data;



( run in 0.709 second using v1.01-cache-2.11-cpan-39bf76dae61 )