-
Notifications
You must be signed in to change notification settings - Fork 10
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
Fix bug in checking for duplicate Mutation Records #1099
Merged
averyniceday
merged 7 commits into
knowledgesystems:master
from
callachennault:fix-duplicate-maf-entries
Jan 17, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
76051ea
Check if mutationRecord is duplicated before annotating
callachennault 982f4d0
Populate mutationMap in loadMutationRecordsFromJson
callachennault 11207d8
add addRecordToMap
callachennault 91c692d
Remove comments, add local vars for debugging
callachennault b77b7b9
Remove duplicate MAF variants for AZ
callachennault fd908a2
Fix remove-duplicate-maf-variants call
callachennault 8eb02eb
revert whitespace change
callachennault 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
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,86 @@ | ||
#!/usr/bin/python | ||
import sys | ||
import os | ||
import optparse | ||
|
||
# Script to remove duplicate maf records based on the 8 key columns. | ||
# Calculates VAF for each record and picks the record with high VAF | ||
# Formula for VAF = t_alt_count / (t_ref_count + t_alt_count) | ||
|
||
ERROR_FILE = sys.stderr | ||
OUTPUT_FILE = sys.stdout | ||
|
||
KEY_COLUMNS_INDEX = [] | ||
KEY_COLUMNS = ['Entrez_Gene_Id','Chromosome','Start_Position','End_Position','Variant_Classification','Tumor_Seq_Allele2','Tumor_Sample_Barcode','HGVSp_Short'] | ||
MAF_DATA = {} | ||
|
||
def remove_duplicate_variants(maf_filename, comments, header, t_refc_index, t_altc_index): | ||
outfile = [] | ||
outfile.append(comments) | ||
outfile.append(header) | ||
for key in MAF_DATA: | ||
if len(MAF_DATA[key]) > 1: | ||
vaf_ind = 0 | ||
vaf_value = 0 | ||
for val in MAF_DATA[key]: | ||
#calculate VAF for each duplicate record. | ||
columns = val.rstrip('\n').split('\t') | ||
try: | ||
VAF = int(columns[t_altc_index])/(int(columns[t_altc_index])+int(columns[t_refc_index])) | ||
if VAF > vaf_value: | ||
vaf_value = VAF | ||
vaf_ind = MAF_DATA[key].index(val) | ||
outfile.append(MAF_DATA[key][vaf_ind]) | ||
except: | ||
print >> ERROR_FILE, 'ERROR: VAF cannot be calculated for the variant : ' + key | ||
print >> ERROR_FILE, 'The t_ref_count is: '+ columns[t_refc_index]+ ' and t_alt_count is: '+ columns[t_altc_index] | ||
outfile.append(val) | ||
else: | ||
outfile.append(MAF_DATA[key][0]) | ||
|
||
out_filename = maf_filename.split('.')[0]+'_merged.txt' | ||
datafile = open(out_filename, 'w') | ||
for line in outfile: | ||
datafile.write(line) | ||
datafile.close() | ||
print >> OUTPUT_FILE, 'MAF file with duplicate variants removed is written to: ' + out_filename +'\n' | ||
|
||
|
||
def main(): | ||
# get command line arguments | ||
parser = optparse.OptionParser() | ||
parser.add_option('-i', '--input-maf-file', action = 'store', dest = 'maf_file') | ||
|
||
(options, args) = parser.parse_args() | ||
maf_filename = options.maf_file | ||
|
||
comments = "" | ||
header = "" | ||
|
||
with open(maf_filename,'r') as maf_file: | ||
for line in maf_file: | ||
if line.startswith('#'): | ||
comments += line | ||
elif line.startswith('Hugo_Symbol'): | ||
header += line | ||
header_cols = line.rstrip('\n').split('\t') | ||
#get the positions of the 8 key maf columns | ||
for value in KEY_COLUMNS: | ||
KEY_COLUMNS_INDEX.append(header_cols.index(value)) | ||
t_refc_index = header_cols.index('t_ref_count') | ||
t_altc_index = header_cols.index('t_alt_count') | ||
else: | ||
reference_key = "" | ||
data = line.rstrip('\n').split('\t') | ||
for index in KEY_COLUMNS_INDEX: | ||
reference_key += data[index]+'\t' | ||
reference_key = reference_key.rstrip('\t') | ||
if reference_key not in MAF_DATA: | ||
MAF_DATA[reference_key] = [line] | ||
else: | ||
MAF_DATA[reference_key].append(line) | ||
|
||
remove_duplicate_variants(maf_filename, comments, header, t_refc_index, t_altc_index) | ||
|
||
if __name__ == '__main__': | ||
main() |
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
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.
Think this logic will fix the issue, but have you run an entire mskimpact fetch with this code? I'm curious about the memory usage, worried that if we have another map tracking the entire mutation record, we'll exacerbate the memory issue