Skip to content

Commit

Permalink
fixing issue with location copying in getSequenceDataBetweenRange and…
Browse files Browse the repository at this point in the history
… adding tests; links TeselaGen/openVectorEditor#634
  • Loading branch information
tnrich committed Mar 16, 2021
1 parent df7f203 commit af6d514
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/getSequenceDataBetweenRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ function getAnnotationsBetweenRange(
shouldExcludePartial
) {
return flatMap(annotationsToBeAdjusted, function(annotation) {
if (annotation.locations && annotation.locations.length) {
annotation.locations = getAnnotationsBetweenRange(
annotation.locations,
range,
maxLength,
shouldExcludePartial
);
}
//map through every annotation and get the overlap of the annotation with the range
const overlaps = getZeroedRangeOverlaps(annotation, range, maxLength).map(
overlap => {
Expand Down
80 changes: 80 additions & 0 deletions src/getSequenceDataBetweenRange.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,86 @@ describe("getSequenceDataBetweenRange", function() {
]
});
});
it("feature with locations, non circular range", function() {
const res = getSequenceDataBetweenRange(
{
sequence: "atgcatgca",
features: [
{
start: 0,
end: 7,
locations: [
{ start: 0, end: 1 },
{ start: 2, end: 5 },
{ start: 6, end: 7 }
],
name: "happy"
}
]
},
{
start: 2,
end: 3
}
);
res.should.containSubset({
sequence: "gc",
features: [
{
start: 0,
end: 1,
locations: [
{
start: 0,
end: 1
}
],
name: "happy"
}
]
});
});
it("feature with locations, non circular enclosing range", function() {
const res = getSequenceDataBetweenRange(
{
sequence: "gggatgcatgca",
// 012345678901
// ffffff
// ll ll
// ccccccccc
// 012345678
features: [
{
start: 5,
end: 10,
locations: [
{ start: 5, end: 6 },
{ start: 9, end: 10 }
],
name: "happy"
}
]
},
{
start: 3,
end: 11
}
);
res.should.containSubset({
sequence: "atgcatgca",
features: [
{
start: 2,
end: 7,
locations: [
{ start: 2, end: 3 },
{ start: 6, end: 7 }
],
name: "happy"
}
]
});
});
it("non circular feature, circular range", function() {
const res = getSequenceDataBetweenRange(
{
Expand Down

0 comments on commit af6d514

Please sign in to comment.