-
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.
#### Added - Added extension of target bed regions to a minimum size of 100 for CNV analysis - PON for: Exome comprehensive 10.2 - PON for: GMSsolid 15.2 - PON for: GMCKsolid 4.2 #### Changed - updated PON for GMCKSolid v4.1 - updated PON for GMSMyeloid v5.3 - updated PON for GMSlymphoid v7.3
- Loading branch information
1 parent
a50ff90
commit 0df968c
Showing
33 changed files
with
897 additions
and
333 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,44 @@ | ||
import click | ||
|
||
|
||
@click.command() | ||
@click.argument("input_bedfile", type=click.Path(exists=True)) | ||
@click.argument("output_bedfile", type=click.Path()) | ||
@click.option( | ||
"--extend-to-min-region-size", | ||
default=100, | ||
help="Will extend regions shorter than the specified size to this minimum size.", | ||
) | ||
def extend_bedfile( | ||
input_bedfile: str, output_bedfile: str, extend_to_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 < extend_to_min_region_size: | ||
center = (start + end) // 2 | ||
half_size = extend_to_min_region_size // 2 | ||
start = max(0, center - half_size) | ||
end = center + half_size | ||
if extend_to_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import click | ||
from BALSAMIC.utils.io import read_csv, write_list_of_strings | ||
|
||
|
||
def calculate_log2_ratio(purity, log2_ratio, ploidy): | ||
"""Adjuts log2 ratio according to purity and ploidy. | ||
Based on method in PureCN: https://github.com/lima1/PureCN/issues/40 | ||
Method is not used currently due to questionable results. | ||
""" | ||
# Ensure that the inputs are within valid ranges | ||
if not (0 <= purity <= 1): | ||
raise ValueError("Purity must be between 0 and 1") | ||
|
||
if ploidy <= 0: | ||
raise ValueError("Ploidy must be a positive number") | ||
|
||
# Ploidy and purity adjustment formula | ||
log2_adjusted = ( | ||
purity * log2_ratio * ploidy + 2 * (1 - purity) * log2_ratio - 2 * (1 - purity) | ||
) / (purity * ploidy) | ||
|
||
return log2_adjusted | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"-o", | ||
"--output-file", | ||
required=True, | ||
type=click.Path(exists=False), | ||
help="Name of output-file.", | ||
) | ||
@click.option( | ||
"-c", | ||
"--normalised-coverage-path", | ||
required=True, | ||
type=click.Path(exists=True), | ||
help="Input CNVkit cnr. result.", | ||
) | ||
@click.option( | ||
"-p", | ||
"--tumor-purity-path", | ||
required=True, | ||
type=click.Path(exists=True), | ||
help="Tumor purity file from PureCN", | ||
) | ||
def create_gens_cov_file( | ||
output_file: str, normalised_coverage_path: str, tumor_purity_path: str | ||
): | ||
"""Post-processes the CNVkit .cnr output for upload to GENS. | ||
Removes Antitarget regions, adjusts for purity and ploidy and outputs the coverages in multiple resolution-formats. | ||
Args: | ||
output_file: Path to GENS output.cov file | ||
normalised_coverage_path: Path to input CNVkit cnr file. | ||
tumor_purity_path: Path to PureCN purity estimate csv file | ||
""" | ||
log2_data = [] | ||
|
||
# Process CNVkit file | ||
cnr_dict_list: list[dict] = read_csv( | ||
csv_path=normalised_coverage_path, delimeter="\t" | ||
) | ||
|
||
# Process PureCN purity file | ||
purecn_dict_list: list[dict] = read_csv(csv_path=tumor_purity_path, delimeter=",") | ||
purity = float(purecn_dict_list[0]["Purity"]) | ||
ploidy = float(purecn_dict_list[0]["Ploidy"]) | ||
|
||
for row in cnr_dict_list: | ||
if row["gene"] == "Antitarget": | ||
continue | ||
|
||
# find midpoint | ||
start: int = int(row["start"]) | ||
end: int = int(row["end"]) | ||
region_size: int = end - start | ||
midpoint: int = start + int(region_size / 2) | ||
|
||
# adjust log2 ratio | ||
log2: float = float(row["log2"]) | ||
|
||
# De-activate purity and ploidy adjustment | ||
# log2: float = calculate_log2_ratio(purity, log2, ploidy) | ||
# log2: float = round(log2, 4) | ||
|
||
# store values in list | ||
log2_data.append(f"{row['chromosome']}\t{midpoint - 1}\t{midpoint}\t{log2}") | ||
|
||
# Write log2 data to output file | ||
resolutions = ["o", "a", "b", "c", "d"] | ||
resolution_log2_lines = [ | ||
f"{resolution}_{line}" for resolution in resolutions for line in log2_data | ||
] | ||
write_list_of_strings(resolution_log2_lines, output_file) | ||
|
||
|
||
if __name__ == "__main__": | ||
create_gens_cov_file() |
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.