Skip to content

Instantly share code, notes, and snippets.

View ravila4's full-sized avatar

Ricardo Avila ravila4

View GitHub Profile
@ravila4
ravila4 / gpt_completions.sh
Last active May 3, 2023 03:15
A simple curl wrapper around the OpenAI completions API.
#!/bin/bash
set -euo pipefail
# This script sends a request to the OpenAI completions endpoint and parses the output using jq.
# It is recommended that the API key is stored in an environment variable.
usage() {
echo "Usage: $0 [-k OPENAI_API_KEY] [-m MODEL] [-t MAX_TOKENS] PROMPT"
echo "Example: $0 -m text-davinci-002 -t 500 \"What is the capital of France?\""
@ravila4
ravila4 / config.py
Last active November 13, 2022 01:42
MyGeneset test config
"""Web config to run MyGeneset API on GitHub Actions"""
import os
ES_INDEX = 'user_genesets'
COOKIE_SECRET = "JKA#9%Wc4ofuqM@C!&yLFsYE"
# ORCID keys
ORCID_CLIENT_ID = os.environ['ORCID_CLIENT_ID']
@ravila4
ravila4 / count_taxids.sh
Last active February 23, 2021 23:40
A demo of converting API responses to CSV format with JQ.
#!/bin/bash
# Genesets aggregated by taxid
aggs=`curl -s "https://mygeneset.info/v1/query?q=*&facets=taxid&facet_size=100"`
taxids=`echo $aggs | jq -r '.facets.taxid.terms | map(.term) | @csv'`
counts=`echo $aggs | jq -r '.facets.taxid.terms | map(.count) | @csv'`
# Query scientific name for each taxid
resp=`curl -s -X POST -d "q=${taxids}" "http://t.biothings.io/v1/query"`
species=`echo $resp | jq -r 'map(.scientific_name) | @csv'`
@ravila4
ravila4 / gist:9aacae443c50a168b4267fca7448d88b
Created December 15, 2020 15:35
BASH_script_template.sh
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
trap cleanup SIGINT SIGTERM ERR EXIT
usage() {
cat <<EOF
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ravila4
ravila4 / databricks-programming-guide.md
Created January 27, 2020 15:40
Databricks Programming Guidance

Databricks Programming Guidance

This document contains lessons learned with regard to Databricks programming, but also contains some best practices

Mapping to a Azure Data Lake Generation 2

blobname = "miraw"  
storageaccount = "rdmidlgen2"  
mountname = "/rdmi"

configs = {"fs.azure.account.auth.type": "OAuth",

@ravila4
ravila4 / align.py
Created January 11, 2020 20:14
Sequence alignment using PyMOL
#!/usr/bin/env python
# Sequence alignment using PyMOL
# The purpose of this script is to generate a sequence alignment between
# the original crystal structure of the apo and holo models, and the sequence
# of the finalised, ungapped Rosetta models. This allows us to get a 1 to 1
# corresponcence between the residue numberings in both structures.
# USAGE: Run once from the project root.
# "pockets.csv" contains the information about apo holo pairs.
@ravila4
ravila4 / HTS_gaussian.ipynb
Created October 24, 2019 20:38
Fitting Gaussian curves to histograms
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ravila4
ravila4 / flatten_json.py
Created September 12, 2019 14:36
Recursive function for flattening JSON.
def flatten_json(y):
out = {}
def flatten(x, name=''):
if type(x) is dict:
for a in x:
flatten(x[a], name + a + '_')
elif type(x) is list:
i = 0
for a in x:
@ravila4
ravila4 / pandas_snippets.py
Created August 31, 2019 15:56
Chris's useful pandas snippets.
# List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
# Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
# Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(valuelist)]