Skip to content

Instantly share code, notes, and snippets.

View mattgalbraith's full-sized avatar

mattgalbraith

  • Linda Crnic Institute for Down Syndrome
  • University of Colorado Anschutz Medical Campus
View GitHub Profile
@mattgalbraith
mattgalbraith / integer_breaks.R
Created June 25, 2025 22:00
Integer breaks in ggplot
tibble(x = seq(0, 15, by = 0.5), y = seq(0, 15, by = 0.5)) |>
ggplot(aes(x, y)) +
geom_point() +
scale_y_continuous(breaks = \(x) seq(0, max(x), by = 1))
@mattgalbraith
mattgalbraith / FASTQ_check.sh
Last active March 4, 2025 20:11
FASTQ checks
# Check length of reads
zcat FASTQ_FILE.gz | head -n40 | paste - - - - | cut -f2,2 | awk '{print length}'
# Check number and distribution of quality scores
zcat FASTQ_FILE.gz | head -n400000 | paste - - - - | cut -f 4 | sed -e $'s/\(.\)/\\1\\\n/g' | sort | uniq -c
@mattgalbraith
mattgalbraith / .gitignore
Created May 17, 2024 15:44
Git ignore file for R Projects
# Ignore .DS_Store
.DS_Store
# Ignore R image files
rdata/*RData
#####################################
# From Github R .gitignore template #
#####################################
# History files
@mattgalbraith
mattgalbraith / wget_CVATICA_download.txt
Last active October 12, 2023 22:38
Download files from CAVATICA via text files with temporary (48hrs) file links
cat download_links.txt | xargs -P 1 wget --content-disposition --trust-server-names -nv -a wget_downloading.log
@mattgalbraith
mattgalbraith / temp_BAM_FASTQ_cleanup_and_transfer.sh
Created February 17, 2023 04:36
Clean up temporary FASTQ and BAM files from BaSH_*seq v1.2 pipeline
# Run from inside analysis_dir
echo "Original disk usage:" > temp_BAM_files_deleted.txt
du -hs $PWD >> temp_BAM_files_deleted.txt
echo "##########" >> temp_BAM_files_deleted.txt
echo "Deletion of temporary BAM files:" >> temp_BAM_files_deleted.txt
# Delete temp bam files
for BAM in $(find $PWD/Sample_*/Alignments/ -name *mapped.no-rgid.bam); do echo $BAM >> temp_BAM_files_deleted.txt; rm $BAM; done
for BAM in $(find $PWD/Sample_*/Alignments/ -name *mapped.rgid.bam); do echo $BAM >> temp_BAM_files_deleted.txt; rm $BAM; done
@mattgalbraith
mattgalbraith / GitHub_repo_setup.md
Last active January 14, 2025 05:31
GitHub repo setup

Set up new GitHub repo and push from local

  1. Create local repo and create/add/edit required files and dirs
    eg README.md, Dockerfile, .gitignore, .github/workflows/docker-image.yml

  2. On GitHub select "New repository" from the "+" menu and set name to match local repo.
    Do not add any template files.

  3. Initialize up local repo and push to GitHub:
    (assumes currently in local repo root dir)

@mattgalbraith
mattgalbraith / gg_color_hue.R
Created February 1, 2023 18:27
R function to get hex codes for standard ggplot colors
# get standard ggplot colors
gg_color_hue <- function(n) {
hues = seq(15, 375, length = n + 1)
hcl(h = hues, l = 65, c = 100)[1:n]
}
@mattgalbraith
mattgalbraith / obj_size.R
Created February 1, 2023 18:25
R function to get object size in human-readable units
obj_size <- function(x) object.size(x) %>% print(units = "auto")
@mattgalbraith
mattgalbraith / mem_used.R
Created February 1, 2023 18:25
R function to check current memory usage
mem_used <- function() lobstr::mem_used() %>% as.numeric() %>% R.utils::hsize()
@mattgalbraith
mattgalbraith / export_excel.R
Last active February 1, 2023 18:37
R function to export tables in XLSX format
## Excel export function
export_excel <- function(named_list, filename = "") {
wb <- openxlsx::createWorkbook()
## Loop through the list of split tables as well as their names
## and add each one as a sheet to the workbook
Map(function(data, name){
openxlsx::addWorksheet(wb, name)
openxlsx::writeData(wb, name, data)
}, named_list, names(named_list))
## Save workbook to working directory
close