Skip to content

Commit

Permalink
Send an email to the PMET admin when a new job is submitted.
Browse files Browse the repository at this point in the history
  • Loading branch information
duocang committed Sep 8, 2024
1 parent 9a2c2b4 commit e445c4e
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 62 deletions.
8 changes: 6 additions & 2 deletions PMETdev/intervals_index_pair.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/bash
set -e

# disable warnings
Expand Down Expand Up @@ -143,6 +143,11 @@ memefile=$2
[ ! -d $indexingOutputDir ] && mkdir $indexingOutputDir
# cd $indexingOutputDir


Rscript R/utils/send_mail.R "[email protected]" $email

Rscript R/utils/send_mail.R $email

print_green "Preparing sequences...";

# final pmet binary requires the universe file. Need to create this if validation scrip didnt.
Expand All @@ -167,7 +172,6 @@ if [[ ! -f "$universefile" || ! -f "$indexingOutputDir/promoter_lengths.txt" ]];

cut -f 1 $indexingOutputDir/promoter_lengths.txt > $universefile
fi

# now we can actually FIMO our way to victory
fasta-get-markov $genomefile > $indexingOutputDir/genome.bg
# FIMO barfs ALL the output. that's not good. time for individual FIMOs
Expand Down
13 changes: 7 additions & 6 deletions PMETdev/promoters_index_pair.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ mkdir -p $indexingOutputDir

start=$SECONDS


Rscript R/utils/send_mail.R "[email protected]" $email
Rscript R/utils/send_mail.R $email
# -------------------------------------------------------------------------------------------
# 1. sort annotaion by gene coordinates
print_fluorescent_yellow " 1. Sorting annotation by gene coordinates"
Expand All @@ -173,7 +174,10 @@ fi
print_fluorescent_yellow " 3. Extracting chromosome, start, end, gene ..."

# 使用grep查找字符串 check if gene_id is present
if grep -q "$gff3id" "$indexingOutputDir/genelines.gff3"; then
grep -q "$gff3id" $indexingOutputDir/genelines.gff3

# 检查状态码 check presence
if [ $? -eq 0 ]; then
python3 $pmetroot/parse_genelines.py $gff3id $indexingOutputDir/genelines.gff3 $bedfile
else
gff3id='ID='
Expand Down Expand Up @@ -229,10 +233,7 @@ bedtools flank \
-l $promlength \
-r 0 -s -i $bedfile \
-g $indexingOutputDir/bedgenome.genome \
> $indexingOutputDir/promoters_not_sorted.bed
# Sort by starting coordinate
sortBed -i $indexingOutputDir/promoters_not_sorted.bed > $indexingOutputDir/promoters.bed
rm -rf $indexingOutputDir/promoters_not_sorted.bed
> $indexingOutputDir/promoters.bed

# -------------------------------------------------------------------------------------------
print_fluorescent_yellow " 8.1 Remove promoters with less than 20 base pairs"
Expand Down
13 changes: 8 additions & 5 deletions PMETdev/promoters_index_pair_new_fimo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ mkdir -p $indexingOutputDir

start=$SECONDS

Rscript R/utils/send_mail.R "[email protected]" $email
Rscript R/utils/send_mail.R $email

print_green "Preparing data for FIMO and PMET index..."

# -------------------------------------------------------------------------------------------
Expand All @@ -220,7 +223,10 @@ fi
print_light_blue " 3. Extracting chromosome, start, end, gene ..."

# 使用grep查找字符串 check if gene_id is present
if grep -q "$gff3id" "$indexingOutputDir/genelines.gff3"; then
grep -q "$gff3id" $indexingOutputDir/genelines.gff3

# 检查状态码 check presence
if [ $? -eq 0 ]; then
python3 $pmetroot/parse_genelines.py $gff3id $indexingOutputDir/genelines.gff3 $bedfile
else
gff3id='ID='
Expand Down Expand Up @@ -275,10 +281,7 @@ bedtools flank \
-l $promlength \
-r 0 -s -i $bedfile \
-g $indexingOutputDir/bedgenome.genome \
> $indexingOutputDir/promoters_not_sorted.bed
# Sort by starting coordinate
sortBed -i $indexingOutputDir/promoters_not_sorted.bed > $indexingOutputDir/promoters.bed
rm -rf $indexingOutputDir/promoters_not_sorted.bed
> $indexingOutputDir/promoters.bed

# -------------------------------------------------------------------------------------------
print_fluorescent_yellow " 8.1 Remove promoters with less than 20 base pairs"
Expand Down
3 changes: 3 additions & 0 deletions PMETdev/promoters_only_pair.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ while getopts ":d:g:i:t:o:e:l:" options; do
esac
done

Rscript R/utils/send_mail.R "[email protected]" $email
Rscript R/utils/send_mail.R $email

# ------------------------------------ Run pmet ----------------------------------

mkdir -p $outputdir
Expand Down
112 changes: 63 additions & 49 deletions R/utils/send_mail.R
Original file line number Diff line number Diff line change
@@ -1,44 +1,3 @@
# library(mailR)

# # Define a function to send an email
# # Arguments:
# # recipient: The recipient of the email
# # result_link: The result link of the email
# SendResultMail <- function(recipient = NULL, result_link = NULL) {
# sender <- "[email protected]"

# subject <- "PMET result is ready!"
# body <- paste("Dear PMET user,\n\n\n",
# result_link,
# "The result will be kept in the server for a week, please download it as soon as possible.\n\n\n Thank you!", sep = "\n\n")

# send.mail(
# from = sender,
# to = recipient,
# subject = subject,
# body = body,
# smtp = list(
# host.name = "v095996.kasserver.com",
# port = 587,
# user.name = "",
# passwd = "",
# ssl = TRUE
# ),
# authenticate = TRUE,
# send = TRUE,
# # attach.files = emailFile,
# encoding = "utf-8"
# )
# }


# args <- commandArgs(trailingOnly = TRUE)

# recipient <- args[1]
# result_link <- args[2]

# SendResultMail(recipient = recipient, result_link = result_link)

library(dplyr)
library(emayili)

Expand All @@ -53,15 +12,70 @@ SendResultMail <- function(recipient = NULL, result_link = NULL) {

sender <- EMAIL_ADDRESS

subject <- "PMET result is ready!"
body <- paste(
"\n\n\nDear PMET user,\n\n\n",
"Please copy and paste the link into a browser if cliking failed\n\n",
result_link,
"\nThe result will be kept in the server for a week, please download it as soon as possible.\n\n\n Thank you!",
sep = "\n\n"
if (is.null(result_link)) {
subject <- "PMET is running, please be patient!"

body <- paste(
'<!DOCTYPE html>',
'<html>',
'<head>',
'<meta charset="UTF-8">',
'<style>',
' body { font-family: Arial, sans-serif; line-height: 1.8; background-color: #f4f4f4; margin: 0; padding: 0; }',
' .container { max-width: 600px; margin: 40px auto; padding: 20px; background-color: #ffffff; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }',
' h2 { color: #333333; margin-bottom: 20px; }',
' p { font-size: 15px; color: #555555; margin: 10px 0; }',
' .note { font-size: 13px; color: #999999; margin-top: 20px; }',
' .footer { font-size: 13px; color: #888888; margin-top: 40px; text-align: center; }',
'</style>',
'</head>',
'<body>',
'<div class="container">',
'<h2>Dear PMET User,</h2>',
'<p>Your request is currently being processed. The results will be sent to your mailbox once PMET has completed its analysis.</p>',
'<p class="note">If you do not receive the results within two days, please reply to this email for further assistance.</p>',
'<p>Thank you for your patience!</p>',
'<div class="footer">Best regards,<br/>The PMET Team</div>',
'</div>',
'</body>',
'</html>',
sep = ""
)
} else {
subject <- "PMET result is ready!"
body <- paste(
'<!DOCTYPE html>',
'<html>',
'<head>',
'<meta charset="UTF-8">',
'<style>',
' body { font-family: Arial, sans-serif; line-height: 1.8; background-color: #f4f4f4; margin: 0; padding: 0; }',
' .container { max-width: 600px; margin: 40px auto; padding: 20px; background-color: #ffffff; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }',
' h2 { color: #333333; margin-bottom: 20px; }',
' p { font-size: 15px; color: #555555; margin: 10px 0; }',
' .link { font-size: 16px; color: #1a73e8; text-decoration: none; word-wrap: break-word; }',
' .link:hover { text-decoration: underline; }',
' .note { font-size: 13px; color: #999999; margin-top: 20px; }',
' .footer { font-size: 13px; color: #888888; margin-top: 40px; text-align: center; }',
'</style>',
'</head>',
'<body>',
'<div class="container">',
'<h2>Dear PMET User,</h2>',
'<p>We are pleased to inform you that your results are ready. Please click the link below to access your results. If the link does not work, you can copy and paste it into your browser’s address bar.</p>',
'<p><a href="', result_link, '" class="link">', result_link, '</a></p>',
'<p class="note">Please note: The results will be available on the server for one week. We recommend downloading your results at your earliest convenience.</p>',
'<p>If you have any questions or need further assistance, feel free to reply to this email.</p>',
'<p>Thank you for using our services!</p>',
'<div class="footer">Best regards,<br/>The PMET Team</div>',
'</div>',
'</body>',
'</html>',
sep = ""
)

}

smtp <- emayili::server(
host = EMAIL_SERVER,
port = EMAIL_PORT,
Expand All @@ -79,6 +93,6 @@ SendResultMail <- function(recipient = NULL, result_link = NULL) {
args <- commandArgs(trailingOnly = TRUE)

recipient <- args[1]
result_link <- args[2]
result_link <- if (length(args) >= 2) args[2] else NULL

SendResultMail(recipient = recipient, result_link = result_link)

0 comments on commit e445c4e

Please sign in to comment.