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

Added read path information to read info dialog #382

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions src/util/tubemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3918,6 +3918,26 @@ function trackDoubleClick() {
createTubeMap();
}

// Takes a track and returns a string describing the nodes it passes through
// In the format of >1>2<3>4, with the intergers being nodeIDs
function getPathInfo(track) {
let result = "";
if (!track.sequence) {
return result;
}

for (const nodeID of track.sequence) {
// Node is approached backwards if "-" is present
if (Array.from(nodeID)[0] === "-") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a weird way to see if the string starts with "-", even though it looks like StackOverflow recommends it, since this looks to convert the whole string to an array just to check the first character. I would probably try the startsWith method instead.

Suggested change
if (Array.from(nodeID)[0] === "-") {
if (nodeID.startsWith("-")) {

result = result.concat("<", nodeID.substring(1));
} else {
result = result.concat(">", nodeID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it is going to be an O(n^2) algorithm when it doesn't need to be. Building the new version of result is going to copy the original contents of result into a new string that also has the </> character and the node ID. But that copy takes some unit of time for each character in result, and as you make result longer the number of characters to be copied increases at each step.

You probably want to build an array of all the pieces you want in the final string, by mutably appending to the array with push() (which doesn't take longer to do as the array gets longer). Then you can use .join("") on the array to turn it into a combined string all at once, in linear time.

}
}

return result;
}

function trackSingleClick() {
/* jshint validthis: true */
// Get the track ID as a number
Expand All @@ -3940,6 +3960,7 @@ function trackSingleClick() {
track_attributes.push(["Score", current_track.score]);
track_attributes.push(["CIGAR string", current_track.cigar_string]);
track_attributes.push(["Mapping Quality", current_track.mapping_quality]);
track_attributes.push(["Path Info", getPathInfo(current_track)]);
}
console.log("Single Click");
console.log("read path");
Expand Down
Loading