Skip to content

Instantly share code, notes, and snippets.

View fomightez's full-sized avatar

Wayne's Bioinformatics Code Portal fomightez

View GitHub Profile
@fomightez
fomightez / a_text_to_dataframe.md
Last active April 5, 2024 04:03
Text lists ===> Python Pandas dataframe

(Note that if using this approach for pasting dataframes into StackOverflow, use CSV and not TSV, see here.)

Small text lists with column headers ==> Pandas dataframes

Without need for a separate file; although list could could be in separate file, and then just not use StringIO. Handy for toy code and keeping examples compact and as one file.

IMPORTANT THING IS TO HAVE import SOURCE MATCH VERSION OF PYTHON, check with import sys;print (sys.version). Or use provided approach compatible with both Python 2 and 3.

@fomightez
fomightez / useful_pandas_snippets.py
Last active September 11, 2025 18:25 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
df['Column Name'].unique() # Note, `NaN` is included as a unique value. If you just want the number, use `nunique()` which stands
# for 'number of unique values'; By default, it excludes `NaN`. `.nunique(dropna=False)` will include `NaN` in the count of unique values.
# To extract a specific column (subset the dataframe), you can use [ ] (brackets) or attribute notation.
df.height
df['height']
# are same thing!!! (from http://www.stephaniehicks.com/learnPython/pages/pandas.html
# -or-
# http://www.datacarpentry.org/python-ecology-lesson/02-index-slice-subset/)
@fomightez
fomightez / SortingBarPlotExample.ipynb
Last active January 31, 2023 11:35
llustrating Sorting bars in a Seaborn Bar Plot in Ascending Order Using Pandas
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fomightez
fomightez / Convert_DESeq2_output_for_plot_across_chromosomes.md
Last active January 25, 2018 18:33
Converting DESeq2 output to use in plot_expression_across_chromosomes.py

Converting DESeq2 output to use in plot_expression_across_chromosomes.py

This gist is for use with script described here.
(Contents converted from a file that begins with What I did to plot Shafi's DESeq2 output from and ends with with my plot_expression script.md)

Data preparation

These are the general steps for preparing the data from what DESeq2 produces. (As described in Michael Love's answer here ideally analysis of the data would be run with DESeq(dds, betaPrior=FALSE), but that wasn't done on the data provided me, and yet the aneuploidy was still obvious using the DESeq2 results to plot across the chromosomes. The fact the anueploidy was visible is consistent with the one time I tried it both ways, I didn't see much of an increase in log2FoldChange values for genes where I had seen using TPM values (Salmon-generated data there) show

@fomightez
fomightez / intro.md
Last active January 24, 2018 17:56
Introduction to Jupyter Notebooks (as of early 2018)
@fomightez
fomightez / a_note_on LATEX notebook.md
Last active December 22, 2021 09:09
Latex Example Use in a Jupyter Notebook

Looks way better rendered at nbviewer than here.

@fomightez
fomightez / using intermine and Binder.md
Last active July 16, 2018 17:54
Expanded tweet reply about using InterMine and Binder-served Jupyter notebooks...

This is a follow-up on an exchange started here. My extended reply follows...

Main use

Typically I am using the code that had been adapted from the templates into full-blown scripts to perform steps in the data analysis with the notebook as as way to perform the steps and document and package everything together.

Usually I am doing this with notebooks that either aren't ready to be shared, and so I just upload them to work on them as I develop an analysis.

@fomightez
fomightez / legend_circles.py
Created February 13, 2018 17:33 — forked from evanmiltenburg/legend_circles.py
Circles in legend
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.lines import Line2D
my_palette = sns.color_palette("cubehelix", 3)
sns.set_palette(my_palette)
def legend_circles(labels, palette, loc=1, markersize=10, marker='o', padding=0):
"Make a legend where the color is indicated by a circle."
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fomightez
fomightez / useful_python_snippets.py
Last active November 4, 2025 19:09
Useful Python snippets
# These are meant to work in both Python 2 and 3, except where noted.
# See my useful_pandas_snippets.py for those related to dataframes (such as pickling/`df.to_pickle(save_as)`)
# https://gist.github.com/fomightez/ef57387b5d23106fabd4e02dab6819b4
# also see https://gist.github.com/fomightez/324b7446dc08e56c83fa2d7af2b89a33 for examples of my
# frequently used Python functions and slight variations for more expanded, modular structures.
#argparse
# good snippet collection at https://mkaz.tech/code/python-argparse-cookbook/