Skip to content

Commit

Permalink
Merge pull request #118 from zhx828/minor-fix
Browse files Browse the repository at this point in the history
Fix issue when input file is empty
  • Loading branch information
Hongxin authored Jan 15, 2021
2 parents 96f964e + f536645 commit 7770f10
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions AnnotatorCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
oncokbapiurl = "https://www.oncokb.org/api/v1"
oncokbapibearertoken = ""


def setoncokbbaseurl(u):
global oncokbapiurl
oncokbapiurl = u.rstrip('/') + '/api/v1'
Expand Down Expand Up @@ -347,6 +347,8 @@ def processalterationevents(eventfile, outfile, previousoutfile, defaultCancerTy
headers = readheaders(reader)

ncols = headers["length"]
if ncols == 0:
return
newncols = 0

outf.write(headers['^-$'])
Expand All @@ -361,7 +363,7 @@ def processalterationevents(eventfile, outfile, previousoutfile, defaultCancerTy

outf.write("\tMUTATION_EFFECT")
outf.write("\tONCOGENIC")

newncols += 4

for l in levels:
Expand Down Expand Up @@ -507,7 +509,7 @@ def get_var_allele(ref_allele, tumor_seq_allele1, tumor_seq_allele2):
tumor_seq_allele = [allele for allele in [tumor_seq_allele1, tumor_seq_allele2] if allele != ref_allele][0]
except:
tumor_seq_allele = ""

return tumor_seq_allele

def process_genomic_change(maffilereader, outf, maf_headers, ncols, nannotationcols, defaultCancerType, cancerTypeMap, annotatehotspots, default_reference_genome):
Expand Down Expand Up @@ -612,7 +614,7 @@ def process_hvsg(maffilereader, outf, maf_headers, alteration_column_names, ncol
annotations = pull_hgvsg_info(queries,annotatehotspots)
append_annotation_to_file(outf, ncols+nannotationcols, rows, annotations)


def getgenesfromfusion(fusion, nameregex=None):
GENES_REGEX = "([A-Za-z\d]+-[A-Za-z\d]+)" if nameregex is None else nameregex
searchresult = re.search(GENES_REGEX, fusion, flags=re.IGNORECASE)
Expand All @@ -639,6 +641,9 @@ def processsv(svdata, outfile, previousoutfile, defaultCancerType, cancerTypeMap

ncols = headers["length"]

if ncols == 0:
return

outf.write(headers['^-$'])
outf.write("\t" + GENE_IN_ONCOKB_HEADER)
outf.write("\t" + VARIANT_IN_ONCOKB_HEADER)
Expand Down Expand Up @@ -732,9 +737,11 @@ def processcnagisticdata(cnafile, outfile, previousoutfile, defaultCancerType, c
with open(cnafile, 'rU') as infile:
reader = csv.reader(infile, delimiter='\t')
headers = readheaders(reader)
startofsamples = getfirstcolumnofsampleingisticdata(headers['^-$'].split('\t'))
rawsamples = headers['^-$'].split('\t')[startofsamples:]
samples = []
rawsamples = []
if headers["length"] != 0:
startofsamples = getfirstcolumnofsampleingisticdata(headers['^-$'].split('\t'))
rawsamples = headers['^-$'].split('\t')[startofsamples:]
for rs in rawsamples:
samples.append(rs)

Expand Down Expand Up @@ -850,6 +857,9 @@ def processclinicaldata(annotatedmutfiles, clinicalfile, outfile):

ncols = headers["length"]

if ncols == 0:
return

igene1 = geIndexOfHeader(headers, ['GENE1'] + HUGO_HEADERS) # fusion
igene2 = geIndexOfHeader(headers, ['GENE2'] + HUGO_HEADERS) # fusion
ifusion = geIndexOfHeader(headers, ['FUSION'])
Expand Down Expand Up @@ -1659,7 +1669,7 @@ def process_oncokb_annotation(annotation, annotate_hotspot):

_3dhotspot = pull3dhotspots(annotation['query']['hugoSymbol'], annotation['query']['consequence'], annotation['query']['proteinStart'], annotation['query']['proteinEnd'])
ret.append(_3dhotspot)

ret.append(oncokbdata[GENE_IN_ONCOKB_HEADER])
ret.append(oncokbdata[VARIANT_IN_ONCOKB_HEADER])
ret.append(oncokbdata['mutation_effect'])
Expand All @@ -1671,7 +1681,7 @@ def process_oncokb_annotation(annotation, annotate_hotspot):
for l in dxLevels:
ret.append(','.join(oncokbdata[l]))
ret.append(gethighestDxPxlevel(dxLevels, [oncokbdata['highestDiagnosticImplicationLevel']]))

for l in pxLevels:
ret.append(','.join(oncokbdata[l]))
ret.append(gethighestDxPxlevel(pxLevels, [oncokbdata['highestPrognosticImplicationLevel']]))
Expand Down Expand Up @@ -1723,6 +1733,7 @@ def readCancerTypes(clinicalFile, data):

def readheaders(reader):
headers = {}
headers["length"] = 0
for row in reader:
if not row[0].startswith("#"):
headers["^-$"] = '\t'.join(row) # the whole line
Expand Down

0 comments on commit 7770f10

Please sign in to comment.