Skip to content

Instantly share code, notes, and snippets.

View nickynicolson's full-sized avatar

Nicky Nicolson nickynicolson

View GitHub Profile
@nickynicolson
nickynicolson / cm2df.py
Last active December 29, 2019 10:56 — forked from ClementC/print_cm.py
Convert scikit-learn confusion matrix to pandas DataFrame
from sklearn.metrics import confusion_matrix
import pandas as pd
def cm2df(cm, labels):
df = pd.DataFrame()
# rows
for i, row_label in enumerate(labels):
rowdata={}
# columns
for j, col_label in enumerate(labels):
@nickynicolson
nickynicolson / gbseq2tsv.xsl
Created May 6, 2015 09:43
XSL to convert INSDSeq XML format download from genbank to tabular delimited file of accession, publication and voucher details
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" encoding="UTF-8"/>
<xsl:variable name="delimiter" select="'&#09;'"/>
<xsl:variable name="newline" select="'&#10;'"/>
<xsl:template match="/">
<!-- header line -->
<xsl:value-of select="concat('primary_accession',$delimiter,'date_created',$delimiter,'date_last_amended', $delimiter, 'definition', $delimiter, 'title', $delimiter, 'reference', $delimiter, 'doi', $delimiter, 'specimen_voucher', $delimiter, 'bio_material', $delimiter, 'organism', $newline)"/>
<!-- data -->
import urllib
import urllib2
try:
# Base url for the TNRS match_names API
url = 'http://api.opentreeoflife.org/v2/tnrs/match_names'
# Encode data value to be looked up as an array of names:
data = '{"names": ["'+value+'"]}'
print "Looking up: " + data
# Set HTTP headers:
@nickynicolson
nickynicolson / name-reconciliation-python.ipynb
Last active February 12, 2016 16:25
Name reconciliation in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This graph gist demonstrates use of Jaccard calculation to determine similarity between two sets of nodes

@nickynicolson
nickynicolson / 0_reuse_code.js
Last active August 29, 2015 14:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@nickynicolson
nickynicolson / cypher-meta-graph-w-counts
Last active August 29, 2015 14:20
Modification of the neo4j "meta" graph creation cypher statement to add counts to nodes and relationships
// Create meta-graph with orphan counts
MATCH (n)
/* ugly string replace to convert collection of labels to colon delimited string */
WITH replace(replace(replace(replace(str(labels(n)),'[',''),']',''),'"',''),',',':') AS l, count(distinct n) AS c
MERGE (mn:Meta_Node {name:l,count:c})
WITH mn
MATCH (a)-[r]->(b)
WITH replace(replace(replace(replace(str(labels(a)),'[',''),']',''),'"',''),',',':') AS a_labels
, count(distinct a) AS from_count
, type(r) AS rel_type
= The taxonomic mind-mapper
Nicky Nicolson, Peter Hovenkamp
:neo4j-version: 2.1.0
:author: Nicky Nicolson
:twitter: nickynicolson
== Domain
We investigate the use of the scheme in: https://docs.google.com/document/d/1FIxNrrGrIZs0l4QJEdGfctXbYVL4cQhKspmMEHmKAGg/edit with a use case in the taxonomy of Diplazium tomentosum (https://docs.google.com/document/d/1vni44RBwGNZ7iRCFf243NtcD-7xwjHrDeAPehato7KY/edit?usp=sharing)
== Data model
@nickynicolson
nickynicolson / Taxonomic-mind-mapper
Last active August 29, 2015 13:57
Peter's use cases for the taxonomic mind mapper
Peter investigates the taxonomy of Diplazium tomentosum.
//console
He starts with one of the types from the Leiden herbarium (http://plants.jstor.org/specimen/l0051073):
[source,cypher]
----
CREATE (s:Specimen{id:"L0051073"
,jstorUrl:'http://plants.jstor.org/specimen/l0051073'