-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extend bedfiles for CNV analysis (#1469)
## Added - padding of bed-regions for CNVkit to minimum 100 base
- Loading branch information
1 parent
8d6736a
commit 2a2dcfe
Showing
19 changed files
with
201 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import click | ||
|
||
|
||
@click.command() | ||
@click.argument("input_bedfile", type=click.Path(exists=True)) | ||
@click.argument("output_bedfile", type=click.Path()) | ||
@click.option("--min-region-size", default=20, help="Minimum region size to enforce.") | ||
def extend_bedfile(input_bedfile: str, output_bedfile: str, min_region_size: int): | ||
""" | ||
Process a BED file to ensure regions are at least a minimum size. | ||
Args: | ||
input_bedfile (str): Input BED file path. | ||
output_bedfile (str): Output BED file path. | ||
min_region_size (int): Minimum region size to enforce. | ||
""" | ||
with open(input_bedfile, "r") as infile, open(output_bedfile, "w") as outfile: | ||
for line in infile: | ||
fields = line.strip().split("\t") | ||
|
||
chrom: str = fields[0] | ||
start = int(fields[1]) | ||
end = int(fields[2]) | ||
|
||
region_length: int = end - start | ||
if region_length < min_region_size: | ||
center = (start + end) // 2 | ||
half_size = min_region_size // 2 | ||
start = max(0, center - half_size) | ||
end = center + half_size | ||
if min_region_size % 2 != 0: | ||
end += 1 | ||
|
||
outfile.write(f"{chrom}\t{start}\t{end}\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
extend_bedfile() |
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
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
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
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,42 @@ | ||
|
||
rule extend_short_bedregions: | ||
input: | ||
baits_bed = config_model.panel.capture_kit, | ||
wake_up= result_dir + "start_analysis", | ||
output: | ||
baits_bed_expanded=Path(cnv_dir + "capture_kit_expanded.bed").as_posix(), | ||
benchmark: | ||
Path(benchmark_dir,"extend_short_bedregions.tsv").as_posix() | ||
singularity: | ||
Path(singularity_image,config["bioinfo_tools"].get("pysam") + ".sif").as_posix() | ||
params: | ||
bedfile_extend = get_script_path("extend_bedfile.py"), | ||
minimum_region_size = params.bed_pre_processing.minimum_region_size | ||
threads: | ||
get_threads(cluster_config, "extend_short_bedregions") | ||
message: | ||
"Extending regions in bedfiel to a minimum size of {params.minimum_region_size}." | ||
shell: | ||
""" | ||
python {params.bedfile_extend} --min-region-size {params.minimum_region_size} {input.baits_bed} {output.baits_bed_expanded} ; | ||
""" | ||
|
||
|
||
rule bedtools_sort_and_merge: | ||
input: | ||
bed_expanded = Path(cnv_dir + "capture_kit_expanded.bed").as_posix(), | ||
output: | ||
bed_expanded_merged = Path(cnv_dir + "capture_kit_expanded_merged.bed").as_posix(), | ||
benchmark: | ||
Path(benchmark_dir, 'bedtools_merge_expanded_bedfile.tsv').as_posix() | ||
singularity: | ||
Path(singularity_image, config["bioinfo_tools"].get("bedtools") + ".sif").as_posix() | ||
threads: | ||
get_threads(cluster_config, "bedtools_merge") | ||
message: | ||
"Running bedtools sort and merge to merge potentially overlapping regions." | ||
shell: | ||
""" | ||
bedtools sort -i {input.bed_expanded} > {input.bed_expanded}_sorted.bed | ||
bedtools merge {input.bed_expanded}_sorted.bed {output.bed_expanded_merged} | ||
""" |
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
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
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
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
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
Oops, something went wrong.