Skip to content

Instantly share code, notes, and snippets.

View ebelter's full-sized avatar

Eddie Belter ebelter

  • McDonnell Genome Institute at Washington University
  • St. Louis, MO
View GitHub Profile
@ebelter
ebelter / gen-seq.py
Created June 2, 2020 23:23
Generate dummy contigs and scaffolds of various lengths. Works, but WIP
import os
from Bio import SeqIO
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
with open("asm.fasta", "w") as out_f:
for i in (1000000, 250000, 100000, 10000, 5000, 2000, 0):
record = SeqRecord(Seq(("ATGC" * int(i/4)) + "A"), id="SEQ_{}".format(i+1), description="")
SeqIO.write(record, out_f, "fasta")
@ebelter
ebelter / aws-set-conf-for-mgi.sh
Last active June 19, 2020 20:50
Set AWS credentials in network file to run AWS CLI at MGI in the data transfer queue.
#!/bin/bash
set -e
USAGE="USAGE: ${0} AWS_CONFIG_FILE
PURPOSE
The script will save AWS secret credentials to a given network readable file name, and export the AWS_CONFIG_FILE environment variable. This will allow the running of the AWS CLI to manipulate files in buckets. The reason for the script is the default location of AWS credentials/config is in the user's HOME directory, and these are not mounted when using the lims-i1-datatransfer LSF queue.
PROCESS
Writes the given AWS credentials to the given network aws config file. Also sets teh file permissions to user rw only.
@ebelter
ebelter / csv.py
Last active September 18, 2020 22:46
Python CSV Examples and Boilerplate
###
# Reader with Sniffer
###
import csv, sys
if len(sys.argv) != 2: raise Exception("Gimme input file")
with open(sys.argv[1], "r") as f:
dialect = csv.Sniffer().sniff(f.read(1024))
f.seek(0)
rdr = csv.reader(f, dialect)
wtr = csv.writer(sys.stdout, delimiter="\t", quoting=csv.QUOTE_ALL)
@ebelter
ebelter / iter.py
Created October 17, 2019 18:23
Python iterator boiler plate
# Python classes become iterator with a __iter__ and __next__ function.
# * the __iter__ function does not need to return self, just something that can __next__
# * raise StopIteration to indicate the itrerator is complete
class TheCount():
def __init__(self, start, stop):
self.current = start - 1
self.stop = stop
def __iter__(self):
@ebelter
ebelter / tutorial.graph-tool.md
Last active September 27, 2019 17:22
Tutorial to Run Graph Tool in Docker on MacOS

A tutorial on running graph_tool in docker on MacOS

Below are are 2 examples:

  • Run a basic docker to create, save as PNG, and view a simple graph with two vertices
  • Run a docker connecting to a Mac display. Then create, view with GTK windows, save as PDF, and view a Barabási–Albert model graph

The benefit of using the GTK windows is being able to skip the save/view steps hile developing a graph.

Install Docker

Skip if docker is already installed on your Mac. Instructions are here:

## STRUCTURE ##
|- myproject/
|-- __init__.py
|-- mymodule.py
|- tests/
|-- __init__.py
|-- test_mymodule.py
## RUNNING ##
@ebelter
ebelter / try-except-finally.py
Last active September 30, 2019 23:33
Example of python try/except/finally syntax.
import sys
def tryit(msg=None):
sys.stderr.write("***\nBEFORE\n")
try:
sys.stderr.write("TRY\n")
if msg is not None:
raise Exception(msg)
except BaseException as ex: # Can be specific exceptions, add as tuple or separate blocks
sys.stderr.write("EXCEPT\n")
@ebelter
ebelter / timezone-update.sh
Created January 31, 2019 22:09
Ways to change timezone without interaction on linux boxes.
#!/bin/bash
# General Linux: The Localtime File
mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime
# General Linux: ENV
export TZ='America/Chicago'
# Cent OS 7+: timedatectl (other subcommands available)
@ebelter
ebelter / SSH HOWTO
Last active January 26, 2024 23:08
Create an key for password-less SSH for a user on another host.
######
# remote user: edbelter
# remote host: bastion1
######
# Create a Key. If the key is for a different user, specify a different RSA file name.
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/ebelter/.ssh/id_rsa): bastion_rsa
Enter passphrase (empty for no passphrase):
# GCE INIT
$ gcloud init
# Set Sample - fill in __HERE__
SAMPLE=__HERE__; export SAMPLE
# DL FASTAS from object store
$ cd /mnt/disks/data/reads
$ mkdir -p ${SAMPLE}