Skip to content

Instantly share code, notes, and snippets.

View skurscheid's full-sized avatar

Sebastian Kurscheid skurscheid

View GitHub Profile
@skurscheid
skurscheid / xargs_realpath_ln.sh
Created March 9, 2023 13:15
create_symbolic_links_from_directory_content
#!/bin/bash
#this command takes the list of all files in the current directory,
#excludes all files that contain "Undetermined" in their filename
#gets the realpath for the given file
#and creates a symbolic link in the $newpath
export newpath="/this/is/the/new/path"
ls . | grep -v Undetermined | xargs -d $'\n' sh -c 'for arg do path=$(realpath "$arg"); ln -s ${path} ${newpath}"$arg"; done' _
@skurscheid
skurscheid / tar_md5_function.sh
Created June 13, 2020 03:36
Bash function to generate TAR file of a directory with MD5 checksums of included fly; can be used in conjunction with ls | xargs -n1 -I% bash -c 'tar_md5 "$*"' _ % to loop over directory contents
#!/bin/bash
function tar_md5 {
DIR=${1}
if [[ -d $DIR ]]
then
tar -cvpf ${DIR}.tar ${DIR}/| xargs -I '{}' sh -c "test -f '{}' && md5sum '{}'" | tee ${DIR}.md5
fi
@skurscheid
skurscheid / tar_w_md5sum.sh
Created June 12, 2020 01:23
creating a tar file with on-the-fly md5sum check of included content - example
#!/bin/bash
# from: https://serverfault.com/questions/120582/creating-a-tar-file-with-checksums-included#120597
tar -cvpf mybackup.tar myfiles/| xargs -I '{}' sh -c "test -f '{}' && md5sum '{}'" | tee mybackup.md5
@skurscheid
skurscheid / activate_conda_in_bash.sh
Created May 22, 2020 09:02
How to activate conda environments within a bash script
#!/bin/bash
eval "$(conda shell.bash hook)"
conda activate <env-name>
# https://github.com/conda/conda/issues/7980#issuecomment-492784093
@skurscheid
skurscheid / norm_factors_ercc.R
Created May 7, 2020 03:50
Function to estimate scaling factors based on ERCC spike ins when using sleuth for differential expression analysis
# this is a simple illustration of the principle
# it does not implement e.g. loess fitting to ERCC data as sugessted by Loven et al
# but rather uses the geometric mean/scaling approach as implemented in sleuth/DESeq2
# on the reduced matrix containing only ERCC spike in quantification
norm_factors_ercc <- function(mat) {
mat <- mat[grep('ERCC', rownames(mat)),]
nz <- apply(mat, 1, function(row) !any(round(row) == 0))
mat_nz <- mat[nz, , drop = FALSE]
p <- ncol(mat)
geo_means <- exp(apply(mat_nz, 1, function(row) mean(log(row))))
@skurscheid
skurscheid / cluster_profiler_GO_SK_edits.R
Created April 29, 2020 04:36
Cluster profiler processing of DESeq2 results -
library(clusterProfiler)
library(magrittr)
library(tidyverse)
library(qusage)
library(msigdbr)
library(biomaRt)
library(DOSE)
library(org.Mm.eg.db)
library(enrichplot)
library(data.table)
@skurscheid
skurscheid / PS_subdir_size.txt
Created April 6, 2020 04:36
Windows PowerShell: list subdirectories including size on disk in GB
gci -force 'C:\Users'-ErrorAction SilentlyContinue | ? { $_ -is [io.directoryinfo] } | % {
$len = 0
gci -recurse -force $_.fullname -ErrorAction SilentlyContinue | % { $len += $_.length }
$_.fullname, '{0:N2} GB' -f ($len / 1Gb)
}
@skurscheid
skurscheid / change_dir_using_sed.sh
Created April 1, 2020 21:50
use sed to change file/dir names
#!/bin/bash
for i in $(find . -type d -name 'SE'); do new=$(echo $i | sed s/SE/se/); mv $i $new; done
@skurscheid
skurscheid / isPairedSRA.py
Created March 29, 2020 23:30 — forked from deto/isPairedSRA.py
Function to determine if an SRA file has paired or single-ended reads
def isPairedSRA(filename):
filename = os.path.abspath(filename);
try:
contents = sp.check_output(["fastq-dump","-X","1","-Z","--split-spot", filename]);
except sp.CalledProcessError, e:
raise Exception("Error running fastq-dump on",filename);
if(contents.count("\n") == 4):
return False;
elif(contents.count("\n") == 8):
@skurscheid
skurscheid / install_R_openssl.sh
Created January 10, 2020 00:42
Installing R openssl package on RHEL 7.2 systems
#!/bin/bash
# find installation path of openssl-dev libraries and headers
ldconfig -p|grep ssl
# download openssl package source tarball
https://cran.r-project.org/src/contrib/openssl_1.4.1.tar.gz
# run installation from command line
sudo R CMD INSTALL --configure-vars='INCLUDE_DIR=/usr/local/openssl/include/ LIB_DIR=/usr/local/openssl/lib/' openssl_1.4.1.tar.gz