Skip to content

Instantly share code, notes, and snippets.

View bradfordcondon's full-sized avatar

Bradford Condon bradfordcondon

View GitHub Profile
@bradfordcondon
bradfordcondon / gist:ec7078b8514a422e65db5e8d6cd29858
Last active March 11, 2019 15:59
link organism to analysis via the Links field on node
<?php
$orgs = db_select('chado.organism', 'o')
->fields('o')
->execute();
foreach ($orgs as $organism) {
$organism_id = $organism->organism_id;
$nid = chado_get_nid_from_id('organism', $organism_id);
$node = node_load($nid);
$links = $node->field_resource_links ?? NULL;
if ($links) {
@bradfordcondon
bradfordcondon / find_sequence.sh
Created January 2, 2019 21:32
one liner for extracting a particular fasta sequence from a file by name
perl -ne 'if(/^>(\S+)/){$c=grep{/^$1$/}qw(sequence_name)}print if $c' file.fasta > out.fasta
@bradfordcondon
bradfordcondon / reset_website.sh
Created December 19, 2018 21:23
rebuild drupal database (developer)
#!/usr/bin/env bash
DB_NAME="drupal"
DB_PASS="secret"
DB_USER="drupal"
ADMIN_PASS=secret
echo "Dropping DB: $DB_NAME"
sudo -u postgres dropdb $DB_NAME
@bradfordcondon
bradfordcondon / Migrate_node_fields.php
Last active March 15, 2019 17:19
migrate tripal 2 node fields to chado properties for tripal 3 compatibility and best FAIR practices
<?php
//if we made this into a module, we would use the tripal jobs... but we dont so its commented out for now.
//
//global $user;
//tripal_add_job(
// "Convert fields to properties", 'no_module',
// 'snippet_tripal_job_callback',
// 'chado_update_existing_node_urls',
// [],
// $user->uid
@bradfordcondon
bradfordcondon / gist:aa2c509975ed79ce4162e17955226fb3
Created July 31, 2018 17:53
delete all git branches except master
git branch | grep -v "master" | xargs git branch -D
@bradfordcondon
bradfordcondon / helper.sql
Last active September 7, 2018 23:42
postgresql diagnostics cheathseet
### What are my densest indexes?
SELECT relname, relpages
FROM pg_class
ORDER BY relpages DESC;
### What are my running queries
ELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
@bradfordcondon
bradfordcondon / 1.3_indexes.sql
Last active June 13, 2018 16:45
chado 1.3 add missing indexes
set search_path to chado;
create index if not exists dbxref_idx1 on dbxref (db_id);
create index if not exists dbxref_idx2 on dbxref (accession);
create index if not exists dbxref_idx3 on dbxref (version);
create index if not exists cvterm_idx1 on cvterm (cv_id);
create index if not exists cvterm_idx2 on cvterm (name);
create index if not exists cvterm_idx3 on cvterm (dbxref_id);
COMMENT ON INDEX cvterm_c1 IS 'A name can mean different things in';
COMMENT ON INDEX cvterm_c2 IS 'The OBO identifier is globally unique.';
create index if not exists cvterm_relationship_idx1 on cvterm_relationship (type_id);
@bradfordcondon
bradfordcondon / cmap.json
Last active May 11, 2018 17:00
cmap.js for HWG trial
{
"#": "cmap-js chinese chestnut configuration file",
"header": ": Chinese Chestnut Genetic map",
"attribution": "HWG",
"initialView": [
{
"source": "Chinese Chestnut Genetic Map",
"map": "A"
},
{
@bradfordcondon
bradfordcondon / AOtrigger.sql
Last active May 9, 2018 14:31
sql for creating a trigger for organism_analysis table to update when feature's organisms change.
CREATE TRIGGER check_ao_linker
AFTER INSERT ON feature
FOR ROW
EXECUTE PROCEDURE update_ao_linker();
CREATE TRIGGER check_ao_linker_update
AFTER UPDATE ON feature ON organism_id
FOR ROW
EXECUTE PROCEDURE update_ao_linker();
git rebase -i HEAD~4 # rebase branch back the number of commits
git commit --amend # make sure the commit message is awesome
git push origin branch-name --force # need to force the commits if you've already pushed