Skip to content

Instantly share code, notes, and snippets.

View Swarchal's full-sized avatar

Scott Warchal Swarchal

View GitHub Profile
@Swarchal
Swarchal / czi2tif.py
Created November 13, 2019 06:24
Convert multi-{channel, z} czi files to simple single tif
import os
import czifile
import skimage.io
import numpy as np
def read_czi(fname):
"""shape: [1, 1, channel, z, x, y, 1]"""
return fname, czifile.imread(fname)
@Swarchal
Swarchal / scroll_text.py
Created August 11, 2023 15:44
animated movie-like text printing in the terminal
import argparse
import sys
from random import choice
from string import ascii_letters
from time import sleep
charset = ascii_letters + '!@#$%^&*()[]<>./m::~`|\\"'
def scroll_text(text: str, delay: float = 0.01, n_chars: int = 5) -> None:
@Swarchal
Swarchal / find_correlation.py
Last active June 23, 2022 04:17
findCorrelation in python
import pandas as pd
import numpy as np
def find_correlation(df, thresh=0.9):
"""
Given a numeric pd.DataFrame, this will find highly correlated features,
and return a list of features to remove
params:
- df : pd.DataFrame
@Swarchal
Swarchal / find_correlation.py
Last active January 30, 2022 04:34
remove redundant columns in pandas dataframe
import pandas as pd
import numpy as np
def find_correlation(data, threshold=0.9, remove_negative=False):
"""
Given a numeric pd.DataFrame, this will find highly correlated features,
and return a list of features to remove.
Parameters
-----------
data : pandas DataFrame
import os
import tempfile
from collections import defaultdict
import string
import htsomeropy
import pandas as pd
from tqdm import tqdm
import cellprofiler_core.preferences as cpprefs
@Swarchal
Swarchal / parse_yokogawa.py
Created January 17, 2020 10:29
parse metadata from yokogawa CV{7,8}000 filepaths
import os
from collections import namedtuple
from typing import NamedTuple, List
import pandas as pd
def parse_filepath(filepath: str) -> NamedTuple:
"""
0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20
T|0|0|0|1|F|0|0|6|L|0 |1 |A |0 |4 |Z |0 |1 |C |0 |2
------------------------------------------------------
@Swarchal
Swarchal / heatmap.R
Last active September 27, 2019 22:02
heatmap.R
library(ggplot2)
library(reshape2)
df_expression <- read.csv("expression.csv")
df_molten <- melt(df_expression)
ggplot(data = df_molten,
aes(x = variable, y = MouseID, fill = value)) +
geom_raster() +
xlab("Protein") +
scale_fill_distiller(palette = "RdYlBu", trans = "log10") +
@Swarchal
Swarchal / welford.py
Created September 12, 2019 13:59
Welford's online/incremental variance calculation
class OnlineVariance:
"""Welfords online variance calculation"""
def __init__(self, arr):
self.arr = arr # np.array
self.mean = arr
self.count = 1
self._M2 = 0
def update(self, arr):
Image_Metadata_PlateID Image_Metadata_CPD_WELL_POSITION Image_Metadata_ASSAY_WELL_ROLE Image_Metadata_BROAD_ID Image_Metadata_CPD_MMOL_CONC
24277 A01 compound BRD-K18250272-003-03-7 3.02251611288227196974775712680585514568
24277 A02 compound BRD-K18316707-001-01-9 5
24277 A03 compound BRD-K18438502-001-02-6 5
24277 A04 compound BRD-K18550767-001-02-8 5
24277 A05 compound BRD-K18574842-323-03-3 2.1954869000456068493180626771633583428
24277 A06 compound BRD-K18619710-001-03-7 2.56073382027223366102019737828998599945
24277 A07 compound BRD-K18742343-001-03-2 5
24277 A08 compound BRD-K18757346-001-02-9 .5
24277 A09 compound BRD-K18779551-003-03-7 4.99999999999999999987113402061855670103
@Swarchal
Swarchal / colab_ai_fnet.py
Last active January 28, 2019 13:29
conda install packages on google colab notebooks
# install anaconda 5.10
! wget -c https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
! chmod +x Anaconda3-5.1.0-Linux-x86_64.sh
! bash ./Anaconda3-5.1.0-Linux-x86_64.sh -b -f -p /usr/local
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages/')
# install conda dependencies
! conda install -y --prefix /usr/local pytorch==0.4.0 torchvision=0.1.8 -c pytorch