plot_profile.sh 1.47 KB
Newer Older
1
#!/bin/bash
Venkat Malladi's avatar
Venkat Malladi committed
2
#plot_profile.sh
3

Venkat Malladi's avatar
Venkat Malladi committed
4
5
6
7
8
9
10
11
12
13
14
script_name="plot_profile.sh"

#Help function
usage() {
  echo "-h  --Help documentation for $script_name"
  echo "-g  --File path to gtf/bed files"
  echo "Example: $script_name -g 'genome.gtf'"
  exit 1
}


Venkat Malladi's avatar
Venkat Malladi committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
raise()
{
  echo "${1}" >&2
}

check_tools() {
	raise "
   Checking for required libraries and components on this system
   "
	 deeptools --version &> version_deeptools.txt
	 if [ $? -gt 0 ]
	 	then
			raise "Missing deeptools"
			return 1
		fi
}

compute_matrix() {
  raise "
  Computing matrix on ${1} using ${2}
  "

	computeMatrix reference-point \
		--referencePoint TSS \
		-S ${1} \
		-R ${2} \
		--skipZeros \
		-o computeMatrix.gz \
		-p max/2

  if [ $? -gt 0 ]
  then
    raise "Problem building matrix"
    return 1
  fi
}

plot_profile() {
  raise "
  Plotting profile
  "

	plotProfile -m computeMatrix.gz \
		-out plotProfile.png

  if [ $? -gt 0 ]
  then
    raise "Problem plotting"
    return 1
  fi
}


run_main() {
Venkat Malladi's avatar
Venkat Malladi committed
69
70
71

  # Parsing options
  OPTIND=1 # Reset OPTIND
Venkat Malladi's avatar
Venkat Malladi committed
72
  while getopts g:h opt
Venkat Malladi's avatar
Venkat Malladi committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
      do
          case $opt in
              g) gtf=$OPTARG;;
              h) usage;;
          esac
      done

  shift $(($OPTIND -1))

  # Check for mandatory options
  if [[ -z $gtf ]]; then
      usage
  fi

Venkat Malladi's avatar
Venkat Malladi committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
	bws=$(ls *.bw)

  check_tools || exit 1

	compute_matrix "${bws}" "${gtf}" || return 1

	plot_profile || return 1

  raise "ALL COMPLETE"
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then
  run_main
  if [ $? -gt 0 ]
  then
    exit 1
  fi
fi