Skip to content

Commit

Permalink
Merge pull request #190 from zhx828/skip-token-validation
Browse files Browse the repository at this point in the history
Support python 3.11
  • Loading branch information
zhx828 authored Jan 19, 2023
2 parents 767572b + ddcbf9b commit f322ccc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [2.7, 3.7, 3.8]
os: [ ubuntu-latest, macos-latest ]
python-version: [ '2.7','3.7','3.8','3.9','3.10','3.11' ]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -45,19 +45,20 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pytest
if [[ $PYTHON_VERSION =~ ^2\.[0-9]$ ]]; then pip install -r requirements/common.txt -r requirements/pip2.7.txt; fi
if [[ $PYTHON_VERSION =~ ^3\.[0-9]$ ]]; then pip install -r requirements/common.txt -r requirements/pip3.txt; fi
if [[ $PYTHON_VERSION =~ ^2\.[0-9]+$ ]]; then pip install -r requirements/common.txt -r requirements/pip2.7.txt; fi
if [[ $PYTHON_VERSION =~ ^3\.[0-9]+$ ]]; then pip install -r requirements/common.txt -r requirements/pip3.txt; fi
- name: Test with pytest
env:
ONCOKB_API_TOKEN: ${{ secrets.ONCOKB_BOT_API_TOKEN }}
run: |
pytest
build-in-windows:
needs: lint
runs-on: windows-latest
strategy:
matrix:
python-version: [2.7, 3.7, 3.8]
python-version: [ '2.7','3.7','3.8','3.9','3.10','3.11' ]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -70,11 +71,11 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pytest
if ( $env:PYTHON_VERSION -match '^2\.[0-9]$' )
if ( $env:PYTHON_VERSION -match '^2\.[0-9]+$' )
{
pip install -r requirements/common.txt -r requirements/pip2.7.txt
}
if ( $env:PYTHON_VERSION -match '^3\.[0-9]$' )
if ( $env:PYTHON_VERSION -match '^3\.[0-9]+$' )
{
pip install -r requirements/common.txt -r requirements/pip3.txt
}
Expand Down
44 changes: 30 additions & 14 deletions AnnotatorCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import datetime
import json
import csv
import sys

import requests
import os.path
import logging
Expand Down Expand Up @@ -35,6 +37,11 @@

oncokb_api_bearer_token = ""

# 'U', which no longer has any effect in python 3. 3.11 completely removed the option.
# It will throw error if we don't do condition check.
# https://stackoverflow.com/questions/56791545/what-is-the-non-deprecated-version-of-open-u-mode
DEFAULT_READ_FILE_MODE = 'r' if sys.version_info.major > 2 else 'rU'


def setoncokbbaseurl(u):
if u and u is not None:
Expand Down Expand Up @@ -416,7 +423,7 @@ def get_tumor_type_from_row(row, row_index, defaultCancerType, icancertype, canc
cancertype = cancerTypeMap[sample]
if cancertype == "":
log.info(
"Cancer type for the sample should be defined for a more accurate result\nline %s: %s\n" % (row_index, row))
"Cancer type for the sample should be defined for a more accurate result. \tLine %s" % (row_index))
# continue
return cancertype

Expand Down Expand Up @@ -483,7 +490,7 @@ def processalterationevents(eventfile, outfile, previousoutfile, defaultCancerTy
if os.path.isfile(previousoutfile):
cacheannotated(previousoutfile, defaultCancerType, cancerTypeMap)
outf = open(outfile, 'w+', 1000)
with open(eventfile, 'rU') as infile:
with open(eventfile, DEFAULT_READ_FILE_MODE) as infile:
reader = csv.reader(infile, delimiter='\t')

headers = readheaders(reader)
Expand Down Expand Up @@ -791,7 +798,7 @@ def process_fusion(svdata, outfile, previousoutfile, defaultCancerType, cancerTy
if os.path.isfile(previousoutfile):
cacheannotated(previousoutfile, defaultCancerType, cancerTypeMap)
outf = open(outfile, 'w+')
with open(svdata, 'rU') as infile:
with open(svdata, DEFAULT_READ_FILE_MODE) as infile:
reader = csv.reader(infile, delimiter='\t')

headers = readheaders(reader)
Expand Down Expand Up @@ -861,7 +868,7 @@ def process_sv(svdata, outfile, previousoutfile, defaultCancerType, cancerTypeMa
if os.path.isfile(previousoutfile):
cacheannotated(previousoutfile, defaultCancerType, cancerTypeMap)
outf = open(outfile, 'w+')
with open(svdata, 'rU') as infile:
with open(svdata, DEFAULT_READ_FILE_MODE) as infile:
reader = csv.reader(infile, delimiter='\t')

headers = readheaders(reader)
Expand Down Expand Up @@ -945,7 +952,7 @@ def get_cna(cell_value, annotate_gain_loss=False):


def process_gistic_data(outf, gistic_data_file, defaultCancerType, cancerTypeMap, annotate_gain_loss):
with open(gistic_data_file, 'rU') as infile:
with open(gistic_data_file, DEFAULT_READ_FILE_MODE) as infile:
reader = csv.reader(infile, delimiter='\t')
headers = readheaders(reader)
samples = []
Expand Down Expand Up @@ -1000,7 +1007,7 @@ def process_gistic_data(outf, gistic_data_file, defaultCancerType, cancerTypeMap


def process_individual_cna_file(outf, cna_data_file, defaultCancerType, cancerTypeMap, annotate_gain_loss):
with open(cna_data_file, 'rU') as infile:
with open(cna_data_file, DEFAULT_READ_FILE_MODE) as infile:
reader = csv.reader(infile, delimiter='\t')
headers = readheaders(reader)
row_headers = headers['^-$'].split('\t') + get_oncokb_annotation_column_headers()
Expand Down Expand Up @@ -1112,7 +1119,7 @@ def process_clinical_data(annotatedmutfiles, clinicalfile, outfile):
sample_tx_resistance_count = {}
samplealterationcount = {}
for annotatedmutfile in annotatedmutfiles:
with open(annotatedmutfile, 'rU') as mutfile:
with open(annotatedmutfile, DEFAULT_READ_FILE_MODE) as mutfile:
reader = csv.reader(mutfile, delimiter='\t')
headers = readheaders(reader)

Expand Down Expand Up @@ -1232,7 +1239,7 @@ def process_clinical_data(annotatedmutfiles, clinicalfile, outfile):
outf = open(outfile, 'w+')

# export to anntoated file
with open(clinicalfile, 'rU') as clinfile:
with open(clinicalfile, DEFAULT_READ_FILE_MODE) as clinfile:
reader = csv.reader(clinfile, delimiter='\t')
headers = readheaders(reader)
outf.write(headers['^-$'])
Expand Down Expand Up @@ -1346,7 +1353,7 @@ def process_clinical_data(annotatedmutfiles, clinicalfile, outfile):


def cacheannotated(annotatedfile, defaultCancerType, cancerTypeMap):
with open(annotatedfile, 'rU') as infile:
with open(annotatedfile, DEFAULT_READ_FILE_MODE) as infile:
try:
reader = csv.reader(infile, delimiter='\t')
headers = readheaders(reader)
Expand Down Expand Up @@ -1454,6 +1461,9 @@ def __init__(self, hugo, hgvs, cancertype, reference_genome=None, consequence=No
if reference_genome is not None:
self.referenceGenome = reference_genome.value

def __repr__(self):
return ",".join([self.gene.hugoSymbol, self.alteration, self.tumorType, self.consequence, self.proteinStart, self.proteinEnd, self.referenceGenome])


class HGVSgQuery:
def __init__(self, hgvsg, cancertype, reference_genome=None):
Expand All @@ -1462,6 +1472,9 @@ def __init__(self, hgvsg, cancertype, reference_genome=None):
if reference_genome is not None:
self.referenceGenome = reference_genome.value

def __repr__(self):
return ",".join([self.hgvsg, self.tumorType, self.referenceGenome])


def gettumortypename(tumortype):
if 'code' in tumortype and tumortype['code'] is not None and tumortype['code'] != '':
Expand Down Expand Up @@ -1496,15 +1509,18 @@ def __init__(self, chromosome, start, end, ref_allele, var_allele, cancertype, r
if reference_genome is not None:
self.referenceGenome = reference_genome.value

def __repr__(self):
return " ".join([self.genomicLocation, self.tumorType, self.referenceGenome])


class CNAQuery:
def __init__(self, hugo, cnatype, cancertype):
self.gene = Gene(hugo)
self.copyNameAlterationType = cnatype.upper()
self.tumorType = cancertype

def __str__(self):
return "\t".join([self.gene.hugoSymbol, self.copyNameAlterationType, self.tumorType])
def __repr__(self):
return ",".join([self.gene.hugoSymbol, self.copyNameAlterationType, self.tumorType])


class StructuralVariantQuery:
Expand All @@ -1521,8 +1537,8 @@ def __init__(self, hugoA, hugoB, structural_variant_type, cancertype):
self.structuralVariantType = structural_variant_type.upper()
self.tumorType = cancertype

def __str__(self):
return "\t".join(
def __repr__(self):
return ",".join(
[self.geneA.hugoSymbol, self.geneB.hugoSymbol, str(self.functionalFusion), self.structuralVariantType,
self.tumorType])

Expand Down Expand Up @@ -1831,7 +1847,7 @@ def gettreatments(evidence):


def readCancerTypes(clinicalFile, data):
with open(clinicalFile, 'rU') as infile:
with open(clinicalFile, DEFAULT_READ_FILE_MODE) as infile:
reader = csv.reader(infile, delimiter='\t')
headers = readheaders(reader)

Expand Down
2 changes: 0 additions & 2 deletions example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ OICNA="data/example_individual_cna.oncokb.txt"
IC="data/example_clinical.txt"
OC="data/example_clinical.oncokb.txt"

OCPDF="data/example_clinical.oncokb.pdf"

TOKEN="" #OncoKB API Token
README="data/example_README.txt"

Expand Down
1 change: 0 additions & 1 deletion requirements/pip2.7.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
matplotlib==2.2.4
enum34==1.1.10
kiwisolver==1.1.0
1 change: 0 additions & 1 deletion requirements/pip3.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
matplotlib==3.1.2
kiwisolver==1.2.0

0 comments on commit f322ccc

Please sign in to comment.