Skip to content

Instantly share code, notes, and snippets.

View jvfe's full-sized avatar
🐢
slow and steady...

João Cavalcante jvfe

🐢
slow and steady...
View GitHub Profile
@jvfe
jvfe / spec.json
Last active May 13, 2020 22:50
Vega-Lite spec from Wed May 13 2020
{
"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}},
"vconcat": [
{
"hconcat": [
{
"mark": {"type": "line", "point": true},
"encoding": {
"color": {
"condition": {"value": "purple", "selection": "selector055"},
@jvfe
jvfe / spec2.json
Created May 13, 2020 23:31
Vega spec
{
"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}},
"vconcat": [
{
"hconcat": [
{
"mark": "point",
"encoding": {
"color": {
"condition": {"value": "purple", "selection": "selector079"},
@jvfe
jvfe / get_covid_data_jhu.py
Last active November 14, 2021 00:05 — forked from fernandobarbalho/get_covid_data_jhu.r
Function to create COVID-19 dataset from JHU github
import pandas as pd
import datetime
def get_covid_data_jhu(dt_ini, dt_fim, us_columns = True, country = None):
date_range = pd.date_range(start = dt_ini, end = dt_fim).to_list()
string_range = [str(d.date().strftime("%m-%d-%Y")) for d in date_range]
full_data_list = []
for dat in string_range:
get_summary <- function(geneids){
summary_list <- entrez_summary("gene", id = geneids, ) %>%
extract_from_esummary(elements = c("uid", "summary"), simplify = TRUE) %>%
as_tibble() %>%
unnest()
gene_names <- summary_list %>%
slice(1) %>%
as.character()
@jvfe
jvfe / plot_network.py
Created August 6, 2020 17:59
Make a nice network plot with bokeh
from bokeh.io import show
from bokeh.models import Range1d, Plot, Circle, HoverTool, MultiLine
from bokeh.models.graphs import NodesAndLinkedEdges
from bokeh.plotting import from_networkx
import networkx as nx
def plot_network(network, tooltip, layout=nx.kamada_kawai_layout):
"""Makes a nice network plot with Bokeh
Mostly stuff I pieced together from the bokeh tutorials.
@jvfe
jvfe / wikidata_utils.py
Last active August 6, 2020 21:32
A few utilities to easily get data from Wikidata into a dataframe
from collections import defaultdict
import pandas as pd
import requests
def perform_query(query):
"""Performs a SPARQL query to the wikidata endpoint
Args:
query: A string containing a functional sparql query
@jvfe
jvfe / docx2pdf.sh
Created September 9, 2020 10:57
Simple snippet I use all the time to convert docx to pdf
#!/bin/bash
libreoffice --headless --convert-to pdf:writer_pdf_Export "$1" --outdir .
@jvfe
jvfe / wikidata_shex_checker.py
Last active September 26, 2020 22:42
Check a wikidata sparql query against a ShEx schema
from pyshex.shex_evaluator import ShExEvaluator
from pyshex.user_agent import SlurpyGraphWithAgent
from pyshex.utils.sparql_query import SPARQLQuery
import pandas as pd
def test_query_against_shex(schema, sparql):
"""Checks the items resulting from a Wikidata query against a shex schema
Using PyShEx, we can check the validity of multiple items against a predefined
@jvfe
jvfe / mkignore
Last active October 1, 2020 17:27
Makes my default gitignore
#!/bin/bash
curl https://www.toptal.com/developers/gitignore/api/python,r,linux,visualstudiocode >> .gitignore
@jvfe
jvfe / diamond.m8
Created May 13, 2021 11:16
Annotate example data
read1 WP_005581541.1 98.2 40 1 0 129 299 1 57 7.7e-22 113.6
read2 WP_005575885.1 100.0 60 0 0 181 2 1 60 2.2e-24 122.1
read3 WP_005580014.1 100.0 50 0 0 2 151 385 434 3.6e-19 104.8
read4 WP_005576929.1 100.0 98 0 0 296 3 308 405 6.7e-42 180.3
read5 ELY74166.1 98.0 100 2 0 300 1 80 179 7.9e-43 183.3
read5 WP_015233403.1 98.0 100 2 0 300 1 98 197 7.9e-43 183.3
read6 WP_005578121.1 100.0 52 0 0 1 156 124 175 1.6e-22 115.9
read7 WP_005576999.1 92.0 100 8 0 1 300 14 113 1.1e-47 199.5
read8 WP_005579760.1 98.0 100 2 0 2 301 214 313 1.8e-42 182.2
read8 AFZ74922.1 98.0 100 2 0 2 301 188 287 1.8e-42 182.2