Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
24be8012
Commit
24be8012
authored
13 years ago
by
Nathan Johnson
Browse files
Options
Downloads
Patches
Plain Diff
moved Slice iterator stuff to BaseFeatureADaptor
parent
60cda8aa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/Bio/EnsEMBL/Utils/Iterator.pm
+33
-133
33 additions, 133 deletions
modules/Bio/EnsEMBL/Utils/Iterator.pm
with
33 additions
and
133 deletions
modules/Bio/EnsEMBL/Utils/Iterator.pm
+
33
−
133
View file @
24be8012
...
...
@@ -71,26 +71,15 @@ use Bio::EnsEMBL::Utils::Exception qw(throw);
=head2 new
Arg
s [1]: Either:
a) A CODE reference representing the Iterator, or a Slice
fetch method to be iterated over using sub Slices.
b) An ARRAY reference to be
iterat
ed
over
If the argument is not defined then we return an 'empty'
Arg
ument : either a coderef representing the iterator, in which case this
anonymous subroutine is assumed to return the next object in the
set when called and to return undef when the set is exhausted,
or an arrayref, in which case we return an
iterat
or
over
this
array.
If the argument is not defined then we return an 'empty'
iterator that immediately returns undef
Args [2]: Optional: Feature Adaptor which was the source of the Slice
fetch CODE ref
Args [3]: Optional: Slice fetch method params ARRAY ref
Args [4]: Optional: Slice parameter index in param arrays. Default=0
Args [5]: Optional: sub Slice chunk size. Default=500000
Example :
dbID Iterator:
my @dbIDs = fetch_relevant_dbIDs();
my $iterator = Bio::EnsEMBL::Utils::Iterator->new(
...
...
@@ -102,135 +91,46 @@ use Bio::EnsEMBL::Utils::Exception qw(throw);
probably be smarter about batching up queries to minimise trips to
the database. See examples in the Variation API.
Slice Iterator:
my $iter = Bio::EnsEMBL::Utils::Iterator->new
($feat_adaptor->can('fetch_all_by_Slice'),
$feat_adaptor,
$fetch_all_by_Slice_params_ref,
0,#Slice idx
#500 #chunk length
);
Description: Constructor, creates a new iterator object
Returntype : Bio::EnsEMBL::Utils::Iterator instance
Exceptions : thrown if the supplied argument is not the expected
Caller : general
Status :
at risk
Status :
Experimental
=cut
sub
new
{
my
(
$class
,
$ref
,
$adaptor
,
$params_ref
,
$slice_param_idx
,
$chunk_size
)
=
@_
;
sub
new
{
my
$class
=
shift
;
my
$arg
=
shift
;
my
$coderef
;
if
(
!
defined
$ref
)
{
# if the user doesn't supply an argument, we create a
# simple 'empty' iterator that immediately returns undef
$coderef
=
sub
{
return
undef
};
}
elsif
(
ref
(
$ref
)
eq
'
ARRAY
')
{
# if the user supplies an arrayref as an argument, we
# create an iterator over this array
$coderef
=
sub
{
return
shift
@$ref
};
}
elsif
(
ref
(
$ref
)
eq
'
CODE
')
{
if
(
!
defined
$adaptor
)
{
# Standard Iterator
$coderef
=
$ref
;
}
else
{
# Slice chunk Iterator
if
(
!
(
ref
(
$adaptor
)
&&
$adaptor
->
isa
('
Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor
'))
)
{
throw
('
You must pass a valid Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor
');
}
if
(
!
(
$params_ref
&&
ref
(
$params_ref
)
eq
'
ARRAY
'))
{
#Don't need to check size here so long as we have valid Slice
throw
('
You must pass a method params ARRAYREF
');
}
$slice_param_idx
=
0
if
(
!
defined
$slice_param_idx
);
my
$slice
=
$params_ref
->
[
$slice_param_idx
];
if
(
!
(
defined
$slice
&&
ref
(
$slice
)
eq
'
Bio::EnsEMBL::Slice
')
)
{
throw
('
You must pass a valid Bio::EnsEMBL::Slice
'
.
'
in your method params and a valid slice param idx arg
');
}
$chunk_size
||=
1000000
;
my
@feat_cache
;
my
$finished
=
0
;
my
$start
=
1
;
#local coord for sub slice
my
$end
=
$slice
->
length
;
my
$num_overlaps
=
0
;
$coderef
=
sub
{
while
(
scalar
(
@feat_cache
)
==
0
&&
!
$finished
)
{
my
$new_end
=
$start
+
$chunk_size
;
if
(
$new_end
>=
$end
)
{
# this is our last chunk
$new_end
=
$end
;
$finished
=
1
;
}
#Chunk by sub slicing
my
$sub_slice
=
$slice
->
sub_Slice
(
$start
,
$new_end
);
$params_ref
->
[
$slice_param_idx
]
=
$sub_slice
;
@feat_cache
=
@
{
$ref
->
(
$adaptor
,
@$params_ref
)};
#Remove & count overlapping features
splice
(
@feat_cache
,
0
,
$num_overlaps
)
if
(
$num_overlaps
);
my
$i
;
if
(
scalar
(
@feat_cache
)
>
0
)
{
my
$feat_end
=
$feat_cache
[
$#feat_cache
]
->
end
;
my
$slice_end
=
$sub_slice
->
end
;
$num_overlaps
=
0
;
for
(
$i
=
$#feat_cache
;
$i
>=
0
;
$i
--
)
{
if
(
$feat_end
>
$slice_end
)
{
$feat_end
=
$feat_cache
[
$i
]
->
end
;
$num_overlaps
++
;
}
else
{
last
;
}
}
}
# update the start coordinate
$start
=
$new_end
+
1
;
}
#this maybe returning from an undef cache
#Need to sub this out even more?
return
shift
@feat_cache
;
};
}
}
else
{
throw
("
The supplied argument does not look like an arrayref or a coderef
"
.
ref
(
$ref
));
}
return
bless
{
sub
=>
$coderef
},
$class
;
if
(
not
defined
$arg
)
{
# if the user doesn't supply an argument, we create a
# simple 'empty' iterator that immediately returns undef
$coderef
=
sub
{
return
undef
};
}
elsif
(
ref
$arg
eq
'
ARRAY
')
{
# if the user supplies an arrayref as an argument, we
# create an iterator over this array
$coderef
=
sub
{
return
shift
@$arg
};
}
elsif
(
ref
$arg
eq
'
CODE
'){
$coderef
=
$arg
;
}
else
{
throw
("
The supplied argument does not look like an arrayref or a coderef
"
.
(
ref
$arg
))
}
my
$self
=
{
sub
=>
$coderef
};
return
bless
$self
,
$class
;
}
=head2 next
Example : $obj = $iterator->next
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment