Skip to content

Instantly share code, notes, and snippets.

@samesense
samesense / README.md
Created January 19, 2021 16:07
Go BigQuery tests

Go BigQuery tests

@samesense
samesense / README.md
Last active January 11, 2021 15:08 — forked from alexkappa/fleet.go

Reading and writing JSON with GO

Problem: I want to read and serve JSON, but the JSON structure differs by query. I solve this with an interface FleetVehicle, a base Vehicle struct, and additional specialized structs that allow for differetnail parsing. The Fleet struct holds raw json in RawVehicles, and parsed objects/structs in Vehicles. By writing MarsahJSON and UnmarshalJSON for the Fleet struct, and I control how each JSON block is parsed into a different type of struct/vehicle. To run: GOPATH=${PWD} go run helloVariant.go, and check http://localhost:8080/world. This loads multiple JSON files into one Fleet object allowing me to serve a concatenation of the JSON files. For now, each JSON block must use the data field to hold a list of vehicles.

  • helloVariant.go is the main file
  • src/varparse/varparse.go holds structs for variants in JSON
  • testVariant1.json and testVariant2.json are example files used by helloVariant.go
  • hello.go is my initial attempt
  • fleet.go, fleet_test.go, fleet_test_
#!/usr/bin/env python3
"""
The idea here is to have one demo of each common argparse format
type. This is useful for me to be able to copy/paste into a new
script and have something to quickly edit and trim down to get
the functionality I need.
Example (in your terminal):
$ python3 argparse-template.py "hello" 123 --enable
@samesense
samesense / Snakefile-blog-dynamic.py
Last active August 2, 2020 20:58
Snakefile using dynamic rule
import rule_maker
one_out = 'out1'
rule one:
output:
one_out
shell:
'touch {output}'
# generate a snakefile file for the second rule
@samesense
samesense / rule_maker.py
Last active August 2, 2020 20:55
Dynamic rule for snakemake
def mk_rule(in_file, out_file, tmp_snake='tmp_snake.py'):
'''input is single file
output is single file
'''
with open(tmp_snake, 'w') as f:
rule_str = f"""rule auto:
input:
'{in_file}'
output:
'{out_file}'
@samesense
samesense / blog-sm-module.py
Created August 2, 2020 20:28
Example snakefile for module concept
''' Three rule ex '''
rule one:
output:
'out1'
shell:
'touch {output}'
rule two:
input:
@samesense
samesense / keybase.md
Created February 11, 2020 02:35
keybase.md

Keybase proof

I hereby claim:

  • I am samesense on github.
  • I am samesense (https://keybase.io/samesense) on keybase.
  • I have a public key ASB-sPD-A8yIsdlWUcJNosvQ0yi326pqYwvZRVxkg3-LHQo

To claim this, I am signing this object:

@samesense
samesense / vcf-snp-check.md
Last active December 21, 2019 14:43
vcf-snp-check

vcf-snp-lookup

I hope you have some terminal/command line experience.

  • Navigate to your vcf.gz file in the terminal/command line.
  • Check your reference genome (install gzcat as needed):
gzcat {your_id}.filtered.snp.vcf.gz | head -100 | less

Look for something like -r /references/grch37

@samesense
samesense / ssh-forward-clipboard.md
Last active August 26, 2019 20:41 — forked from dergachev/ssh-forward-clipboard.md
Forward your clipboard via SSH reverse tunnels

Exposing your clipboard over SSH

I frequently administer remote servers over SSH, and need to copy data to my clipboard. If the text I want to copy all fits on one screen, then I simply select it with my mouse and press CMD-C, which asks relies on m y terminal emulator (xterm2) to throw it to the clipboard.

This isn't practical for larger texts, like when I want to copy the whole contents of a file.

If I had been editing large-file.txt locally, I could easily copy its contents by using the pbcopy command:

@samesense
samesense / snakemake-sms.py
Created August 22, 2019 18:36
snakemake-sms
onsuccess:
shell(
"curl `singularity exec docker://vault:1.2.1 vault read -field=value secret/v1/users/evansj/twilio-a` -X POST --data-urlencode 'To=+12406819176' --data-urlencode 'From=+18174022818' -u `singularity exec docker://vault:1.2.1 vault read -field=value secret/v1/users/evansj/twilio-u` --data-urlencode 'Body=gatk done'"
)
onerror:
shell(
"curl `singularity exec docker://vault:1.2.1 vault read -field=value secret/v1/users/evansj/twilio-a` -X POST --data-urlencode 'To=+12406819176' --data-urlencode 'From=+18174022818' -u `singularity exec docker://vault:1.2.1 vault read -field=value secret/v1/users/evansj/twilio-u` --data-urlencode 'Body=gatk fail'"
)