annotate hilbertvis.sh @ 1:e1a9ad05dced draft default tip

Uploaded tool help images.
author devteam
date Tue, 03 Jun 2014 15:26:14 -0400
parents 0e80ffa5b7f7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
1 #!/usr/bin/env bash
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
2
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
3 input_file="$1"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
4 output_file="$2"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
5 chromInfo_file="$3"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
6 chrom="$4"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
7 score_col="$5"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
8 hilbert_curve_level="$6"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
9 summarization_mode="$7"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
10 chrom_col="$8"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
11 start_col="$9"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
12 end_col="${10}"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
13 strand_col="${11}"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
14
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
15 ## use first sequence if chrom filed is empty
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
16 if [ -z "$chrom" ]; then
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
17 chrom=$( head -n 1 "$input_file" | cut -f$chrom_col )
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
18 fi
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
19
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
20 ## get sequence length
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
21 if [ ! -r "$chromInfo_file" ]; then
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
22 echo "Unable to read chromInfo_file $chromInfo_file" 1>&2
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
23 exit 1
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
24 fi
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
25
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
26 chrom_len=$( awk '$1 == chrom {print $2}' chrom=$chrom $chromInfo_file )
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
27
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
28 ## error if we can't find the chrom_len
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
29 if [ -z "$chrom_len" ]; then
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
30 echo "Can't find length for sequence \"$chrom\" in chromInfo_file $chromInfo_file" 1>&2
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
31 exit 1
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
32 fi
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
33
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
34 ## make sure chrom_len is positive
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
35 if [ $chrom_len -le 0 ]; then
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
36 echo "sequence \"$chrom\" length $chrom_len <= 0" 1>&2
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
37 exit 1
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
38 fi
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
39
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
40 ## modify R script depending on the inclusion of a score column, strand information
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
41 input_cols="\$${start_col}, \$${end_col}"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
42 col_types='beg=0, end=0, strand=""'
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
43
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
44 # if strand_col == 0 (strandCol metadata is not set), assume everything's on the plus strand
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
45 if [ $strand_col -ne 0 ]; then
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
46 input_cols="${input_cols}, \$${strand_col}"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
47 else
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
48 input_cols="${input_cols}, \\\"+\\\""
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
49 fi
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
50
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
51 # set plot value (either from data or use a constant value)
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
52 if [ $score_col -eq -1 ]; then
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
53 value=1
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
54 else
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
55 input_cols="${input_cols}, \$${score_col}"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
56 col_types="${col_types}, score=0"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
57 value='chunk$score[i]'
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
58 fi
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
59
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
60 R --vanilla &> /dev/null <<endOfCode
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
61 library(HilbertVis);
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
62
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
63 chrom_len <- ${chrom_len};
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
64 chunk_size <- 1000;
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
65 interval_count <- 0;
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
66 invalid_strand <- 0;
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
67
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
68 awk_cmd <- paste(
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
69 "awk 'BEGIN{FS=\"\t\";OFS=\"\t\"}",
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
70 "\$${chrom_col} == \"${chrom}\"",
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
71 "{print ${input_cols}}' ${input_file}"
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
72 );
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
73
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
74 col_types <- list(${col_types});
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
75 vec <- vector(mode="numeric", length=chrom_len);
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
76 conn <- pipe(description=awk_cmd, open="r");
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
77
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
78 repeat {
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
79 chunk <- scan(file=conn, what=col_types, sep="\t", nlines=chunk_size, quiet=TRUE);
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
80
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
81 if ((rows <- length(chunk\$beg)) == 0)
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
82 break;
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
83
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
84 interval_count <- interval_count + rows;
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
85
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
86 for (i in 1:rows) {
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
87 if (chunk\$strand[i] == '+') {
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
88 start <- chunk\$beg[i] + 1;
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
89 stop <- chunk\$end[i];
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
90 } else if (chunk\$strand[i] == '-') {
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
91 start <- chrom_len - chunk\$end[i] - 1;
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
92 stop <- chrom_len - chunk\$beg[i];
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
93 } else {
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
94 invalid_strand <- invalid_strand + 1;
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
95 interval_count <- interval_count - 1;
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
96 next;
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
97 }
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
98 vec[start:stop] <- ${value};
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
99 }
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
100 }
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
101
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
102 close(conn);
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
103
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
104 hMat <- hilbertImage(vec, level=$hilbert_curve_level, mode="$summarization_mode");
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
105 pdf(file="$output_file", onefile=TRUE, width=8, height=10.5, paper="letter");
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
106 showHilbertImage(hMat);
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
107 dev.off();
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
108 endOfCode
0e80ffa5b7f7 Uploaded tool tarball.
devteam
parents:
diff changeset
109