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

Prepare chunk path format fix #356

Merged
merged 9 commits into from
Oct 27, 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
2 changes: 1 addition & 1 deletion exampleData/cactus.bed
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ref 10 100 this is a test region
ref 1000 2000 another region with a very long description to see how it will be displayed
ref 2000 3000 pre-fecthed region test_prechunk
ref 2000 3000 pre-fecthed region chunk-ref-2000-3000
ref 4000 4500 pre-fecthed region but the chunk is missing test_prechunk_missing
1 change: 1 addition & 0 deletions exampleData/cactus_subgraph.bed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref 2000 3000 Region ref:2000-3000 chunk-ref-2000-3000
41 changes: 26 additions & 15 deletions exampleData/chunk-ref-1-20/tracks.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
{
"trackFile": "cactus.vg",
"trackType": "graph",
"trackColorSettings": {"mainPalette": "plainColors", "auxPalette": "greys"}
},
{
"trackFile": "cactus0_10.sorted.gam",
"trackType": "read",
"trackColorSettings": {"mainPalette": "blues", "auxPalette": "reds"}
},
{
"trackFile": "cactus10_20.sorted.gam",
"trackType": "read",
"trackColorSettings": {"mainPalette": "blues", "auxPalette": "reds"}
}
[
{
"trackFile": "exampleData/cactus.vg",
"trackType": "graph",
"trackColorSettings": {
"mainPalette": "plainColors",
"auxPalette": "greys"
}
},
{
"trackFile": "exampleData/cactus0_10.sorted.gam",
"trackType": "read",
"trackColorSettings": {
"mainPalette": "blues",
"auxPalette": "reds"
}
},
{
"trackFile": "exampleData/cactus10_20.sorted.gam",
"trackType": "read",
"trackColorSettings": {
"mainPalette": "blues",
"auxPalette": "reds"
}
}
]
Binary file modified exampleData/chunk-ref-2000-3000/chunk.vg
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions exampleData/chunk-ref-2000-3000/chunk_contents.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
chunk.vg
chunk_0_ref_2000_3000.annotate.txt
chunk_0_ref_2000_3000.gam
regions.tsv
tracks.json
2 changes: 1 addition & 1 deletion exampleData/chunk-ref-2000-3000/regions.tsv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ref 1955 5024 chunk-ref-2000-3000/chunk_0_ref_1955_5023.gam chunk-ref-2000-3000/chunk_0_ref_1955_5023.annotate.txt
ref 2000 3000 chunk_0_ref_2000_3000.gam chunk_0_ref_2000_3000.annotate.txt
25 changes: 18 additions & 7 deletions exampleData/chunk-ref-2000-3000/tracks.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
{
"graph_file": "cactus.vg",
"haplotype_file": "",
"gam_files": [
"cactus-NA12879.sorted.gam"
]
}
[
{
"trackFile": "exampleData/cactus.vg",
"trackType": "graph",
"trackColorSettings": {
"mainPalette": "plainColors",
"auxPalette": "greys"
}
},
{
"trackFile": "exampleData/cactus-NA12879.sorted.gam",
"trackType": "read",
"trackColorSettings": {
"mainPalette": "blues",
"auxPalette": "reds"
}
}
]
162 changes: 0 additions & 162 deletions exampleData/test_prechunk/chunk.vg

This file was deleted.

Empty file.
Binary file removed exampleData/test_prechunk/chunk_0_ref_1955_5023.gam
Binary file not shown.
1 change: 0 additions & 1 deletion exampleData/test_prechunk/regions.tsv

This file was deleted.

21 changes: 17 additions & 4 deletions scripts/prepare_chunks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,39 @@ mkdir -p $OUTDIR

vg_chunk_params=(-x $GRAPH_FILE -g -c 20 -p $REGION -T -b $OUTDIR/chunk -E $OUTDIR/regions.tsv)


# construct track JSON for graph file
# get path relative to directory above the scripts directory
GRAPH_FILE_PATH=$(realpath --relative-to $(dirname ${BASH_SOURCE[0]})/../ $GRAPH_FILE)
echo ${GRAPH_FILE_PATH}
GRAPH_PALETTE="$(cat src/config.json | jq '.defaultGraphColorPalette')"
jq -n --arg trackFile "${GRAPH_FILE}" --arg trackType "graph" --argjson trackColorSettings "$GRAPH_PALETTE" '$ARGS.named' >> $OUTDIR/tracks.json
jq -n --arg trackFile "${GRAPH_FILE_PATH}" --arg trackType "graph" --argjson trackColorSettings "$GRAPH_PALETTE" '$ARGS.named' >> $OUTDIR/temp.json

# construct track JSON for haplotype file, if provided
HAPLOTYPE_PALETTE="$(cat src/config.json | jq '.defaultHaplotypeColorPalette')"
if [[ ! -z "${HAPLOTYPE_FILE}" ]] ; then
jq -n --arg trackFile "${HAPLOTYPE_FILE}" --arg trackType "haplotype" --argjson trackColorSettings "$HAPLOTYPE_PALETTE" '$ARGS.named' >> $OUTDIR/tracks.json
HAPLOTYPE_FILE_PATH=$(realpath --relative-to $(dirname ${BASH_SOURCE[0]})/../ $HAPLOTYPE_FILE)
echo ${HAPLOTYPE_FILE_PATH}
jq -n --arg trackFile "${HAPLOTYPE_FILE_PATH}" --arg trackType "haplotype" --argjson trackColorSettings "$HAPLOTYPE_PALETTE" '$ARGS.named' >> $OUTDIR/temp.json
fi

# construct track JSON for each gam file
echo >&2 "Gam Files:"
READ_PALETTE="$(cat src/config.json | jq '.defaultReadColorPalette')"
echo >&2 "Read Palette: $READ_PALETTE"
for GAM_FILE in "${GAM_FILES[@]}"; do
echo >&2 " - $GAM_FILE"
jq -n --arg trackFile "${GAM_FILE}" --arg trackType "read" --argjson trackColorSettings "$READ_PALETTE" '$ARGS.named' >> $OUTDIR/tracks.json
GAM_FILE_PATH=$(realpath --relative-to $(dirname ${BASH_SOURCE[0]})/../ $GAM_FILE)
echo >&2 " - $GAM_FILE_PATH"
jq -n --arg trackFile "${GAM_FILE_PATH}" --arg trackType "read" --argjson trackColorSettings "$READ_PALETTE" '$ARGS.named' >> $OUTDIR/temp.json
vg_chunk_params+=(-a $GAM_FILE)
done

# put all tracks objects into an array
(jq -s '.' < $OUTDIR/temp.json) > $OUTDIR/tracks.json

rm $OUTDIR/temp.json


# construct node file
if [[ ! -z "${NODE_COLORS}" ]] ; then
for NODENAME in "${NODE_COLORS[@]}"; do
Expand Down
14 changes: 12 additions & 2 deletions scripts/prepare_local_chunk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ REGION_END="$(echo ${REGION} | rev | cut -f1 -d'-' | rev)"
REGION_START="$(echo ${REGION} | rev | cut -f2 -d'-' | cut -f1 -d':' | rev)"
REGION_CONTIG="$(echo ${REGION} | rev| cut -f2- -d':' | rev)"

# get path relative to directory above the scripts directory
GRAPH_FILE_PATH=$(realpath --relative-to $(dirname ${BASH_SOURCE[0]})/../ $GRAPH_FILE)

# construct track JSON for graph file
GRAPH_PALETTE="$(cat src/config.json | jq '.defaultGraphColorPalette')"
jq -n --arg trackFile "${GRAPH_FILE}" --arg trackType "graph" --argjson trackColorSettings "$GRAPH_PALETTE" '$ARGS.named' >> $OUTDIR/tracks.json
jq -n --arg trackFile "${GRAPH_FILE_PATH}" --arg trackType "graph" --argjson trackColorSettings "$GRAPH_PALETTE" '$ARGS.named' >> $OUTDIR/temp.json

# Put the graphy file in place
vg convert -p "${GRAPH_FILE}" > $OUTDIR/chunk.vg
Expand All @@ -82,8 +85,10 @@ GAM_NUM=0
READ_PALETTE="$(cat src/config.json | jq '.defaultReadColorPalette')"
for GAM_FILE in "${GAM_FILES[@]}"; do
echo >&2 " - $GAM_FILE"

GAM_FILE_PATH=$(realpath --relative-to $(dirname ${BASH_SOURCE[0]})/../ $GAM_FILE)
# construct track JSON for each gam file
jq -n --arg trackFile "${GAM_FILE}" --arg trackType "read" --argjson trackColorSettings "$READ_PALETTE" '$ARGS.named' >> $OUTDIR/tracks.json
jq -n --arg trackFile "${GAM_FILE_PATH}" --arg trackType "read" --argjson trackColorSettings "$READ_PALETTE" '$ARGS.named' >> $OUTDIR/temp.json
# Work out a chunk-internal GAM name with the same leading numbering vg chunk uses
if [[ "${GAM_NUM}" == "0" ]] ; then
GAM_LEADER="chunk"
Expand All @@ -98,6 +103,11 @@ for GAM_FILE in "${GAM_FILES[@]}"; do
GAM_NUM=$((GAM_NUM + 1))
done

# put all tracks objects into an array
(jq -s '.' < $OUTDIR/temp.json) > $OUTDIR/tracks.json

rm $OUTDIR/temp.json

# construct node file
if [[ ! -z "${NODE_COLORS}" ]] ; then
for NODENAME in "${NODE_COLORS[@]}"; do
Expand Down
1 change: 1 addition & 0 deletions src/components/CopyLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function CopyLink(props) {
// Don't stringify objects for readability
// https://github.com/ljharb/qs#stringifying
const params = qs.stringify(viewTarget, { encodeValuesOnly: true });
console.log("params ", params);
// complete url
const full = window.location.origin + "?" + params;
console.log(full);
Expand Down
16 changes: 2 additions & 14 deletions src/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,21 +1432,9 @@ async function getBedRegions(bed) {
if (fs.existsSync(track_json)) {
// Create string of tracks data
const string_data = fs.readFileSync(track_json);
const parser = new JSONParser({separator: ''});
parser.onValue = ({value, key, parent, stack}) => {
if (stack.length > 0) {
// ignore inner values
return;
}
if (!Object.hasOwn(value, 'trackFile')) {
throw new BadRequestError('Non-track object in tracks.json: ' + JSON.stringify(value))
}
// put tracks in array
tracks_array.push(value);
};
parser.write(string_data);

// Convert to object container like the client component prop types expect
tracks = {...tracks_array};
tracks = JSON.parse(string_data);
}
}

Expand Down
Loading