Skip to content

Instantly share code, notes, and snippets.

@shahpnmlab
shahpnmlab / install-vim.sh
Created July 19, 2020 23:16 — forked from lboulard/install-vim.sh
Compile Vim 8 on Centos 7
# Source: https://www.netroby.com/view/3891
yum groupinstall "Development Tools"
yum install ncurses-devel git-core
git clone [email protected]:vim/vim.git
./configure --prefix=/usr --with-features=huge --enable-multibyte --with-python-config-dir=/usr/lib/python2.7/config --enable-pythoninterp=yes
make -j4
make install
@shahpnmlab
shahpnmlab / pick2d.py
Last active March 14, 2022 23:49
create segmentation masks
import napari
import mrcfile
import numpy as np
from pathlib import Path
from magicgui import magicgui
from napari.types import LabelsData, PointsData, ImageData
from scipy.ndimage import distance_transform_edt
@shahpnmlab
shahpnmlab / plotFSCwrp.py
Last active September 6, 2024 21:16
Make a pretty FSC plot
import starfile
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# Read the data
warp_apo_df = starfile.read("warp_apo/apoferritin_fsc.star")
pyco_apo_df = starfile.read("pyco_apo/apoferritin_fsc.star")
# Create the plot
@shahpnmlab
shahpnmlab / csv2star.py
Created August 30, 2024 16:56
writing a starfile
import os
import glob
import pandas as pd
import starfile
# Function to read CSV files
def read_csv_files(directory):
all_data = []
for filename in glob.glob(os.path.join(directory, '*.csv')):
df = pd.read_csv(filename, header=None, names=['X', 'Y', 'Z'])
@shahpnmlab
shahpnmlab / star2mod.py
Last active October 14, 2024 10:31
Convert star file to imod mod for viz
import starfile
import typer
from pathlib import Path
import subprocess
import os
star2mod = typer.Typer(add_completion=False)
@star2mod.command(no_args_is_help=True)
@shahpnmlab
shahpnmlab / mod2mask.py
Last active September 16, 2024 12:07
Generate binary masks from IMOD model files (and saves them as MRC files).
import typer
import logging
from pathlib import Path
import imodmodel
import numpy as np
import matplotlib.path as mplPath
import mrcfile
from scipy.interpolate import interp1d
app = typer.Typer(add_completion=False)
@shahpnmlab
shahpnmlab / starout.py
Created September 17, 2024 12:58
starfile writing example
import starfile
import pandas as pd
df_optics = pd.DataFrame({
'rlnOpticsGroup': [1],
"rlnOpticsGroupName": ["OpticsGroup1"],
'rlnSphericalAberration': [2.7],
'rlnVoltage': [300],
'rlnImagePixelSize': [5],
'rlnImageDimensionality': [3]
@shahpnmlab
shahpnmlab / frames_from_mdoc.py
Last active November 4, 2024 22:00
copy_subset_frames_from_mdoc
from pathlib import Path
import mdocfile
import shutil
import typer
import logging
from typing import Optional
# Configure logging
logging.basicConfig(
level=logging.INFO,
@shahpnmlab
shahpnmlab / warpPick2mod.py
Last active November 4, 2024 15:15
Plot warp picked coords using IMOD
import numpy as np
import starfile
XDIM = 378
YDIM = 378
ZDIM = 228
df = starfile.read("gs07_ts_003_8.00Apx_emd_13474_clean.star")
xyz_headings = [f'rlnCoordinate{axis}' for axis in 'XYZ']
xyz_headings.append('rlnAutopickFigureOfMerit')
@shahpnmlab
shahpnmlab / mod2star.py
Created November 5, 2024 14:13
Script to generate a single star file from mod files
from pathlib import Path
import imodmodel
import starfile
import pandas as pd
import numpy as np
# Create optics dataframe
df_optics = pd.DataFrame({
'rlnOpticsGroup': [1],
'rlnOpticsGroupName': ["OpticsGroup1"],