Automated RNA Sequencing Workflow Deployment with Makefile

I wrote a Makefile to quickly deploy a small project that automates the integration of RNA sequencing via email.

This small project automatically clears all files under the entire project directory approximately every week, so quick automated deployment is quite necessary.

The format layout presented may have issues, and directly copying it might cause problems; you can use AI to quickly organize the format.

I am sharing something that may seem useless to everyone, but I actually want to tell bioinformatics workers that Makefile is very useful, and it is worth learning when you have time.

The Makefile is as follows:

# RNA automation integration process # Here we use hierarchical dependencies

# <target> : <prerequisites> 
# [tab]  <commands>

SHELL := /bin/bash

# Default values can be modified through parameters; variables should not end with spaces, as this may cause issues.
WORKDIR ?= .
pyinstaller ?= pyinstaller

# Generate absolute path
ifeq ($(WORKDIR),.)
override WORKDIR := $(shell readlink -f $(WORKDIR))
endif

.PHONY: decompress delete permission pack pipline clean

run_all: decompress delete permission pack pipline clean

decompress:
# Unzip files
 [[ ! -f $(WORKDIR)/scripts/bamdst/chromosome.list.v2.bed.gz ]] || gunzip $(WORKDIR)/scripts/bamdst/chromosome.list.v2.bed.gz

delete: decompress
 @echo "# Deleting temporary files"
 find $(WORKDIR) -type f -name "*md" |xargs -I{} rm {}
 find $(WORKDIR) -type f -name "*[Bb][Aa][Kk]" |xargs -I{} rm {}
# R language project
 find $(WORKDIR) -type f -name "*.Rproj" |xargs -I{} rm {}
# Example scripts
 find $(WORKDIR) -type d -name "example*" |xargs -I{} rm -r {}

permission: delete
 @echo "# Granting permissions"
 find $(WORKDIR) -type f -name "*[sp][hyl]" |xargs -I{} chmod u+x {}

# Since $(WORKDIR)/run_monitor_new_DNA_Result.py script is deleted, it cannot be written in dependencies.
# Here we wrote the virtual target of the previous step
# Block commands { } cannot appear on separate lines.
$(WORKDIR)/run_monitor_new_DNA_Result: permission
 @echo "# run_monitor_new_DNA_Result"
 [[ ! -f $(WORKDIR)/run_monitor_new_DNA_Result.py ]] || \
 { $(pyinstaller) --onefile --clean $(WORKDIR)/run_monitor_new_DNA_Result.py && \
 cp $(WORKDIR)/dist/run_monitor_new_DNA_Result $(WORKDIR) && \
 rm -rf $(WORKDIR)/run_monitor_new_DNA_Result.py; }

$(WORKDIR)/run_monitor_new_RNA_Raw_data: permission
 @echo "# run_monitor_new_RNA_Raw_data"
 [[ ! -f $(WORKDIR)/run_monitor_new_RNA_Raw_data.py ]] || \
 { $(pyinstaller) --onefile --clean $(WORKDIR)/run_monitor_new_RNA_Raw_data.py && \
 cp $(WORKDIR)/dist/run_monitor_new_RNA_Raw_data $(WORKDIR) && \
 rm -rf $(WORKDIR)/run_monitor_new_RNA_Raw_data.py; }

$(WORKDIR)/run_send_mail_to_myself: permission
 @echo "# run_send_mail_to_myself"
 [[ ! -f $(WORKDIR)/run_send_mail_to_myself.py ]] || \
 { $(pyinstaller) --onefile --clean $(WORKDIR)/run_send_mail_to_myself.py && \
 cp $(WORKDIR)/dist/run_send_mail_to_myself $(WORKDIR) && \
 rm -rf $(WORKDIR)/run_send_mail_to_myself.py; }

# Package the three files into a virtual target for easier testing and updates
# make pack
pack: $(WORKDIR)/run_monitor_new_RNA_Raw_data $(WORKDIR)/run_monitor_new_DNA_Result $(WORKDIR)/run_send_mail_to_myself
 @echo "# pyinstaller packaging..."
 rm -rf $(WORKDIR)/dist
 rm -rf $(WORKDIR)/build
 rm -rf $(WORKDIR)/run_monitor_new_DNA_Result.spec
 rm -rf $(WORKDIR)/run_monitor_new_RNA_Raw_data.spec
 rm -rf $(WORKDIR)/run_send_mail_to_myself.spec 

pipeline: pack
 @echo "# Submitting scheduled tasks..."
 nohup bash run_RNA_pipe_monitor.sh &&
 nohup bash run_WES_result_monitor.sh &&

clean: pipeline
 rm -f $(WORKDIR)/Makefile

Leave a Comment