Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node coverage stats deletions #336

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/util/tubemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3241,6 +3241,15 @@ export function coverage(node, allReads) {
let readPathIndex = readVisit[1];
let currRead = allReads[readNum];
let numNodes = currRead.sequenceNew.length;
// identify deletion: if there's a deletion, then those bases must be deleted from total base count
for (let i = 0; i < currRead.sequenceNew.length; i += 1) {
currRead.sequenceNew[i].mismatches.forEach((mm) => {
if (mm.type === "deletion") {
console.log ("this read has a deletion", currRead)
countBases -= mm.length;
}
})
};
// if current node is the last node on the read path, add the finalNodeCoverLength number of bases
if (numNodes === readPathIndex + 1) {
countBases += currRead.finalNodeCoverLength;
Expand All @@ -3255,12 +3264,30 @@ export function coverage(node, allReads) {
// indicating read's starting and ending points within the node.
let readNum = readVisit;
let currRead = allReads[readNum];
// identify deletion: if there's a deletion, then those bases must be deleted from total base count
for (let i = 0; i < currRead.sequenceNew.length; i += 1) {
currRead.sequenceNew[i].mismatches.forEach((mm) => {
if (mm.type === "deletion") {
console.log ("this read has a deletion", currRead)
countBases -= mm.length;
}
})
};
countBases += currRead.finalNodeCoverLength - currRead.firstNodeOffset;
}
// outgoing reads
for (let readVisit of node.outgoingReads) {
let readNum = readVisit[0];
let currRead = allReads[readNum];
// identify deletion: if there's a deletion, then those bases must be deleted from total base count
for (let i = 0; i < currRead.sequenceNew.length; i += 1) {
currRead.sequenceNew[i].mismatches.forEach((mm) => {
if (mm.type === "deletion") {
console.log ("this read has a deletion", currRead)
countBases -= mm.length;
}
})
};
// coverage of outgoing read would be the the distance between the end of the node and the
// starting point of the read within the node
countBases += node.sequenceLength - currRead.firstNodeOffset;
Expand Down
237 changes: 237 additions & 0 deletions src/util/tubemap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,4 +607,241 @@ describe('coverage', () => {
expect(checkNodeExample(node, reads)).toBe(undefined);
expect(coverage(node, reads)).toBe(6.57);
})
// TEST #5
it('it can handle nodes with deletions in 1 read', async () => {
const node = {
nodename: '3',
sequenceLength: 6,
incomingReads: [],
internalReads: [0, 1],
outgoingReads: [[2, 0], [3, 0]]
}
const reads = [
{
"id": 1,
"sequenceNew": [
{
"nodeName": "1",
"mismatches": [
{
"type": "deletion",
"pos": 0,
"length": 2
}
]
}
],
"firstNodeOffset": 0,
"finalNodeCoverLength": 3,
},
{
"id": 2,
"sequenceNew": [
{
"nodeName": "1",
"mismatches": [
{
"type": "insertion",
"pos": 0,
"seq": "TCAAGAACAGTCATTCATG"
}
]
}
],
"firstNodeOffset": 1,
"finalNodeCoverLength": 5,
},
{
"id": 3,
"sequenceNew": [
{
"nodeName": "1",
"mismatches": []
},
{
"nodeName": "11",
"mismatches": []
},
{
"nodeName": "13",
"mismatches": []
}
],
"firstNodeOffset": 2,
"finalNodeCoverLength": 6,
},
{
"id": 4,
"sourceTrackID": "1",
"sequence": [
"1",
"12",
"13"
],
"sequenceNew": [
{
"nodeName": "1",
"mismatches": []
},
{
"nodeName": "12",
"mismatches": []
},
{
"nodeName": "13",
"mismatches": []
}
],
"firstNodeOffset": 4,
"finalNodeCoverLength": 6,
}
];
//expect(checkNodeExample(node, reads)).toBe(undefined);
//console.log("coverage(node, reads) for test 5:", coverage(node, reads))
expect(coverage(node, reads)).toBe(1.83);
})
// TEST #6
it('it can handle larger node with deletions in all reads', async () => {
const node = {
nodename: '3',
sequenceLength: 24,
incomingReads: [[0, 1]],
internalReads: [1, 2],
outgoingReads: [[3, 0], [4, 0]]
}
const reads = [
{
"id": 1,
"sequenceNew": [
{
"nodeName": "1",
"mismatches": [
{
"type": "deletion",
"pos": 0,
"length": 1
}
]
}
],
"firstNodeOffset": 1,
"finalNodeCoverLength": 10,
},
{
"id": 2,
"sequenceNew": [
{
"nodeName": "1",
"mismatches": [
{
"type": "deletion",
"pos": 0,
"length": 1
}
]
}
],
"firstNodeOffset": 4,
"finalNodeCoverLength": 15,
},
{
"id": 3,
"sequenceNew": [
{
"nodeName": "1",
"mismatches": [
{
"type": "deletion",
"pos": 0,
"length": 1
}
]
},
{
"nodeName": "11",
"mismatches": [
{
"type": "deletion",
"pos": 0,
"length": 2
}
]
},
{
"nodeName": "13",
"mismatches": [
{
"type": "deletion",
"pos": 0,
"length": 1
}
]
}
],
"firstNodeOffset": 2,
"finalNodeCoverLength": 8,
},
{
"id": 4,
"sourceTrackID": "1",
"sequence": [
"1",
"12",
"13"
],
"sequenceNew": [
{
"nodeName": "1",
"mismatches": [
{
"type": "deletion",
"pos": 0,
"length": 1
}
]
},
{
"nodeName": "12",
"mismatches": [
{
"type": "deletion",
"pos": 0,
"length": 1
}
]
},
{
"nodeName": "13",
"mismatches": [
{
"type": "deletion",
"pos": 0,
"length": 1
}
]
}
],
"firstNodeOffset": 9,
"finalNodeCoverLength": 12,
},
{
"id": 5,
"sequenceNew": [
{
"nodeName": "1",
"mismatches": [
{
"type": "deletion",
"pos": 0,
"length": 2
}
]
}
],
"firstNodeOffset": 2,
"finalNodeCoverLength": 14,
},
];
expect(coverage(node, reads)).toBe(2.79);
})
})
Loading