# Processing Histone centric data

bedops --everything  H3K4me1_filtered_peaks.bed H3K27ac_filtered_peaks.bed | bedops -m --range -1 - > Histone_putative_enhancers.bed


# RPKM Filtering
# Get RPKM
./rpkm.py --peaks Histone_putative_enhancers.bed --experiments h3k27ac_list.csv -f Histone_h3k27ac --minimum 1
./rpkm.py --peaks Histone_putative_enhancers.bed --experiments h3k4me1_list.csv -f Histone_h3k4me1 --minimum 1
./rpkm.py --peaks Histone_putative_enhancers.bed --experiments putative_histone_enhancers.csv -f Histone_pe --minimum 0

awk -F\, '{print $0 "\tHE_" NR}' Histone_pe_filtered_peaks.bed > t
mv t Histone_pe_filtered_peaks.bed

grep chrom Histone_pe_filtered_peaks.tsv | awk -F\, '{print $0 "\tname"}' > t
grep -v chrom Histone_pe_filtered_peaks.tsv | awk -F\, '{print $0 "\tHE_" NR}' >> t
mv t Histone_pe_filtered_peaks.tsv

# Acutal Processing
python histone_enhancer_plots.py

# Getting surround 1kb
python extend_histone_1kb.py -e ES_D0_Histone_enhancers.bed -o ES_D0_Histone_enhancers_1kb
python extend_histone_1kb.py -e ES_D2_Histone_enhancers.bed -o ES_D2_Histone_enhancers_1kb
python extend_histone_1kb.py -e ES_D5_Histone_enhancers.bed -o ES_D5_Histone_enhancers_1kb
python extend_histone_1kb.py -e ES_D7_Histone_enhancers.bed -o ES_D7_Histone_enhancers_1kb
python extend_histone_1kb.py -e ES_D10_Histone_enhancers.bed -o ES_D10_Histone_enhancers_1kb


# Meme processing
#!/bin/bash

#SBATCH --job-name=fasta_processing
#SBATCH --partition=super
#SBATCH --nodes=2
#SBATCH --ntasks=64
#SBATCH --time=0-36:00:00
#SBATCH --output=fasta_processing.%j.out
#SBATCH --error=fasta_processing.%j.err
#SBATCH --mail-user=venkat.malladi@utsouthwestern.edu
#SBATCH --mail-type=ALL
# Fasta file processing

module load bedtools
bedtools getfasta -fi /project/apps_database/iGenomes/Homo_sapiens/UCSC/hg19/Sequence/WholeGenomeFasta/genome.fa -bed ES_D0_Histone_enhancers_1kb.bed -fo  ES_D0_Histone_enhancers.fasta -name
bedtools getfasta -fi /project/apps_database/iGenomes/Homo_sapiens/UCSC/hg19/Sequence/WholeGenomeFasta/genome.fa -bed ES_D2_Histone_enhancers_1kb.bed -fo  ES_D2_Histone_enhancers.fasta -name
bedtools getfasta -fi /project/apps_database/iGenomes/Homo_sapiens/UCSC/hg19/Sequence/WholeGenomeFasta/genome.fa -bed ES_D5_Histone_enhancers_1kb.bed -fo  ES_D5_Histone_enhancers.fasta -name
bedtools getfasta -fi /project/apps_database/iGenomes/Homo_sapiens/UCSC/hg19/Sequence/WholeGenomeFasta/genome.fa -bed ES_D7_Histone_enhancers_1kb.bed -fo  ES_D7_Histone_enhancers.fasta -name
bedtools getfasta -fi /project/apps_database/iGenomes/Homo_sapiens/UCSC/hg19/Sequence/WholeGenomeFasta/genome.fa -bed ES_D10_Histone_enhancers_1kb.bed -fo  ES_D10_Histone_enhancers.fasta -name

# Meme processing
#!/bin/bash

#SBATCH --job-name=meme_test
#SBATCH --partition=super
#SBATCH --nodes=2
#SBATCH --ntasks=64
#SBATCH --time=0-36:00:00
#SBATCH --output=meme_test.%j.out
#SBATCH --error=meme_test.%j.err
#SBATCH --mail-user=venkat.malladi@utsouthwestern.edu
#SBATCH --mail-type=ALL

module load meme/4.11.0-intel-mvapich2


#!/bin/bash

#SBATCH --job-name=meme_test
#SBATCH --output=meme_test.%j.out
#SBATCH --error=meme_test.%j.err
#SBATCH --mail-user=venkat.malladi@utsouthwestern.edu
# Use super partition
#SBATCH --partition=super

# Use 2 nodes
#SBATCH -N 2

# Total of 96 tasks
#SBATCH -n 96

#SBATCH -t 1:0:0

module add meme/4.11.1-gcc-openmpi
meme-chip -meme-p -dna -meme-mod zoops -meme-nmotifs 15 -meme-minw 8 -meme-maxw 15 -meme-maxsize 20000000 -db /project/GCRB/Lee_Lab/shared/For_CBs/databases/meme_motif_databases/JASPAR/JASPAR_CORE_2016.meme ES_D0_Histone_enhancers_1kb.fasta -o MEME_op_ES_D0_Histone_enhancers_1kb_zoops
meme -meme-p -dna -meme-mod zoops -meme-nmotifs 15 -meme-minw 8 -meme-maxw 15 -meme-maxsize 20000000 -revcomp ES_D2_H3K27ac_filtered_peaks.fasta -o MEME_op_ES_D2_H3K27ac_1kb_zoops
meme -meme-p -dna -meme-mod zoops -meme-nmotifs 15 -meme-minw 8 -meme-maxw 15 -meme-maxsize 20000000 -revcomp ES_D5_H3K27ac_filtered_peaks.fasta -o MEME_op_ES_D5_H3K27ac_1kb_zoops
meme -meme-p -dna -meme-mod zoops -meme-nmotifs 15 -meme-minw 8 -meme-maxw 15 -meme-maxsize 20000000 -revcomp ES_D7_H3K27ac_filtered_peaks.fasta -o MEME_op_ES_D7_H3K27ac_1kb_zoops
meme -meme-p -dna -meme-mod zoops -meme-nmotifs 15 -meme-minw 8 -meme-maxw 15 -meme-maxsize 20000000 -revcomp ES_D10_H3K27ac_filtered_peaks.fasta -o MEME_op_ES_D10_H3K27ac_1kb_zoops
