-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: add tga cnvkit to gens #1448
Open
mathiasbio
wants to merge
57
commits into
update_cnvkit_pons
Choose a base branch
from
cnvkit_to_gens
base: update_cnvkit_pons
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
e6516d6
add gens functionality to tga
mathiasbio 7f6e521
add gens inputs
mathiasbio 24e41a9
add gens gnomad af to tga
mathiasbio cdbe43f
black
mathiasbio f262919
fix
mathiasbio c2aafb9
fix
mathiasbio cc9e506
fix
mathiasbio d471395
fix
mathiasbio 05bd3ae
fix
mathiasbio 6868556
doc strings and named args
mathiasbio b03a9f0
black
mathiasbio 582cfb0
changelog
mathiasbio e9c4c7f
bug fix
mathiasbio 8f88da7
fix
mathiasbio 4a4671e
lower padding
mathiasbio 5bcf768
add tumor purity adjustment to gens cov file
mathiasbio acde38f
typehints
mathiasbio ed4c018
black
mathiasbio a108a0e
fix pytests
mathiasbio 99d3d57
update purity adjustment formula
mathiasbio bf57f92
Merge branch 'develop' of github.com:Clinical-Genomics/BALSAMIC into …
mathiasbio d69c3c7
merge develop
mathiasbio 44f25e1
m conflict
mathiasbio 9335478
m conflict
mathiasbio 5768116
adjust formula
mathiasbio 6433887
add round
mathiasbio f3a2c66
code review
mathiasbio 2de2692
fix merge conflicts
mathiasbio 2b91865
fix bug
mathiasbio 821bbd3
float
mathiasbio 6aa5510
comment out purity and ploidy adjustment
mathiasbio f703189
adjust purity and ploidy
mathiasbio 8994fc8
bug fix
mathiasbio 11be7bf
remove purity and ploidy adjustment
mathiasbio 3d44b03
new threads
mathiasbio b484670
return purity adjustment
mathiasbio 1fac876
code review
mathiasbio 9688e3d
new purity and ploidy formula from PureCN
mathiasbio 8d80a75
merge pon repo
mathiasbio 3abae1b
fix pytests
mathiasbio ce95786
black
mathiasbio d736f7c
Merge branch 'update_cnvkit_pons' of github.com:Clinical-Genomics/BAL…
mathiasbio 4f7cf28
Merge branch 'update_cnvkit_pons' into cnvkit_to_gens
mathiasbio 8f32eac
Merge branch 'update_cnvkit_pons' of github.com:Clinical-Genomics/BAL…
mathiasbio ca32fea
Merge branch 'update_cnvkit_pons' into cnvkit_to_gens
mathiasbio 0c99f60
Merge branch 'update_cnvkit_pons' of github.com:Clinical-Genomics/BAL…
mathiasbio f5eebd6
Merge branch 'update_cnvkit_pons' into cnvkit_to_gens
mathiasbio 8a40907
Merge branch 'update_cnvkit_pons' of github.com:Clinical-Genomics/BAL…
mathiasbio 254c6a8
Merge branch 'update_cnvkit_pons' into cnvkit_to_gens
mathiasbio 42c314a
Merge branch 'update_cnvkit_pons' of github.com:Clinical-Genomics/BAL…
mathiasbio e3f54f7
Merge branch 'update_cnvkit_pons' into cnvkit_to_gens
mathiasbio 6030b87
add io test
mathiasbio 604f059
add new test
mathiasbio 92b5c4d
Merge branch 'update_cnvkit_pons' of github.com:Clinical-Genomics/BAL…
mathiasbio 2a07bb1
Merge branch 'update_cnvkit_pons' into cnvkit_to_gens
mathiasbio 3f6b529
Merge branch 'update_cnvkit_pons' of github.com:Clinical-Genomics/BAL…
mathiasbio 9569ebd
Merge branch 'update_cnvkit_pons' into cnvkit_to_gens
mathiasbio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,91 @@ | ||
import click | ||
from BALSAMIC.utils.io import read_csv, write_list_of_strings | ||
|
||
def calculate_log2_ratio(purity, log2_ratio, ploidy): | ||
# 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 reference to PureCN issue: https://github.com/lima1/PureCN/issues/40 | ||
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"]) | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have some tests for this script