-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from kids-first/feature/pbta-updates-2024-06-24
🔧 Fix Missing Field
- Loading branch information
Showing
7 changed files
with
117 additions
and
7 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
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,48 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Script to pull patient IDs from a study on pedcbioportal | ||
""" | ||
|
||
import argparse | ||
from bravado.client import SwaggerClient | ||
from bravado.requests_client import RequestsClient | ||
from urllib.parse import urlparse | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="Pull patient IDs from a study on pedcbioportal" | ||
) | ||
parser.add_argument( | ||
"-u", "--url", action="store", dest="url", help="url to search against", default="https://pedcbioportal.kidsfirstdrc.org/api/v2/api-docs" | ||
) | ||
parser.add_argument( | ||
"-s", "--study", action="store", dest="study", help="Cancer study ID to compare on server" | ||
) | ||
parser.add_argument( | ||
"-t", "--token", action="store", dest="token", help="Token file obtained from Web API" | ||
) | ||
|
||
args = parser.parse_args() | ||
with open(args.token, 'r') as token_file: | ||
token = token_file.read().rstrip().split(': ')[1] | ||
|
||
url_object = urlparse(args.url) | ||
|
||
http_client = RequestsClient() | ||
http_client.set_api_key( | ||
'{}'.format(url_object.hostname), 'Bearer {}'.format(token), | ||
param_name='Authorization', param_in='header' | ||
) | ||
|
||
cbioportal = SwaggerClient.from_url(args.url, | ||
http_client=http_client, | ||
config={"validate_requests":False, | ||
"validate_responses":False, | ||
"validate_swagger_spec": False} | ||
) | ||
|
||
pt_list = cbioportal.Patients.getAllPatientsInStudyUsingGET(studyId=args.study).result() | ||
print("\n".join([x.patientId for x in pt_list])) | ||
|
||
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
File renamed without changes.
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,35 @@ | ||
#!/usr/bin/python | ||
""" | ||
Script that can be cleaned up. | ||
Removes entries from a table using a list of banned values. | ||
Usage: | ||
python subtract_by_id.py <id_list> <colname> <out_flag> <in_file> | ||
To have no out_flag, provide "SKIP_THIS" as the value | ||
""" | ||
|
||
import sys | ||
import pdb | ||
|
||
id_list = {} | ||
with open(sys.argv[1]) as rm_list: | ||
for line in rm_list: | ||
id_list[line.rstrip('\n')] = 0 | ||
colname = sys.argv[2] | ||
out_flag = sys.argv[3] | ||
with open(sys.argv[4]) as in_file: | ||
head = next(in_file) | ||
header = head.rstrip('\n').split('\t') | ||
c_idx = header.index(colname) | ||
o_idx = None | ||
if out_flag != "SKIP_THIS": | ||
out_list = [] | ||
o_idx = header.index(out_flag) | ||
print(head, end='') | ||
for line in in_file: | ||
info = line.rstrip('\n').split('\t') | ||
if info[c_idx] not in id_list: | ||
print(line, end='') | ||
elif o_idx is not None: | ||
out_list.append(info[o_idx]) | ||
if o_idx is not None: | ||
print("\n".join(list(set(out_list))), file=sys.stderr) |