-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
downsample reads prior to Medaka [CW-2496] See merge request epi2melabs/workflows/wf-amplicon!17
- Loading branch information
Showing
6 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
bin/workflow_glue/get_reads_with_longest_aligned_ref_len.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""Get IDs of reads with largest `aligned_ref_len` from `bamstats` results TSV file.""" | ||
import sys | ||
|
||
import pandas as pd | ||
|
||
from .util import get_named_logger, wf_parser # noqa: ABS101 | ||
|
||
|
||
def argparser(): | ||
"""Argument parser for entrypoint.""" | ||
parser = wf_parser("get_reads_with_longest_aligned_ref") | ||
parser.add_argument( | ||
"bamstats_results", | ||
help="`bamstats` results TSV file.", | ||
) | ||
parser.add_argument( | ||
"num_reads_per_strand", | ||
help="Number of reads to select.", | ||
type=int, | ||
) | ||
return parser | ||
|
||
|
||
def main(args): | ||
"""Run the entry point.""" | ||
logger = get_named_logger("longAlnRds") | ||
logger.info( | ||
f"Extract IDs of {args.num_reads_per_strand} reads with " | ||
"longest `aligned_ref_len`." | ||
) | ||
|
||
# we only load the relevant columns and use categorical dtype where possible to | ||
# reduce the memory footprint | ||
dtypes = { | ||
"name": str, | ||
"ref": "category", | ||
"direction": "category", | ||
"aligned_ref_len": int, | ||
} | ||
df = pd.read_csv( | ||
args.bamstats_results, sep="\t", usecols=dtypes.keys(), dtype=dtypes | ||
).query('ref != "*"') | ||
|
||
# for each ref--direction combo, write out the read IDs of the longest | ||
# `args.num_reads_per_strand` reads | ||
df.groupby(["ref", "direction"]).apply( | ||
lambda grp_df: sys.stdout.write( | ||
"\n".join( | ||
grp_df.sort_values("aligned_ref_len", ascending=False)["name"].head( | ||
args.num_reads_per_strand | ||
) | ||
) | ||
+ "\n" | ||
) | ||
) | ||
|
||
logger.info("Finished writing read IDs with longest `aligned_ref_len` to STDOUT.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ params { | |
min_coverage = 20 | ||
basecaller_cfg = "[email protected]" | ||
medaka_model = null | ||
medaka_target_depth_per_strand = 75 | ||
|
||
// misc | ||
help = false | ||
|
@@ -53,7 +54,7 @@ params { | |
"--fastq 'wf-amplicon-demo/fastq'", | ||
"--reference 'wf-amplicon-demo/reference.fa'" | ||
] | ||
common_sha = "sha5fc720674a26bc63a6f31ed186344209175b54b1" | ||
common_sha = "sha0a6dc21fac17291f4acb2e0f67bcdec7bf63e6b7" | ||
container_sha = "sha2699195046454bce4411b7b781457eabe3d5ee52" | ||
container_sha_medaka = "sha492176b6093aa922aae5610f6ad899aacd2c3c7f" | ||
agent = null | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters