Skip to content

Instantly share code, notes, and snippets.

View Avantol13's full-sized avatar
🎹

Alexander VanTol Avantol13

🎹
  • CTDS - University of Chicago
View GitHub Profile
# other stuff ...
# open git cola (https://git-cola.github.io/) easier
alias gc='git-cola &'
# enter friendly interactive shell easier (https://fishshell.com/)
alias f='fish'
# create and checkout new branch easier, stash stuff before if needed
gitbranch(){
@Avantol13
Avantol13 / nested_dict_replace.py
Last active June 13, 2018 22:53
Replace nested value in dict from another nested value in a different dict
import copy
def replace(data, path_to_key, replacement_value):
"""
Will replace a nested value in a dict with the given value.
Args:
data (dict): a dictionary
path_to_key (str): nested/path/to/key. The value of this key will be
replaced
replacement_value (str): Replacement value for the key from
@Avantol13
Avantol13 / g_sign.py
Created September 28, 2018 14:28
generating signed url for requester pays bucket, bill to project that owns the bucket
# NOTE: need to install oauth2client
# Signed URL generates correctly but I keep getting:
# <Error>
# <Code>SignatureDoesNotMatch</Code>
# <Message>
# The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
# </Message>
# ...
# </Error>
@Avantol13
Avantol13 / dictionaries_match.py
Created October 24, 2018 15:40
Check if two dictionaries in Python have the same key structure/schema
def dictionaries_match(d1, d2):
# both are dicts, need to check values
if isinstance(d1, dict) and isinstance(d2, dict):
d1_keys = d1.keys()
d1_keys.sort()
d2_keys = d2.keys()
d2_keys.sort()
valid = d1_keys == d2_keys and all(
dictionaries_match(d1[k], d2[k]) for k in d1.keys()
# Python 2
from mock import patch, mock_open
creds_file = "This text is not really in a file."
mocked_open = patch("__builtin__.open", mock_open(read_data=creds_file))
mocked_open.start()
with open("any_file_name") as mocked_file:
print(mocked_file.read())
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 3.
guid submitted_sample_id biosample_id dbgap_sample_id sra_sample_id submitted_subject_id dbgap_subject_id consent_code consent_short_name sex body_site analyte_type sample_use repository dbgap_status sra_data_details study_accession study_accession_with_consent study_with_consent study_subject_id
c65ae178-e070-4a33-a091-bca0516b6ab3 NWD680715 SAMN04109058 1784155 SRS1361261 DBG00391 1360750 2 HMB-IRB-MDS female Blood DNA "[""Seq_DNA_SNP_CNV"", ""WGS""]" TOPMed_WGS_Amish Loaded "{""status"": ""public"", ""experiments"": ""1"", ""runs"": ""1"", ""bases"": ""135458977924"", ""size_Gb"": ""25"", ""experiment_type"": ""WGS"", ""platform"": ""ILLUMINA"", ""center"": ""UM-TOPMed""}" phs000956.v4.p1 phs000956.v4.p1.c2 phs000956.c2 phs000956.v4_DBG00391
2e4f042b-55fd-481a-ae6c-5102357bafe4 NWD437822 SAMN11169121 3415113 SRS4907945 BUR02263239B 2199582 2 DS-LD-IRB-COL male Peripheral Blood DNA "[""Seq_DNA_SNP_CNV"", ""WGS""]" GALAII Loaded "{""status"": ""public"", ""experiments"": ""1"", ""runs"": ""1"", ""bases"": ""
We can't make this file beautiful and searchable because it's too large.
guid,urls,authz,acl,md5,file_size,file_name
2e4f042b-55fd-481a-ae6c-5102357bafe4,gs://dcf-integration-test/NWD437822.txt s3://cdis-presigned-url-test/testdata,/programs/DEV/projects/test,,f0aa6ed73a82379a6b8150a3e2b2b42c,42,
c65ae178-e070-4a33-a091-bca0516b6ab3,s3://cdis-presigned-url-test/NWD680715 gs://dcf-integration-test/file.txt,/programs/DEV/projects/test,,443e7594cbe3275a152906392e433e8d,42,
b81501c5-034c-415a-9a28-989296e9e5b2,s3://cdis-presigned-url-test/testdata gs://dcf-integration-test/file.txt,/programs/DEV/projects/test,,5c4395d5062ae6235a8b8b91752a5a75,42,
5a030535-3257-4b7a-93cd-b60934e711c3,s3://cdis-presigned-url-test/testdata gs://dcf-integration-test/file.txt,/programs/DEV/projects/test,,7edd57cdc3405c9e94909e59da55405b,42,
092b8c05-c848-4397-8884-38bdb9e0b00f,s3://cdis-presigned-url-test/testdata gs://dcf-integration-test/file.txt,/programs/DEV/projects/test,,d873dcebf8c7056a2aede0e588e3b9bd,42,
85b9605f-e92d-4020-8caa-290ca6aeb09c,gs://dcf-integration-test/file.txt s3://cdis-presigned-ur
guid md5 size acl authz urls
c519fedb-686a-4b96-b910-65355d3ea0ab f0aa6ed73a82379a6b8150a3e2b2b42c 12345678345 phs000964.c1 admin /programs/DEV gs://topmed-irc-share/test2
{
"ga4gh_passport_v1":
[
{
"iss": "https://stsstg.nih.gov",
"sub": "Ei4sFoHQ1KO-foobar",
"iat": 1588686798,
"exp": 1588729998,
"scope": "email profile ga4gh_passport_v1 openid",
"jti": "42d1e574-4129-4ee1-8a07-fa6a8d8bffcf",
{
"ga4gh_passport_v1":
[
{
"iss": "https://stsstg.nih.gov",
"sub": "Ei4sFoHQ1KO-foobar",
"iat": 1588686798,
"exp": 1588729998,
"scope": "email profile ga4gh_passport_v1 openid",
"jti": "42d1e574-4129-4ee1-8a07-fa6a8d8bffcf",