Skip to content

Instantly share code, notes, and snippets.

View bbarad's full-sized avatar

Benjamin Barad bbarad

View GitHub Profile
@bbarad
bbarad / stl2sff.py
Created February 8, 2023 04:24
Convert a bunch of individual STL files to a large mesh collection sff file.
## Convert all mitochondria STL files in current directory to SFF/HFF files
## Usage: python stl2sff.py FOLDERNAME
## Assumes there are multiple mitochondria per tomogram and up to one ER per tomogram.
## Performs both per-segment and global annotations based on assumption of MitoGFP MEF cells treated with thapsigargin (sometimes)
## Outputs HFF format sff files.
## Author: Benjamin Barad <benjamin.barad@gmail.com> with guidance from Paul Korir
import os
import sys
import glob
@bbarad
bbarad / warp_mask_eroder.py
Last active January 24, 2023 05:24
Quickly Erode Masks from Warp
# Author: Benjamin Barad
# A quick script to erode the masks generated by warp to more tightly surround frost and beads
# Warp's neural net masking can be used to quickly remove gold beads and hunks of frost from tomograms.
# However, it tends to overmask and generate a nice big blob around each bead. This is desirable for
# limiting particle picking, but not for tomogram generation. This script erodes the mask to more tightly
# surround the frost and beads.
# Usage:
# 1. Run warp and generate masks for your tomograms with boxnet3mask
# 2. Close warp and rename the warp "mask" folder to "mask_raw"
# 3. Run this script as follows:
@bbarad
bbarad / pretilt_mdocs.py
Created April 8, 2022 00:21
Mdoc tilt adjustment for flattening tilt series on lamellae with a known pretilt
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Adapted by Benjamin Barad (benjamin.barad@gmail.com) from code by Digvijay Singh (digvijay.in1@gmail.com)
# Run in an mdocs folder, makes an "Adjusted_mdoc" subfolder with corrected angles, which allows more flexibility for
# which program is used for tilt series alignment while guaranteeing a flat tomogram. I use it with etomo and warp primarily.
# Instead of identifying the "0" tilt based on transmission, you do it based on a predetermined milling angle.
# This has benefits and disadvantages, and is particularly useful if knowing absolute orientation is useful for future
# analysis.
@bbarad
bbarad / adjust_angles.py
Created March 25, 2022 17:08
Adjust angles for all files in a folder
# Adjust angles from imod alignment before warp import to allow flattening of tomograms
# Replaces imod's taSolution.log file with adjusted deltlts, while preserving the original file in taSolution.log.bak
# Author: Benjamin Barad 2022
# Usage:
# cd WARPTOPFOLDER/imod
# python adjust_angles.py *
# Alternatively, instead of the wildcard individual tilt series folders can be specified.
import pandas as pd
@bbarad
bbarad / apply_gis.py
Created March 4, 2020 15:53
Automate GIS Application Time for Cryo FIB Milling
from autoscript_sdb_microscope_client import SdbMicroscopeClient
import time
ip_address = '192.168.0.1' # depends on system setup
open_time = 1.5 # seconds
microscope = SdbMicroscopeClient()
microscope.connect(ip_address)
gis_port = microscope.gas.get_gis_port("Pt dep")
print(gis_port.get_temperature())
gis_port.open()
time.sleep(open_time)
@bbarad
bbarad / tomoseg_to_imod.py
Created December 5, 2019 16:27
Convert segmentation HDF to .mod file appropriate for imod.
"""
Script to convert eman2 segmentation hdf maps to imod model files at a user defined contour level.
Requires python>=3.5 as well as having Eman2 and IMOD in the path.
Usage: `python3 tomoseg_to_imod.py -i EXAMPLE.hdf -o EXAMPLE.mod -t 0.8`
Author: Benjamin Barad <benjamin.barad@gmail.com>
"""
import argparse
@bbarad
bbarad / mrc_to_pngs.py
Created October 3, 2019 21:50
Convert Class Average MRC File to PNGs
import imageio
import mrcfile
import os
import sys
def make_photos(basename, working_directory="."):
"""
Convert MRC file with stack of classes to series of scaled PNGs for web viewing.
Args:
basename (str): name of desired folder within class_images - usually the same name as the mrc file.
@bbarad
bbarad / tpkl_to_dat.py
Last active July 26, 2019 16:58
Sample script to convert tpkl to dat in batch.
import parse
import trace
filename_list = ["test_1.tpkl", "test_2.tpkl"]
for filename in filename_list:
trace = parse.parse(filename)
new_name = "{}.dat".format(filename[:-5])
trace.write_dat(new_name)
javascript:!function(){
if(window.location.href.indexOf("user=")>-1)
{window.location.href=window.location.href+'&sortby=pubdate';}
else if(window.location.href.indexOf("&q=")>-1)
{window.location.href=window.location.href+'&scisbd=1';}
}();
@bbarad
bbarad / keybase.md
Created September 9, 2016 19:04
Keybase Proof

Keybase proof

I hereby claim:

  • I am bbarad on github.
  • I am bbarad (https://keybase.io/bbarad) on keybase.
  • I have a public key whose fingerprint is 15F1 05DC C3D0 E590 8B2E DA2B ABE8 2F5A C18E 2902

To claim this, I am signing this object: