├── License ├── README.md ├── e ├── heatmapS.sh.bak ├── i ├── lines.py ├── linesWithErrorBar.py ├── mfuzz.r ├── old ├── heatmap.2.sh ├── patch ├── sp_boxplot.statistics.sh.orig └── sp_scatterplotContour.bak.sh ├── p ├── python.log ├── s-plot ├── s-plot.sh ├── sp_areaplot.new.sh ├── sp_barPlot.sh ├── sp_boxplot.sh ├── sp_boxplot.statistics.sh ├── sp_boxplot_precomputed_values.sh ├── sp_colorLegend.sh ├── sp_configure.sh ├── sp_contourPlot.sh ├── sp_density2d.sh ├── sp_densityHistPlot.sh ├── sp_densityPlot.sh ├── sp_enrichmentPlot.sh ├── sp_hclust.sh ├── sp_hcluster.sh ├── sp_hcluster_gg.sh ├── sp_heatmap.2.sh ├── sp_heatmapM.sh ├── sp_heatmapS.sh ├── sp_histogram.sh ├── sp_horizontalBar.sh ├── sp_lines.sh ├── sp_lines.sh.depleted ├── sp_lines_lm.sh ├── sp_multiBar.sh ├── sp_normTest.sh ├── sp_pca.sh ├── sp_pheatmap.sh ├── sp_png2eps.sh ├── sp_pretteyHeatmap.sh ├── sp_prettyHeatmap.sh ├── sp_scatterplot.sh ├── sp_scatterplot2.sh ├── sp_scatterplot3d.sh ├── sp_scatterplotColor.sh ├── sp_scatterplotContour.bak.sh ├── sp_scatterplotContour.sh ├── sp_scatterplotDoubleVariable.sh ├── sp_scatterplotLotsData.sh ├── sp_scatterplotMatrix.sh ├── sp_upsetView.sh ├── sp_vennDiagram.sh ├── sp_volcano.sh ├── swap ├── swap2 ├── tips ├── trash ├── test ├── test.scatterplot.color.pdf └── test.scatterplot.dv.pdf └── tutorial ├── diamond.extract.matrix ├── diamond.extract.matrix.boxplot.noOutlier.png ├── diamond.extract.matrix.boxplot.noOutlier.r ├── diamond.extract.matrix.boxplot.png ├── diamond.extract.matrix.boxplot.r ├── diamond.extract.matrix.boxplot.violin.png ├── diamond.extract.matrix.boxplot.violin.r ├── diamond.extract.matrix.melt ├── diamond.extract.matrix.melt.boxplot.png ├── diamond.extract.matrix.melt.boxplot.r ├── test ├── test.boxplot.png ├── test.boxplot.r └── trash ├── diamond.matrix ├── diamond.matrix.boxplot.png ├── diamond.matrix.boxplot.r ├── diamonds.matrix ├── file.matrix ├── file.matrix.boxplot.png └── file.matrix.boxplot.r /README.md: -------------------------------------------------------------------------------- 1 | ### s-plot 2 | ===== 3 | A simple plot library based on `bash`, `R` mainly `ggplot2` to make 4 | the plot easily and flexibly. 5 | 6 | This lists the basic information for using [`s-plot`](https://github.com/Tong-Chen/Plot/blob/master/s-plot). 7 | 8 | #### Currently supported plots 9 | 10 | Please type `s-plot` in command line directly to have the latest list. 11 | 12 | ``` 13 | #### Bars 14 | ${filename} barPlot 15 | ${filename} horizontalBar 16 | ${filename} multiBar 17 | ${filename} colorBar 18 | 19 | #### Lines 20 | ${filename} lines 21 | 22 | #### Dots 23 | ${filename} pca 24 | ${filename} scatterplot 25 | ${filename} scatterplot2 26 | ${filename} scatterplotColor 27 | ${filename} scatterplotContour 28 | ${filename} scatterplotLotsData 29 | ${filename} scatterplotMatrix 30 | ${filename} scatterplotDoubleVariable 31 | ${filename} contourPlot 32 | 33 | #### Distribution 34 | ${filename} areaplot 35 | ${filename} boxplot 36 | ${filename} densityPlot 37 | ${filename} densityHistPlot 38 | ${filename} histogram 39 | 40 | #### Cluster 41 | ${filename} hcluster_gg (latest) 42 | ${filename} hcluster 43 | ${filename} hclust (depleted) 44 | 45 | #### Heatmap 46 | ${filename} heatmapS 47 | ${filename} heatmapM 48 | ${filename} heatmap.2 49 | ${filename} pheatmap 50 | ${filename} pretteyHeatmap 51 | 52 | #### Others 53 | ${filename} volcano 54 | ${filename} vennDiagram 55 | ${filename} upsetView 56 | ``` 57 | 58 | #### Basic test data set 59 | 60 | Here lists the general information of `diamonds` dataset that comes packaged with `ggplot2`. 61 | 62 | This dataset contains ~50,000 entries. Each row is an individual diamond, and some of the variables of interest include the weight of the diamond in carats, color, clarity, and its price. 63 | 64 | One can get, save and view the dataset using below commands. Or download data set from 65 | 66 | * [diamond.extract.matrix](https://github.com/Tong-Chen/Plot/blob/master/diamond.extract.matrix) 67 | * [diamond.extract.matrix.melt](https://github.com/Tong-Chen/Plot/blob/master/diamond.extract.matrix.melt) 68 | 69 | ```r 70 | > library(ggplot2) 71 | > data(diamonds) 72 | 73 | > head(diamonds) 74 | carat cut color clarity depth table price x y z 75 | 1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43 76 | 2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31 77 | 3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31 78 | 4 0.29 Premium I VS2 62.4 58 334 4.20 4.23 2.63 79 | 5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75 80 | 6 0.24 Very Good J VVS2 62.8 57 336 3.94 3.96 2.48 81 | 82 | > summary(diamonds) 83 | carat cut color clarity depth 84 | Min. :0.2000 Fair : 1610 D: 6775 SI1 :13065 Min. :43.00 85 | 1st Qu.:0.4000 Good : 4906 E: 9797 VS2 :12258 1st Qu.:61.00 86 | Median :0.7000 Very Good:12082 F: 9542 SI2 : 9194 Median :61.80 87 | Mean :0.7979 Premium :13791 G:11292 VS1 : 8171 Mean :61.75 88 | 3rd Qu.:1.0400 Ideal :21551 H: 8304 VVS2 : 5066 3rd Qu.:62.50 89 | Max. :5.0100 I: 5422 VVS1 : 3655 Max. :79.00 90 | J: 2808 (Other): 2531 91 | table price x y 92 | Min. :43.00 Min. : 326 Min. : 0.000 Min. : 0.000 93 | 1st Qu.:56.00 1st Qu.: 950 1st Qu.: 4.710 1st Qu.: 4.720 94 | Median :57.00 Median : 2401 Median : 5.700 Median : 5.710 95 | Mean :57.46 Mean : 3933 Mean : 5.731 Mean : 5.735 96 | 3rd Qu.:59.00 3rd Qu.: 5324 3rd Qu.: 6.540 3rd Qu.: 6.540 97 | Max. :95.00 Max. :18823 Max. :10.740 Max. :58.900 98 | 99 | z 100 | Min. : 0.000 101 | 1st Qu.: 2.910 102 | Median : 3.530 103 | Mean : 3.539 104 | 3rd Qu.: 4.040 105 | Max. :31.800 106 | 107 | #col.names=NA can generate an empty string to represent the name of first column 108 | > write.table(diamonds, file="diamond.matrix",sep="\t", col.names=NA, row.names=T, quote=F) 109 | 110 | #melt data set 111 | > library(reshape2) 112 | 113 | #Default all non-numerical column will be used as id variables 114 | #melt will group each data value into combinations of factor variable or categorial variable. 115 | > data_m <- melt(diamonds) 116 | Using cut, color, clarity as id variables 117 | 118 | > head(data_m) 119 | cut color clarity variable value 120 | 1 Ideal E SI2 carat 0.23 121 | 2 Premium E SI1 carat 0.21 122 | 3 Good E VS1 carat 0.23 123 | 4 Premium I VS2 carat 0.29 124 | 5 Good J SI2 carat 0.31 125 | 6 Very Good J VVS2 carat 0.24 126 | 127 | # Extract four columns from full data sets 128 | > diamonds_extract <- diamonds[c(1,2,3,7)] 129 | > diamonds_extract$price <- diamonds_extract$price / 1000 130 | > head(diamonds_extract) 131 | carat cut color price 132 | 1 0.23 Ideal E 0.326 133 | 2 0.21 Premium E 0.326 134 | 3 0.23 Good E 0.327 135 | 4 0.29 Premium I 0.334 136 | 5 0.31 Good J 0.335 137 | 6 0.24 Very Good J 0.336 138 | > write.table(diamonds_extract, file="diamond.extract.matrix",sep="\t", col.names=NA, row.names=T, quote=F) 139 | 140 | > diamonds_extract_melt <- melt(diamonds_extract) 141 | Using cut, color as id variables 142 | > head(diamonds_extract_melt) 143 | cut color variable value 144 | 1 Ideal E carat 0.23 145 | 2 Premium E carat 0.21 146 | 3 Good E carat 0.23 147 | 4 Premium I carat 0.29 148 | 5 Good J carat 0.31 149 | 6 Very Good J carat 0.24 150 | 151 | > tail(diamonds_extract_melt) 152 | cut color variable value 153 | 107875 Premium D price 2.757 154 | 107876 Ideal D price 2.757 155 | 107877 Good D price 2.757 156 | 107878 Very Good D price 2.757 157 | 107879 Premium H price 2.757 158 | 107880 Ideal D price 2.757 159 | 160 | > write.table(diamonds_extract_melt, file="diamond.extract.matrix.melt",sep="\t", row.names=F, quote=F) 161 | ``` 162 | 163 | #### Basic layouts and themes 164 | 165 | * Legend position 166 | 167 | Defult, the legend is posited at the right of pictures. One can give `top` to `-p` to put the legend above pictures. Other accepted strings to `-p` is `bottom`,`left`,`right`, or `c(0.008,0.8)`. The two element numerical vactor indicats the reltaive position of legend in pictures. 0.008 means position relative y-axis and 0.8 means position relative to x-axis. Specially, `c(1,1)` put legends at top-right. 168 | 169 | * Width, Height, Resolution, type of output pictures 170 | 171 | Default, width is `20 cm`, one can give `number` to `-w` to change it. Height is `12 cm`, give `number` to `-u` to change height. Give `number` to `-r` to alter resolution instead of using `300` as default. 172 | 173 | 8 picture formats are supported, `eps/ps`, `tex` (pictex), `pdf`, `jpeg`, `tiff`, `bmp`, `svg` and `wmf`, with `png` as default. Give any mentioned string to `-E` to change output format. 174 | 175 | * Title, xlab, ylab of picture 176 | 177 | One can set title, xlab, ylab with `-t`, `-x`, `-y`. 178 | 179 | * Install modules 180 | 181 | Give `TRUE` to `-i` to install required modules for the first time. (`i` is shorted for `install`) 182 | 183 | Give `FALSE` to `-e` if you only want to get the R scripts instead of running them. (`e` is shorted for `execute`) 184 | 185 | Ref: 186 | 187 | -------------------------------------------------------------------------------- /e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/e -------------------------------------------------------------------------------- /heatmapS.sh.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/heatmapS.sh.bak -------------------------------------------------------------------------------- /i: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/i -------------------------------------------------------------------------------- /lines.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | #from __future__ import division, with_statement 4 | ''' 5 | Copyright 2010, 陈同 (chentong_biology@163.com). 6 | Please see the license file for legal information. 7 | =========================================================== 8 | ''' 9 | __author__ = 'chentong & ct586[9]' 10 | __author_email__ = 'chentong_biology@163.com' 11 | #========================================================= 12 | import sys 13 | import os 14 | 15 | def main(): 16 | if len(sys.argv) < 2 : 17 | print >>sys.stderr, "Output a png graph file with the \ 18 | filename given as prefix." 19 | print >>sys.stderr, ''' 20 | File Format:(with a header line, startswith a '#'. This is necessary 21 | and is used to annotate the first line not as data.) 22 | #sample iso1 iso2 iso3 iso4 23 | sample1 0.345 0.35 0.43 0.89 24 | sample2 1.234 9.23 20.1 0 25 | sample3 5.02 3.42 0.33 0.01 26 | sample4 5.60 0.01 0.03 4.3 27 | ####################### 28 | Note: sample column is the x-axis label 29 | sample row is the legend 30 | The column number is not allowed to be larger than 37. 31 | ''' 32 | print >>sys.stderr, 'Using python %s filename \ 33 | legend[default with legend, which is your itms in your first line, \ 34 | if there are many items, it would be better to tun it off by supply\ 35 | a 0 here.] xtics[default text xtics, if number supply a 0] \ 36 | preaditionallines[; seperate multiple lines] postaditionallines \ 37 | xlabel ylabel title [lines or linespoints]' % sys.argv[0] 38 | sys.exit(0) 39 | #--------------------------------- 40 | lenpara = len(sys.argv) 41 | legendornot = 1 42 | if lenpara >= 3: 43 | legendornot = int(sys.argv[2]) 44 | #------------------------------- 45 | xticsornot = 1 #text xtics 46 | xticsvalue = '' 47 | if lenpara >= 4: 48 | xticsornot = int(sys.argv[3]) 49 | xticsvalue = '1:' 50 | #------------------------------- 51 | pregnu = '' 52 | if lenpara >= 5: 53 | pregnu = sys.argv[4] 54 | #------------------------------- 55 | postgnu = '' 56 | if lenpara >= 6: 57 | postgnu = sys.argv[5] 58 | #------------------------------- 59 | xlabel = '' 60 | if lenpara >= 7: 61 | xlabel = sys.argv[6] 62 | #------------------------------- 63 | ylabel = '' 64 | if lenpara >= 8: 65 | ylabel = sys.argv[7] 66 | #------------------------------- 67 | title = '' 68 | if lenpara >= 9: 69 | title = sys.argv[8] 70 | #------------------------------- 71 | style = 'lines' 72 | if lenpara >=10: 73 | style = sys.argv[9] 74 | #------------------------------- 75 | lsDict = {2:' ls 1', 3:' ls 2', 4:' ls 3', 5:' ls 4', 76 | 6:' ls 5', 7:' ls 6', 8:' ls 7', 9:' ls 8', 77 | 10:' ls 9', 11:' ls 10', 12:' ls 11', 13:' ls 12', 78 | 14:' ls 13', 15:' ls 14', 16:' ls 15', 17:' ls 16', 79 | 18:' ls 17', 19:' ls 18', 20:' ls 19', 21:' ls 20', 80 | 22:' ls 21', 23:' ls 22', 24:' ls 23', 25:' ls 24', 81 | 26:' ls 25', 27:' ls 26', 28:' ls 27', 29:' ls 28', 82 | 30:' ls 29', 31:' ls 30', 32:' ls 31', 33:' ls 32', 83 | 34:' ls 33', 35:' ls 34', 36:' ls 35', 37:' ls 36' 84 | } 85 | #----------------------------- 86 | sample = [] 87 | header = 1 88 | for line in open(sys.argv[1]): 89 | if header: 90 | header = 0 91 | lineL = line.strip().split("\t") 92 | plot = 'plot ' + '\'' + sys.argv[1] + '\' ' 93 | pos = 1 94 | for item in lineL[1:]: 95 | pos += 1 96 | if pos == 2: 97 | plot += 'using ' + xticsvalue + str(pos) + \ 98 | ' title ' + '\'' +\ 99 | item + '\'' + ' with ' + style + lsDict[pos] 100 | else: 101 | plot += ',\'\' using ' + xticsvalue + str(pos) + ' title ' + '\'' +\ 102 | item + '\'' + ' with ' + style + lsDict[pos] 103 | #--------------------------------------- 104 | else: 105 | tmp = line.split("\t",1)[0] 106 | sample.append(tmp) 107 | #-------------------------------------------- 108 | xtics = 'set xtics (' 109 | i48 = -1 110 | for item in sample: 111 | i48 += 1 112 | if item == '-': 113 | continue 114 | if i48 == 0: 115 | xtics += '\'' + item + '\' ' + str(i48) 116 | else: 117 | xtics += ',\'' + item + '\' ' + str(i48) 118 | xtics += ')' 119 | #------------------------------ 120 | xrange='set xrange [-0.5:' + str(i48+0.5) + ']' 121 | #------------------------------ 122 | fileout = sys.argv[1] + '.plt' 123 | fh = open(fileout , 'w') 124 | print >>fh, 'set term png' 125 | print >>fh, "set output \'" + sys.argv[1] + '.png\'' 126 | print >>fh, ''' 127 | set style line 1 lt 1 linecolor rgb "red" lw 3 128 | set style line 2 lt 1 linecolor rgb "orange" lw 3 129 | set style line 3 lt 1 linecolor rgb "#000000" lw 3 130 | set style line 4 lt 1 linecolor rgb "green" lw 3 131 | set style line 5 lt 1 linecolor rgb "cyan" lw 3 132 | set style line 6 lt 1 linecolor rgb "blue" lw 3 133 | set style line 7 lt 1 linecolor rgb "violet" lw 3 134 | set style line 8 lt 1 linecolor rgb "olive" lw 3 135 | set style line 9 lt 1 linecolor rgb "purple" lw 3 136 | set style line 10 lt 2 linecolor rgb "red" lw 3 137 | set style line 11 lt 2 linecolor rgb "orange" lw 3 138 | set style line 12 lt 2 linecolor rgb "#000000" lw 3 139 | set style line 13 lt 2 linecolor rgb "green" lw 3 140 | set style line 14 lt 2 linecolor rgb "cyan" lw 3 141 | set style line 15 lt 2 linecolor rgb "blue" lw 3 142 | set style line 16 lt 2 linecolor rgb "violet" lw 3 143 | set style line 17 lt 2 linecolor rgb "olive" lw 3 144 | set style line 18 lt 2 linecolor rgb "purple" lw 3 145 | set style line 19 lt 3 linecolor rgb "red" lw 3 146 | set style line 20 lt 3 linecolor rgb "orange" lw 3 147 | set style line 21 lt 3 linecolor rgb "#000000" lw 3 148 | set style line 22 lt 3 linecolor rgb "green" lw 3 149 | set style line 23 lt 3 linecolor rgb "cyan" lw 3 150 | set style line 24 lt 3 linecolor rgb "blue" lw 3 151 | set style line 25 lt 3 linecolor rgb "violet" lw 3 152 | set style line 26 lt 3 linecolor rgb "olive" lw 3 153 | set style line 27 lt 3 linecolor rgb "purple" lw 3 154 | set style line 28 lt 3 linecolor rgb "red" lw 3 155 | set style line 29 lt 3 linecolor rgb "orange" lw 3 156 | set style line 30 lt 3 linecolor rgb "#000000" lw 3 157 | set style line 31 lt 3 linecolor rgb "green" lw 3 158 | set style line 32 lt 3 linecolor rgb "cyan" lw 3 159 | set style line 33 lt 3 linecolor rgb "blue" lw 3 160 | set style line 34 lt 3 linecolor rgb "violet" lw 3 161 | set style line 35 lt 3 linecolor rgb "olive" lw 3 162 | set style line 36 lt 3 linecolor rgb "purple" lw 3 163 | 164 | ''' 165 | if not legendornot: 166 | print >>fh, "set nokey" 167 | if xticsornot: 168 | print >>fh, xrange 169 | print >>fh, xtics 170 | if pregnu: 171 | print >>fh, pregnu 172 | #---------------------------- 173 | if xlabel: 174 | print >>fh, 'set xlabel \"%s\"' % xlabel 175 | if ylabel: 176 | print >>fh, 'set ylabel \"%s\"' % ylabel 177 | if title: 178 | print >>fh, 'set title \"%s\"' % title 179 | #----------------------------- 180 | print >>fh, plot 181 | if postgnu: 182 | print >>fh, postgnu 183 | print >>fh, 'exit' 184 | fh.close() 185 | cmd1 = 'gnuplot ' + fileout 186 | #cmd2 = 'convert -density 300 -flatten ' + sys.argv[1] + '.eps ' +\ 187 | # sys.argv[1] + '.png' 188 | os.system(cmd1) 189 | #os.system(cmd2) 190 | if __name__ == '__main__': 191 | main() 192 | 193 | -------------------------------------------------------------------------------- /linesWithErrorBar.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | #from __future__ import division, with_statement 4 | ''' 5 | Copyright 2010, 陈同 (chentong_biology@163.com). 6 | Please see the license file for legal information. 7 | =========================================================== 8 | ''' 9 | __author__ = 'chentong & ct586[9]' 10 | __author_email__ = 'chentong_biology@163.com' 11 | #========================================================= 12 | import sys 13 | import os 14 | 15 | def main(): 16 | if len(sys.argv) < 2 : 17 | print >>sys.stderr, "Output an eps and pdf graph file with the \ 18 | filename given as prefix." 19 | print >>sys.stderr, ''' 20 | File Format:(with a header line, startswith a '#'. This is necessary 21 | and is used to annotate the first line not as data.) 22 | #sample iso1 ylow yhigh iso2 ylow yhigh 23 | sample1 0.345 0.1 0.55 0.35 0.43 0.89 24 | sample2 1.234 1.0 1.3 9.23 20.1 0 25 | sample3 5.02 5 6 3.42 0.33 0.01 26 | sample4 5.60 5.5 6.2 0.01 0.03 4.3 27 | ####################### 28 | Note: sample column is the x-axis label 29 | sample row is the legend 30 | The column number is not allowed to be larger than 37. 31 | ''' 32 | print >>sys.stderr, 'Using python %s filename \ 33 | legend[default with legend, which is your itms in your first line, \ 34 | if there are many items, it would be better to tun it off by supply\ 35 | a 0 here.] xtics[default 1 means text xtics , if number supply a 0] \ 36 | preaditionallines[; seperate multiple lines] postaditionallines \ 37 | xlabel ylabel title [lines or linespoints]' % sys.argv[0] 38 | sys.exit(0) 39 | #--------------------------------- 40 | lenpara = len(sys.argv) 41 | legendornot = 1 42 | if lenpara >= 3: 43 | legendornot = int(sys.argv[2]) 44 | #------------------------------- 45 | xticsornot = 1 #text xtics 46 | xticsvalue = '' 47 | if lenpara >= 4: 48 | xticsornot = int(sys.argv[3]) 49 | xticsvalue = '1:' 50 | #------------------------------- 51 | pregnu = '' 52 | if lenpara >= 5: 53 | pregnu = sys.argv[4] 54 | #------------------------------- 55 | postgnu = '' 56 | if lenpara >= 6: 57 | postgnu = sys.argv[5] 58 | #------------------------------- 59 | xlabel = '' 60 | if lenpara >= 7: 61 | xlabel = sys.argv[6] 62 | #------------------------------- 63 | ylabel = '' 64 | if lenpara >= 8: 65 | ylabel = sys.argv[7] 66 | #------------------------------- 67 | title = '' 68 | if lenpara >= 9: 69 | title = sys.argv[8] 70 | #------------------------------- 71 | style = 'lines' 72 | if lenpara >=10: 73 | style = sys.argv[9] 74 | #------------------------------- 75 | lsDict = {2:' ls 1', 3:' ls 2', 4:' ls 3', 5:' ls 4', 76 | 6:' ls 5', 7:' ls 6', 8:' ls 7', 9:' ls 8', 77 | 10:' ls 9', 11:' ls 10', 12:' ls 11', 13:' ls 12', 78 | 14:' ls 13', 15:' ls 14', 16:' ls 15', 17:' ls 16', 79 | 18:' ls 17', 19:' ls 18', 20:' ls 19', 21:' ls 20', 80 | 22:' ls 21', 23:' ls 22', 24:' ls 23', 25:' ls 24', 81 | 26:' ls 25', 27:' ls 26', 28:' ls 27', 29:' ls 28', 82 | 30:' ls 29', 31:' ls 30', 32:' ls 31', 33:' ls 32', 83 | 34:' ls 33', 35:' ls 34', 36:' ls 35', 37:' ls 36' 84 | } 85 | #----------------------------- 86 | sample = [] 87 | header = 1 88 | for line in open(sys.argv[1]): 89 | if header: 90 | header = 0 91 | lineL = line.strip().split("\t") 92 | plot = 'plot ' + '\'' + sys.argv[1] + '\' ' 93 | pos = 1 94 | lenLineL = len(lineL) 95 | for i in range(1, lenLineL, 3): 96 | item = lineL[i] 97 | pos += 1 98 | errorbar = ':'.join((str(pos),str(pos+1),str(pos+2))) 99 | if pos == 2: 100 | plot += 'using ' + xticsvalue + str(pos) + \ 101 | ' title ' + '\'' +\ 102 | item + '\'' + ' with ' + style + lsDict[pos] 103 | plot += ',\'\' using ' + xticsvalue + errorbar + \ 104 | ' with errorbar notitle' + lsDict[pos] 105 | else: 106 | plot += ',\'\' using ' + xticsvalue + str(pos) + ' title ' + '\'' +\ 107 | item + '\'' + ' with ' + style + lsDict[pos] 108 | plot += ',\'\' using ' + xticsvalue + errorbar + \ 109 | ' with errorbar notitle' + lsDict[pos] 110 | #--------------------------------------- 111 | else: 112 | tmp = line.split("\t",1)[0] 113 | sample.append(tmp) 114 | #-------------------------------------------- 115 | xtics = 'set xtics (' 116 | i48 = -1 117 | for item in sample: 118 | i48 += 1 119 | if item == '-': 120 | continue 121 | if i48 == 0: 122 | xtics += '\'' + item + '\' ' + str(i48) 123 | else: 124 | xtics += ',\'' + item + '\' ' + str(i48) 125 | xtics += ')' 126 | #------------------------------ 127 | xrange='set xrange [-0.5:' + str(i48+0.5) + ']' 128 | #------------------------------ 129 | fileout = sys.argv[1] + '.plt' 130 | fh = open(fileout , 'w') 131 | print >>fh, 'set term postscript eps color' 132 | print >>fh, "set output \'" + sys.argv[1] + '.eps\'' 133 | print >>fh, ''' 134 | set style line 1 lt 1 linecolor rgb "red" lw 3 135 | set style line 2 lt 1 linecolor rgb "orange" lw 3 136 | set style line 3 lt 1 linecolor rgb "#000000" lw 3 137 | set style line 4 lt 1 linecolor rgb "green" lw 3 138 | set style line 5 lt 1 linecolor rgb "cyan" lw 3 139 | set style line 6 lt 1 linecolor rgb "blue" lw 3 140 | set style line 7 lt 1 linecolor rgb "violet" lw 3 141 | set style line 8 lt 1 linecolor rgb "olive" lw 3 142 | set style line 9 lt 1 linecolor rgb "purple" lw 3 143 | set style line 10 lt 2 linecolor rgb "red" lw 3 144 | set style line 11 lt 2 linecolor rgb "orange" lw 3 145 | set style line 12 lt 2 linecolor rgb "#000000" lw 3 146 | set style line 13 lt 2 linecolor rgb "green" lw 3 147 | set style line 14 lt 2 linecolor rgb "cyan" lw 3 148 | set style line 15 lt 2 linecolor rgb "blue" lw 3 149 | set style line 16 lt 2 linecolor rgb "violet" lw 3 150 | set style line 17 lt 2 linecolor rgb "olive" lw 3 151 | set style line 18 lt 2 linecolor rgb "purple" lw 3 152 | set style line 19 lt 3 linecolor rgb "red" lw 3 153 | set style line 20 lt 3 linecolor rgb "orange" lw 3 154 | set style line 21 lt 3 linecolor rgb "#000000" lw 3 155 | set style line 22 lt 3 linecolor rgb "green" lw 3 156 | set style line 23 lt 3 linecolor rgb "cyan" lw 3 157 | set style line 24 lt 3 linecolor rgb "blue" lw 3 158 | set style line 25 lt 3 linecolor rgb "violet" lw 3 159 | set style line 26 lt 3 linecolor rgb "olive" lw 3 160 | set style line 27 lt 3 linecolor rgb "purple" lw 3 161 | set style line 28 lt 3 linecolor rgb "red" lw 3 162 | set style line 29 lt 3 linecolor rgb "orange" lw 3 163 | set style line 30 lt 3 linecolor rgb "#000000" lw 3 164 | set style line 31 lt 3 linecolor rgb "green" lw 3 165 | set style line 32 lt 3 linecolor rgb "cyan" lw 3 166 | set style line 33 lt 3 linecolor rgb "blue" lw 3 167 | set style line 34 lt 3 linecolor rgb "violet" lw 3 168 | set style line 35 lt 3 linecolor rgb "olive" lw 3 169 | set style line 36 lt 3 linecolor rgb "purple" lw 3 170 | 171 | ''' 172 | if not legendornot: 173 | print >>fh, "set nokey" 174 | if xticsornot: 175 | print >>fh, xrange 176 | print >>fh, xtics 177 | if pregnu: 178 | print >>fh, pregnu 179 | #---------------------------- 180 | if xlabel: 181 | print >>fh, 'set xlabel \"%s\"' % xlabel 182 | if ylabel: 183 | print >>fh, 'set ylabel \"%s\"' % ylabel 184 | if title: 185 | print >>fh, 'set title \"%s\"' % title 186 | #----------------------------- 187 | print >>fh, plot 188 | if postgnu: 189 | print >>fh, postgnu 190 | print >>fh, 'exit' 191 | fh.close() 192 | cmd1 = 'gnuplot ' + fileout 193 | cmd2 = 'convert -density 300 -flatten ' + sys.argv[1] + '.eps ' +\ 194 | sys.argv[1] + '.png' 195 | os.system(cmd1) 196 | os.system(cmd2) 197 | if __name__ == '__main__': 198 | main() 199 | 200 | -------------------------------------------------------------------------------- /mfuzz.r: -------------------------------------------------------------------------------- 1 | #awk 'BEGIN{OFS="\t";FS="\t"}{if(FNR==1) {$1="GENE.NAME"; print "GENE.ID", $0;} else {print $1, $0}}' lsm.expr.shannon.selected >lsm.expr.shannon.selected.mfuzz 2 | 3 | file <- "lsm.expr.shannon.selected" 4 | 5 | data <- read.table(file=file, header=T,sep="\t",row.names=1) 6 | 7 | file.m <- "lsm.expr.shannon.selected.mfuzz" 8 | 9 | data.eset <- table2eset(file.m) 10 | 11 | data.eset.s <- standardise(data.eset) 12 | 13 | cl <- mfuzz(data.eset.s, c=10, m=1.25) 14 | 15 | cluster <- cl$cluster 16 | 17 | data.c <- cbind(data, cluster) 18 | 19 | data.c <- data.c[order(data.c$cluster), ] 20 | 21 | write.table(data.c, file="lsm.expr.shannon.selected.cluster", 22 | sep="\t", row.names=T, col.names=T, quote=F) 23 | 24 | transferNormalClusteredMatrixForLinePlot.py -i lsm.expr.shannon.selected.cluster >lsm.expr.shannon.selected.cluster.forLine 25 | s-plot lines -f lsm.expr.shannon.selected.cluster.forLine -m TRUE -a Sample -P none -F " + facet_wrap(~set, ncol=2, scale='free')" -G 'data_m$set <- factor(data_m$set, levels=c(1,2,3,4,5,6,7,8,9,10), ordered=T)' -w 30 -u 60 -r 50 -L "'COL_2D','GEL_2D','PS_2D','MES','COL_3D','PLGA_3D','QB_3D','EB_5d'" -B 0.5 26 | 27 | 28 | print("Output the mean value of each cluster") 29 | cluster.mean <- aggregate(data, by=list(cl$cluster), FUN=mean) 30 | write.table(t(cluster.mean), file="lsm.expr.shannon.selected.cluster.10.kmeans.cluster.mean.lines", sep='\t', col.names=F, row.names=T, quote=F) 31 | 32 | s-plot lines -f lsm.expr.shannon.selected.cluster.10.kmeans.cluster.mean.lines -B 0.5 33 | 34 | 35 | #pdf("lsm.expr.shannon.selected.cluster.pdf") 36 | #mfuzz.plot2(data.eset, cl, mforw=c(5,2), colo="fancy", x11=FALSE) 37 | #dev.off() 38 | -------------------------------------------------------------------------------- /old/heatmap.2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | usage() 4 | { 5 | cat <$file${midname}.r 183 | library(graphics) 184 | data1 = read.table("$file", header=$header, 185 | sep="\t",row.names=1, comment.char="", check.names=${checkNames}) 186 | x <- as.matrix(data1) 187 | #rc <- rainbow(nrow(x), start=0, end=.3) 188 | #cc <- rainbow(ncol(x), start=0, end=.3) 189 | library(gplots) 190 | #postscript(file="${file}${midname}.eps", onefile=FALSE, horizontal=FALSE, 191 | # paper="special", width=10, height = 12, pointsize=10) 192 | png(filename="${file}${midname}.png", width=${width}, height=${height}, 193 | res=${res}, ) 194 | break_v <- c($break_v) 195 | if (length(break_v) > 1) { 196 | 197 | hv <- heatmap.2(x, col=greenred, trace="${trace}", 198 | xlab="$xlab", ylab="$ylab", breaks=break_v, 199 | main="$title", margins=c(7,12), keysize=0.6, Rowv=${row_C}, 200 | Colv=${col_C}, dendrogram=c("${dendrogram}"), scale=c("$scale")) 201 | 202 | } else { 203 | hv <- heatmap.2(x, col=greenred(75), trace="${trace}", 204 | xlab="$xlab", ylab="$ylab", 205 | main="$title", margins=c(7,12), keysize=0.6, Rowv=${row_C}, 206 | Colv=${col_C}, dendrogram=c("${dendrogram}"), scale=c("$scale")) 207 | } 208 | dev.off() 209 | EOF 210 | 211 | if [ "${den}" = 'TRUE' ]; then 212 | if [ "$row_C" = 'TRUE' ] && [ $col_C = 'TRUE' ]; then 213 | cat <>$file${midname}.r 214 | #postscript(file="${file}${midname}.rowden.eps", onefile=FALSE, horizontal=FALSE, 215 | # paper="special", width=10, height = 12, pointsize=10) 216 | png(filename="${file}${midname}.rowden.png", width=${width}, 217 | height=${height}, res=${res} ) 218 | plot(hv\$rowDendrogram) 219 | dev.off() 220 | #postscript(file="${file}${midname}.colden.eps", onefile=FALSE, horizontal=FALSE, 221 | # paper="special", width=10, height = 12, pointsize=10) 222 | png(filename="${file}${midname}.colden.png", width=${width}, 223 | height=${height}, res=${res}) 224 | plot(hv\$colDendrogram) 225 | dev.off() 226 | EOF 227 | elif [ "$row_C" = 'TRUE' ]; then 228 | cat <>$file${midname}.r 229 | #postscript(file="${file}${midname}.rowden.eps", onefile=FALSE, horizontal=FALSE, 230 | # paper="special", width=10, height = 12, pointsize=10) 231 | png(filename="${file}${midname}.rowden.png", width=${width}, 232 | height=${height}, res=${res}) 233 | plot(hv\$rowDendrogram) 234 | dev.off() 235 | EOF 236 | elif [ "$col_C" = 'TRUE' ]; then 237 | cat <>$file${midname}.r 238 | #postscript(file="${file}${midname}.colden.eps", onefile=FALSE, horizontal=FALSE, 239 | # paper="special", width=10, height = 12, pointsize=10) 240 | png(filename="${file}${midname}.colden.png", width=${width}, 241 | height=${height}, res=${res}) 242 | plot(hv\$colDendrogram) 243 | dev.off() 244 | EOF 245 | fi 246 | fi 247 | 248 | 249 | if [ "${execute}" = 'TRUE' ]; then 250 | Rscript $file${midname}.r 251 | #epstopdf ${file}${midname}.eps 252 | #convert -density 200 -flatten ${file}${midname}.eps ${file}${midname}.png 253 | #-------------208-218--------- 254 | #if [ "${den}" = 'TRUE' ]; then 255 | # if [ "$row_C" = 'TRUE' ] && [ $col_C = 'TRUE' ]; then 256 | # convert -density 200 -flatten ${file}${midname}.rowden.eps ${file}${midname}.rowden.png 257 | # convert -density 200 -flatten ${file}${midname}.colden.eps ${file}${midname}.colden.png 258 | # elif [ "$row_C" = 'TRUE' ]; then 259 | # convert -density 200 -flatten ${file}${midname}.rowden.eps ${file}${midname}.rowden.png 260 | # elif [ "$col_C" = 'TRUE' ]; then 261 | # convert -density 200 -flatten ${file}${midname}.colden.eps ${file}${midname}.colden.png 262 | # fi 263 | #fi 264 | #-------------208-219--------- 265 | fi 266 | -------------------------------------------------------------------------------- /old/patch: -------------------------------------------------------------------------------- 1 | 144c144 2 | < midname=".boxplot.${method}" 3 | --- 4 | > mid=".boxplot.${method}" 5 | 147c147 6 | < cat <${file}${midname}.r 7 | --- 8 | > cat <${file}${mid}.r 9 | 222c222 10 | < Rscript ${file}${midname}.r 11 | --- 12 | > Rscript ${file}${mid}.r 13 | -------------------------------------------------------------------------------- /old/sp_boxplot.statistics.sh.orig: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Only for debugging 4 | #set -x 5 | 6 | usage() 7 | { 8 | cat <${file}${mid}.r 146 | 147 | if ($ist){ 148 | #install.packages("ggplot2", repo="http://cran.us.r-project.org") 149 | } 150 | 151 | if(! $melted){ 152 | 153 | data <- read.table(file="${file}", sep="\t", header=$header, 154 | row.names=1) 155 | if ("$xvariable" != "variable"){ 156 | data_m <- melt(data, id.vars=c("${xvariable}")) 157 | } else { 158 | data_m <- melt(data) 159 | } 160 | } else { 161 | data_m <- read.table(file="$file", sep="\t", 162 | header=$header) 163 | } 164 | 165 | if ("${legend_cut}" != ""){ 166 | data_m\$variable <- cut(data_m\$variable, ${legend_cut}) 167 | } 168 | if ("${x_cut}" != ""){ 169 | data_m\$${xvariable} <- cut(data_m\$${xvariable},${x_cut}) 170 | } 171 | 172 | if ("$xvariable" == "variable"){ 173 | #No Group information 174 | print(${method}(value~variable, data=data_m)) 175 | } else { 176 | #Compute several groups 177 | group <- names(summary(data_m\$${xvariable})) 178 | for (i in group){ 179 | tmp <- data_m[data_m\$${xvariable}==i,] 180 | print(paste("*** Compute for Group ", i, " ***")) 181 | print(${method}(value~variable, data=tmp)) 182 | } 183 | } 184 | 185 | END 186 | 187 | if [ "$execute" == "TRUE" ]; then 188 | Rscript ${file}${mid}.r 189 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 190 | fi 191 | 192 | -------------------------------------------------------------------------------- /old/sp_scatterplotContour.bak.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <&2 "Please give filename, xval and yval." 113 | usage 114 | exit 1 115 | fi 116 | 117 | 118 | if [ ! -z $group ]; then 119 | group='|'$group 120 | legend="TRUE" 121 | fi 122 | 123 | cat <${file}${mid}.r 124 | 125 | if ($ist){ 126 | install.packages("car", repo="http://cran.us.r-project.org") 127 | } 128 | library(car) 129 | data <- read.table(file="$file", sep="\t", header=T, row.names=1) 130 | #postscript(file="${file}${mid}.eps", onefile=FALSE, 131 | #horizontal=FALSE,paper="special" , width=10, height = 12,pointsize=10) 132 | 133 | #if ($width!="" && $width >0 && $height > 0 && $res > 0){ 134 | # png(filename="${file}${mid}.png", width=$width, height=$height, 135 | # res=$res) 136 | #}else{ 137 | png(filename="${file}${mid}.png") 138 | #} 139 | 140 | scatterplot($yval~${xval}${group}, data=data, xlab="$xlab", ylab="$ylab", 141 | main="$title", label=row.names(data), id.method="identify", 142 | boxplots="xy", legend.plot=${legend}, ellipse=TRUE) 143 | dev.off() 144 | END 145 | 146 | if [ "$execute" == "TRUE" ]; then 147 | Rscript ${file}${mid}.r 148 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 149 | fi 150 | 151 | #convert -density 200 -flatten ${file}${mid}.eps ${first}${mid}.png 152 | -------------------------------------------------------------------------------- /p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/p -------------------------------------------------------------------------------- /python.log: -------------------------------------------------------------------------------- 1 | /home/chentong/home/server/pybin/transferNormalClusteredMatrixForLinePlot.py -i swap 2 | Run time : 2014-09-01 14:15:40 - 2014-09-01 14:15:40 3 | /home/chentong/home/server/pybin/transferNormalClusteredMatrixForLinePlot.py -i swap s-plot lines 4 | Run time : 2014-09-01 14:20:15 - 2014-09-01 14:20:15 5 | -------------------------------------------------------------------------------- /s-plot: -------------------------------------------------------------------------------- 1 | s-plot.sh -------------------------------------------------------------------------------- /s-plot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | filename=`basename $0` 6 | 7 | usage() 8 | { 9 | cat </dev/null 2>&1 70 | error=$? 71 | if test $error != 0; then 72 | usage 73 | echo "**Please check the program name input**" 74 | exit 1 75 | else 76 | shift 77 | ${program} "$@" 78 | fi 79 | 80 | -------------------------------------------------------------------------------- /sp_areaplot.new.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <&2 "Please give filename." 144 | usage 145 | exit 1 146 | fi 147 | 148 | 149 | cat <${file}${mid}.r 150 | 151 | if ($ist){ 152 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 153 | install.packages("reshape2", repo="http://cran.us.r-project.org") 154 | } 155 | 156 | data <- read.table(file="$file", header=T, sep="\t", quote="") 157 | 158 | if ($summary) { 159 | data.m <- melt(data, id.vars=c("$x_var")) 160 | alldata <- rep(data.m\$${x_var}, data.m\$value) 161 | print(summary(alldata)) 162 | quit() 163 | } 164 | 165 | library(ggplot2) 166 | library(reshape2) 167 | 168 | if ("$grp_var" != "FALSE"){ 169 | break_a=$break_l 170 | if (length(break_a) > 1){ 171 | group_i_0023 = c() 172 | for (i in data\$${x_var}){ 173 | outlier=1 174 | for (j in 1:length(break_a)){ 175 | if (i <= break_a[j]){ 176 | group_i_0023 = c(group_i_0023, j-1) 177 | outlier=0 178 | break 179 | } 180 | } 181 | if(outlier==1) { 182 | group_i_0023=c(group_i_0023,j-1) 183 | } 184 | } 185 | data\$${grp_var} <- group_i_0023 186 | } 187 | data.m <- melt(data, id.vars=c("${x_var}", "${grp_var}")) 188 | } else { 189 | data.m <- melt(data, id.vars=c("${x_var}")) 190 | } 191 | 192 | #data.m\$variable <- factor(data.m\$variable, levels=c('1','2','3')) 193 | 194 | p <- ggplot(data.m, aes(${x_var},value)) + geom_area(aes(fill=variable, 195 | group=variable), position='stack', alpha=0.5) + xlab(${x_label}) + 196 | ylab(${y_label}) + theme_bw() + theme(legend.title=element_blank(), 197 | panel.grid.major = element_blank(), panel.grid.minor = element_blank()) 198 | 199 | if("${grp_var}" != "FALSE"){ 200 | p <- p + facet_wrap(~${grp_var}, ncol=${ncol}, scale='free') 201 | } 202 | 203 | png(filename="${file}${mid}.png", width=$uwid, height=$vhig, 204 | res=$res) 205 | p 206 | dev.off() 207 | END 208 | 209 | if [ "$execute" == "TRUE" ]; then 210 | Rscript ${file}${mid}.r 211 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 212 | fi 213 | 214 | #if [ "$quiet" == "TRUE" ]; then 215 | # /bin/rm -f ${file}${mid}.r 216 | #fi 217 | #convert -density 200 -flatten ${file}${mid}.eps ${first}${mid}.png 218 | -------------------------------------------------------------------------------- /sp_boxplot.statistics.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Only for debugging 4 | #set -x 5 | 6 | usage() 7 | { 8 | cat <${file}${mid}.r 148 | 149 | if ($ist){ 150 | #install.packages("ggplot2", repo="http://cran.us.r-project.org") 151 | } 152 | 153 | if(! $melted){ 154 | 155 | data <- read.table(file="${file}", sep="\t", header=$header, 156 | row.names=1, quote="") 157 | if ("$xvariable" != "variable"){ 158 | data_m <- melt(data, id.vars=c("${xvariable}")) 159 | } else { 160 | data_m <- melt(data) 161 | } 162 | } else { 163 | data_m <- read.table(file="$file", sep="\t", 164 | header=$header, quote="") 165 | } 166 | 167 | if ("${legend_cut}" != ""){ 168 | data_m\$variable <- cut(data_m\$variable, ${legend_cut}) 169 | } 170 | if ("${x_cut}" != ""){ 171 | data_m\$${xvariable} <- cut(data_m\$${xvariable},${x_cut}) 172 | } 173 | 174 | if ("$xvariable" == "variable"){ 175 | #No Group information 176 | variableL <- unique(data_m\$variable) 177 | len_var <- length(variableL) 178 | if (len_var < 3){ 179 | print(${method}(value~variable, data=data_m)) 180 | } else { 181 | for(i in 1:(len_var-1)){ 182 | var1 <- variableL[i] 183 | for(j in (i+1):len_var){ 184 | var2 <- variableL[j] 185 | new_data <- data_m[data_m\$variable == var1 | 186 | data_m\$variable == var2, ] 187 | print(paste("### Compare for", var1, "and", var2, "###")) 188 | print(${method}(value~variable, data=new_data)) 189 | } 190 | } 191 | } 192 | } else { 193 | #Compute several groups 194 | group <- names(summary(data_m\$${xvariable})) 195 | for (i in group){ 196 | tmp <- data_m[data_m\$${xvariable}==i,] 197 | print(paste("*** Compute for Group ", i, " ***")) 198 | #print(${method}(value~variable, data=tmp)) 199 | 200 | variableL <- unique(tmp\$variable) 201 | len_var <- length(variableL) 202 | if (len_var < 3){ 203 | print(${method}(value~variable, data=tmp)) 204 | } else { 205 | for(i in 1:(len_var-1)){ 206 | var1 <- variableL[i] 207 | for(j in (i+1):len_var){ 208 | var2 <- variableL[j] 209 | new_data <- tmp[tmp\$variable == var1 | 210 | tmp\$variable == var2, ] 211 | print(paste("### Compare for", var1, "and", var2, "###")) 212 | print(${method}(value~variable, data=new_data)) 213 | } 214 | } 215 | } 216 | } 217 | } 218 | 219 | END 220 | 221 | if [ "$execute" == "TRUE" ]; then 222 | Rscript ${file}${mid}.r 223 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 224 | fi 225 | 226 | -------------------------------------------------------------------------------- /sp_colorLegend.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <${file}.r 136 | 137 | if ($ist){ 138 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 139 | install.packages("reshape2", repo="http://cran.us.r-project.org") 140 | install.packages("grid", repo="http://cran.us.r-project.org") 141 | } 142 | library(ggplot2) 143 | library(reshape2) 144 | library(grid) 145 | 146 | points <- c(${points}) 147 | binSize <- c(${len_bins}) 148 | 149 | len_points = length(points) 150 | len_binSize = length(binSize) 151 | 152 | data <- c(seq(points[1], points[2], length=binSize[1])) 153 | 154 | if (len_points == len_binSize+1){ 155 | for(i in 2:len_binSize){ 156 | tmp <- c(seq(points[i], points[i+1], length=binSize[i])) 157 | data <- c(data, tmp) 158 | } 159 | } else { 160 | for(i in 2:len_points-1){ 161 | tmp <- c(seq(points[i], points[i+1], length=binSize[1])) 162 | data <- c(data, tmp) 163 | } 164 | print("Unconsistent points and len_bins, using the the first 165 | element in bins as interval.") 166 | #quit() 167 | } 168 | 169 | data <- matrix(data, ncol=1) 170 | colnames(data) <- 'value' 171 | data <- as.data.frame(data) 172 | data\$id <- rownames(data) 173 | data.m <- melt(data, c('id')) 174 | data.m\$id <- factor(data.m\$id, levels=data\$id, ordered=T) 175 | #print(data.m) 176 | 177 | p <- ggplot(data.m, aes(x=variable, y=id)) + 178 | geom_tile(aes(fill=value)) + xlab($xlab) + ylab($ylab) + theme_bw() + 179 | theme(legend.title=element_blank(), 180 | panel.grid.major = element_blank(), panel.grid.minor = element_blank()) 181 | 182 | p <- p + theme(axis.ticks.x = element_blank(), 183 | legend.key=element_blank(), axis.text.y=element_blank()) 184 | 185 | if (len_points >2){ 186 | p <- p+scale_fill_gradient2(low="$xcol", mid="$mcol", 187 | high="$ycol", midpoint=points[2]) 188 | }else{ 189 | p <- p+scale_fill_gradient(low="$xcol", high="$ycol") 190 | } 191 | 192 | top='top' 193 | botttom='bottom' 194 | left='left' 195 | right='right' 196 | none='none' 197 | legend_pos_par <- ${legend_pos} 198 | 199 | p <- p + theme(legend.position=legend_pos_par) 200 | 201 | if(${legend_width} != 0) { 202 | p <- p + theme(legend.key.width=unit(${legend_width}, "cm")) 203 | } 204 | 205 | if(${legend_height} != 0) { 206 | p <- p + theme(legend.key.height=unit(${legend_height}, "cm")) 207 | } 208 | 209 | #png(filename="${file}.png", width=$uwid, height=$vhig, 210 | #res=$res) 211 | #p 212 | #dev.off() 213 | 214 | 215 | 216 | 217 | ggsave(p, filename="${file}.${ext}", dpi=$res, width=$uwid, 218 | height=$vhig, units=c("cm")) 219 | END 220 | 221 | if [ "$execute" == "TRUE" ]; then 222 | Rscript ${file}.r 223 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 224 | fi 225 | 226 | -------------------------------------------------------------------------------- /sp_configure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function ggplot2_configure { 4 | 5 | cat <>${file}${mid}.r 6 | 7 | #Configure the canvas 8 | #legend.title=element_blank(), 9 | p <- p + theme_bw() + theme( 10 | panel.grid.major = element_blank(), 11 | panel.grid.minor = element_blank(), 12 | legend.key=element_blank()) 13 | 14 | if (${xtics_angle} != 0){ 15 | if (${xtics_angle} == 90){ 16 | p <- p + theme(axis.text.x= 17 | element_text(angle=${xtics_angle},hjust=1, vjust=0.5)) 18 | }else if (${xtics_angle} == 45){ 19 | p <- p + theme(axis.text.x= 20 | element_text(angle=${xtics_angle},hjust=0.5, vjust=0.5)) 21 | } else { 22 | p <- p + theme(axis.text.x= 23 | element_text(angle=${xtics_angle},hjust=0.5, vjust=0.5)) 24 | } 25 | } 26 | 27 | #Set the position of legend 28 | top='top' 29 | botttom='bottom' 30 | left='left' 31 | right='right' 32 | none='none' 33 | legend_pos_par <- ${legend_pos} 34 | 35 | p <- p + theme(legend.position=legend_pos_par) 36 | 37 | #add additional ggplot2 supported commands 38 | 39 | p <- p${par} 40 | 41 | 42 | # output pictures 43 | 44 | if ("${ext}" == "pdf") { 45 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, 46 | height=$vhig, units=c("cm"),colormodel="${colormodel}") 47 | } else { 48 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, 49 | height=$vhig, units=c("cm")) 50 | } 51 | #png(filename="${file}${mid}.png", width=$uwid, height=$vhig, 52 | #res=$res) 53 | #p 54 | #dev.off() 55 | END 56 | } 57 | -------------------------------------------------------------------------------- /sp_contourPlot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <&2 "Please give filename, xval and yval." 188 | usage 189 | exit 1 190 | fi 191 | 192 | 193 | #if [ "$log" == "TRUE" ]; then 194 | # log=", trans=\"log\"" 195 | #fi 196 | 197 | mid=".scatterContour" 198 | 199 | if test "${user_mid}" != ""; then 200 | mid=${mid}".${user_mid}" 201 | fi 202 | 203 | cat <${file}${mid}.r 204 | 205 | if ($ist){ 206 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 207 | } 208 | 209 | library(ggplot2) 210 | 211 | data <- read.table(file="$file", sep="\t", header=T, quote="") 212 | 213 | data\$${xval} <- data\$${xval} + ${x_add} 214 | data\$${yval} <- data\$${yval} + ${y_add} 215 | data\$${zval} <- data\$${zval} + ${z_add} 216 | 217 | p <- ggplot(data,aes(${xval},${yval}, z=${zval}))+ 218 | labs(x="$xlab", y="$ylab") + ggtitle("$title") 219 | 220 | if ("${fill_contour}" == "..density..") { 221 | p <- p + stat_contour(aes(fill = ${fill_contour}), geom="tile") 222 | } else if ("${fill_contour}" == "..level.."){ 223 | p <- p + stat_contour(aes(fill = ${fill_contour}), 224 | geom="polygon") 225 | } 226 | 227 | p <- p + scale_fill_gradient(low="${low}", high="${high}") 228 | 229 | if (${points}){ 230 | p <- p + geom_point(size=0.3, alpha=0.5, color="${point_color}") 231 | } 232 | 233 | if (${scale} || ${x_add} != 0 || ${y_add} != 0) { 234 | p <- p + ${log} 235 | } 236 | 237 | p <- p + theme_bw() + theme(legend.title=element_blank(), 238 | panel.grid.major = element_blank(), panel.grid.minor = element_blank()) 239 | 240 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, 241 | height=$vhig, units=c("cm")) 242 | END 243 | 244 | if [ "$execute" == "TRUE" ]; then 245 | Rscript ${file}${mid}.r 246 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 247 | fi 248 | 249 | #convert -density 200 -flatten ${file}${mid}.eps ${first}${mid}.png 250 | -------------------------------------------------------------------------------- /sp_densityPlot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <${file}${mid}.r 235 | 236 | if ($ist){ 237 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 238 | install.packages("reshape2", repo="http://cran.us.r-project.org") 239 | install.packages("grid", repo="http://cran.us.r-project.org") 240 | } 241 | library(ggplot2) 242 | library(reshape2) 243 | library(grid) 244 | 245 | if(! $melted){ 246 | 247 | data <- read.table(file="${file}", sep="\t", header=$header, 248 | row.names=1, quote="") 249 | data_rownames <- rownames(data) 250 | data_colnames <- colnames(data) 251 | data\$${xvariable} <- data_rownames 252 | data_m <- melt(data, id.vars=c("${xvariable}")) 253 | } else { 254 | data_m <- read.table(file="$file", sep="\t", 255 | header=$header, quote="") 256 | } 257 | 258 | if (${y_add} != 0){ 259 | data_m\$value <- data_m\$value + ${y_add} 260 | } 261 | 262 | if ("${level}" != ""){ 263 | level_i <- c(${level}) 264 | data_m\$variable <- factor(data_m\$variable, levels=level_i) 265 | } else { 266 | data_m\$variable <- factor(data_m\$variable, levels=data_colnames, 267 | ordered=T) 268 | } 269 | 270 | if (${x_type}){ 271 | if ("${x_level}" != ""){ 272 | x_level <- c(${x_level}) 273 | data_m\$${xvariable} <- factor(data_m\$${xvariable},levels=x_level) 274 | }else{ 275 | data_m\$${xvariable} <- factor(data_m\$${xvariable},levels=data_rownames,ordered=TRUE) 276 | } 277 | } 278 | 279 | p <- ggplot(data_m, aes(x=$xvariable, y=value, color=variable, 280 | group=variable)) + xlab($xlab) + ylab($ylab) + theme_bw() + 281 | theme(legend.title=element_blank(), 282 | panel.grid.major = element_blank(), panel.grid.minor = element_blank()) 283 | 284 | p <- p + theme(axis.ticks.x = element_blank(), legend.key=element_blank()) 285 | #legend.background = element_rect(colour='white')) 286 | 287 | #legend.background = element_rect(fill = "white"), legend.box=NULL, 288 | #legend.margin=unit(0,"cm")) 289 | 290 | if (${smooth}){ 291 | if ("${line_size}" != ""){ 292 | p <- p + stat_smooth(method="${smooth_method}", se=FALSE, 293 | size=${line_size}) 294 | }else{ 295 | p <- p + stat_smooth(method="${smooth_method}", se=FALSE, 296 | size=${line_size}) 297 | } 298 | }else{ 299 | if ("${line_size}" != ""){ 300 | p <- p + geom_line(size=${line_size}) 301 | }else{ 302 | p <- p + geom_line() 303 | } 304 | } 305 | 306 | if("$scaleY"){ 307 | p <- p + $scaleY_x 308 | } 309 | 310 | if(${color}){ 311 | p <- p + scale_color_manual(values=c(${color_v})) 312 | } 313 | 314 | if ("$xtics" == "FALSE"){ 315 | p <- p + theme(axis.text.x=element_blank()) 316 | }else{ 317 | if (${xtics_angle} != 0){ 318 | p <- p + theme(axis.text.x=element_text(angle=${xtics_angle},hjust=1)) 319 | } 320 | } 321 | if ("$ytics" == "FALSE"){ 322 | p <- p + theme(axis.text.y=element_blank()) 323 | } 324 | 325 | 326 | top='top' 327 | botttom='bottom' 328 | left='left' 329 | right='right' 330 | none='none' 331 | legend_pos_par <- ${legend_pos} 332 | 333 | p <- p + theme(legend.position=legend_pos_par) 334 | 335 | p <- p${par} 336 | 337 | 338 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, 339 | height=$vhig, units=c("cm")) 340 | 341 | #png(filename="${file}${mid}.png", width=$uwid, height=$vhig, 342 | #res=$res) 343 | #p 344 | #dev.off() 345 | END 346 | 347 | if [ "$execute" == "TRUE" ]; then 348 | Rscript ${file}${mid}.r 349 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 350 | fi 351 | 352 | -------------------------------------------------------------------------------- /sp_hclust.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | usage() 4 | { 5 | cat <=2)] 51 | EOF 52 | } 53 | 54 | file= 55 | checkNames='TRUE' 56 | scale='FALSE' 57 | title='' 58 | xlab='' 59 | ylab='' 60 | dm='euclidean' 61 | hm='ward' 62 | header='TRUE' 63 | execute='TRUE' 64 | num=0 65 | transpose='FALSE' 66 | 67 | while getopts "hf:k:s:t:x:y:d:c:z:e:a:b:" OPTION 68 | do 69 | case $OPTION in 70 | h) 71 | usage 72 | exit 1 73 | ;; 74 | f) 75 | file=$OPTARG 76 | ;; 77 | k) 78 | checkNames=$OPTARG 79 | ;; 80 | s) 81 | scale=$OPTARG 82 | ;; 83 | t) 84 | title=$OPTARG 85 | ;; 86 | x) 87 | xlab=$OPTARG 88 | ;; 89 | y) 90 | ylab=$OPTARG 91 | ;; 92 | d) 93 | dm=$OPTARG 94 | ;; 95 | c) 96 | hm=$OPTARG 97 | ;; 98 | z) 99 | header=$OPTARG 100 | ;; 101 | e) 102 | execute=$OPTARG 103 | ;; 104 | a) 105 | num=$OPTARG 106 | ;; 107 | b) 108 | transpose=$OPTARG 109 | ;; 110 | ?) 111 | usage 112 | exit 1 113 | ;; 114 | esac 115 | done 116 | if [ -z $file ]; then 117 | usage 118 | echo "This is decrepated, please use **s-plot hcluster**" 119 | exit 1 120 | fi 121 | 122 | mid='.hclust' 123 | 124 | if [ "$scale" = 'TRUE' ]; then 125 | mid=${mid}'.scale' 126 | fi 127 | 128 | 129 | cat <$file${mid}.r 130 | library(graphics) 131 | data1 = read.table("$file", header=$header, quotes="", 132 | sep="\t",row.names=1, comment.char="", check.names=${checkNames}) 133 | x <- as.matrix(data1) 134 | if ($transpose){ 135 | x <- t(x) 136 | } 137 | if ($scale){ 138 | x <- scale(x) 139 | } 140 | d <- dist(x, method="$dm") 141 | fit <- hclust(d, method="$hm") 142 | #postscript(file="${file}${mid}.eps", onefile=FALSE,horizontal=FALSE) 143 | png(file="${file}${mid}.png", width=600, height=900, res=100) 144 | plot(fit, hang=-1, main="$title", xlab="$xlab", ylab="$ylab") 145 | if ($num){ 146 | rect.hclust(fit, k=$num, border="red") 147 | } 148 | dev.off() 149 | EOF 150 | 151 | if [ "${execute}" = 'TRUE' ]; then 152 | Rscript $file${mid}.r 153 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 154 | #epstopdf ${file}${mid}.eps 155 | #if [ $? -eq 0 ]; then 156 | #convert -density 200 -flatten ${file}${mid}.eps ${file}${mid}.png 157 | #if [ $num -ne 0 ]; then 158 | # convert -density 200 -flatten ${file}${mid}.${num}.eps ${file}${mid}.${num}.png 159 | #fi 160 | #fi 161 | fi 162 | -------------------------------------------------------------------------------- /sp_hcluster.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | usage() 4 | { 5 | cat <=2). Red lines will be displayed to label 33 | each cluster.] 34 | -t Title of picture[${txtred}Default empty title${txtrst}] 35 | -x xlab of picture[${txtred}Default empty xlab${txtrst}. 36 | If setted, using the words which represents the 37 | meaning of your columns] 38 | -y ylab of picture[${txtred}Default empty ylab${txtrst}. 39 | If setted, using the words which represents the 40 | meaning of your rows] 41 | -d Dist method[${bldred}Default "euclidean"${txtrst}] 42 | Accept "euclidean", ‘maximum", ‘manhattan", 43 | "canberra", ‘binary,," 44 | "pearson", "correlation", "spearman" or "kendall". 45 | -c hclust method[${txtred}Default "ward"${txtrst}] 46 | Accept "single", "complete", "average", "mcquitty", "median" 47 | or "centroid". 48 | -z Is there a header[${bldred}Default TRUE${txtrst}] 49 | Accept FALSE. 50 | -e Execute or not[${bldred}Default TRUE${txtrst}] 51 | Accept FALSE. 52 | EOF 53 | } 54 | 55 | file= 56 | checkNames='TRUE' 57 | scale='FALSE' 58 | title='' 59 | xlab='' 60 | ylab='' 61 | dm='euclidean' 62 | hm='ward' 63 | header='TRUE' 64 | execute='TRUE' 65 | num=0 66 | transpose='TRUE' 67 | 68 | while getopts "hf:k:s:t:x:y:d:c:z:e:a:b:" OPTION 69 | do 70 | case $OPTION in 71 | h) 72 | usage 73 | exit 1 74 | ;; 75 | f) 76 | file=$OPTARG 77 | ;; 78 | k) 79 | checkNames=$OPTARG 80 | ;; 81 | s) 82 | scale=$OPTARG 83 | ;; 84 | t) 85 | title=$OPTARG 86 | ;; 87 | x) 88 | xlab=$OPTARG 89 | ;; 90 | y) 91 | ylab=$OPTARG 92 | ;; 93 | d) 94 | dm=$OPTARG 95 | ;; 96 | c) 97 | hm=$OPTARG 98 | ;; 99 | z) 100 | header=$OPTARG 101 | ;; 102 | e) 103 | execute=$OPTARG 104 | ;; 105 | a) 106 | num=$OPTARG 107 | ;; 108 | b) 109 | transpose=$OPTARG 110 | ;; 111 | ?) 112 | usage 113 | exit 1 114 | ;; 115 | esac 116 | done 117 | if [ -z $file ]; then 118 | usage 119 | exit 1 120 | fi 121 | 122 | mid=".hcluster.${dm}.${hm}" 123 | 124 | if [ "$scale" = 'TRUE' ]; then 125 | mid=${mid}'.scale' 126 | fi 127 | 128 | 129 | cat <$file${mid}.r 130 | library(graphics) 131 | library(amap) 132 | data1 = read.table("$file", header=$header, quote="", 133 | sep="\t",row.names=1, comment.char="", check.names=${checkNames}) 134 | x <- as.matrix(data1) 135 | if ($transpose){ 136 | x <- t(x) 137 | } 138 | if ($scale){ 139 | x <- scale(x) 140 | } 141 | #d <- dist(x, method="$dm") 142 | #fit <- hclust(d, method="$hm") 143 | fit <- hcluster(x, method="$dm", link="$hm") 144 | #postscript(file="${file}${mid}.eps", onefile=FALSE, horizontal=FALSE, 145 | # paper="special", width=10, height = 12, pointsize=10) 146 | png(file="${file}${mid}.png", width=600, height=900, res=100) 147 | plot(fit, hang=-1, main="$title", xlab="$xlab", ylab="$ylab") 148 | if ($num){ 149 | rect.hclust(fit, k=$num, border="red") 150 | } 151 | dev.off() 152 | EOF 153 | 154 | if [ "${execute}" = 'TRUE' ]; then 155 | Rscript $file${mid}.r 156 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 157 | #epstopdf ${file}${mid}.eps 158 | #if [ $? -eq 0 ]; then 159 | # convert -density 200 -flatten ${file}${mid}.eps ${file}${mid}.png 160 | #if [ $num -ne 0 ]; then 161 | # convert -density 200 -flatten ${file}${mid}.${num}.eps ${file}${mid}.${num}.png 162 | #fi 163 | #fi 164 | fi 165 | -------------------------------------------------------------------------------- /sp_hcluster_gg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat < or 63 | a R function generating a list of colors.${txtrst} 64 | -I Clustering distance method for cols. 65 | ${bldred}Default 'correlation', accept 'euclidean', 66 | "manhattan", "maximum", "canberra", "binary", "minkowski". ${txtrst} 67 | -L First get log-value, then do other analysis. 68 | Accept an R function log2 or log10. 69 | ${bldred}[Default FALSE]${txtrst} 70 | -d Scale the data or not for clustering and visualization. 71 | [Default 'none' means no scale, accept 'row', 'column' to 72 | scale by row or column.] 73 | -Q A file to specify col-annotation.[${txtred}Default NA${txtrst}] 74 | -u The width of output picture.[${txtred}Default 20${txtrst}] 75 | -v The height of output picture.[${txtred}Default 20${txtrst}] 76 | -E The type of output figures.[${txtred}Default pdf, accept 77 | eps/ps, tex (pictex), png, jpeg, tiff, bmp, svg and wmf)${txtrst}] 78 | -r The resolution of output picture.[${txtred}Default 300 ppi${txtrst}] 79 | -F Font size [${txtred}Default 14${txtrst}] 80 | -e Execute or not[${bldred}Default TRUE${txtrst}] 81 | -i Install the required packages[${bldred}Default FALSE${txtrst}] 82 | 83 | Example: sp_hcluster_gg.sh -f matrix.pearson.xls -Q cluster.txt 84 | 85 | EOF 86 | } 87 | 88 | file='' 89 | title='' 90 | horizontal='FALSE' 91 | clustering_distance_cols='correlation' 92 | clustering_method='complete' 93 | legend_breaks='NA' 94 | color_vector='colorRampPalette(rev(brewer.pal(n=7, name="RdYlBu")))(100)' 95 | width='' 96 | label='' 97 | logv='FALSE' 98 | kclu='NA' 99 | scale='none' 100 | execute='TRUE' 101 | ist='FALSE' 102 | legend=' ' 103 | na_color='grey' 104 | uwid=20 105 | vhig=20 106 | res=300 107 | fontsize=14 108 | ext='pdf' 109 | colormodel='srgb' 110 | xcol='green' 111 | ycol='red' 112 | mcol='yellow' 113 | mid_value_use='FALSE' 114 | mid_value='Inf' 115 | xtics='TRUE' 116 | xtics_angle=270 117 | ytics='TRUE' 118 | gradient=1 119 | givenSepartor='' 120 | gradientC="'green','yellow','red'" 121 | generateNA='FALSE' 122 | digits='FALSE' 123 | annotation_row='NA' 124 | annotation_col='NA' 125 | preprocess='TRUE' 126 | 127 | while getopts "hf:t:a:A:b:H:R:c:D:p:I:L:d:k:u:v:E:r:F:P:Q:x:y:M:Z:X:s:m:N:Y:G:C:O:e:i:" OPTION 128 | do 129 | case $OPTION in 130 | h) 131 | echo "Help mesage" 132 | usage 133 | exit 1 134 | ;; 135 | f) 136 | file=$OPTARG 137 | ;; 138 | t) 139 | title=$OPTARG 140 | ;; 141 | a) 142 | xtics=$OPTARG 143 | ;; 144 | A) 145 | xtics_angle=$OPTARG 146 | ;; 147 | b) 148 | ytics=$OPTARG 149 | ;; 150 | H) 151 | horizontal=$OPTARG 152 | ;; 153 | R) 154 | cluster_rows=$OPTARG 155 | ;; 156 | c) 157 | clustering_method=$OPTARG 158 | ;; 159 | D) 160 | clustering_distance_rows=$OPTARG 161 | ;; 162 | I) 163 | clustering_distance_cols=$OPTARG 164 | ;; 165 | p) 166 | preprocess=$OPTARG 167 | ;; 168 | L) 169 | logv=$OPTARG 170 | ;; 171 | P) 172 | annotation_row=$OPTARG 173 | ;; 174 | Q) 175 | annotation_col=$OPTARG 176 | ;; 177 | d) 178 | scale=$OPTARG 179 | ;; 180 | k) 181 | kclu=$OPTARG 182 | ;; 183 | u) 184 | uwid=$OPTARG 185 | ;; 186 | v) 187 | vhig=$OPTARG 188 | ;; 189 | E) 190 | ext=$OPTARG 191 | ;; 192 | r) 193 | res=$OPTARG 194 | ;; 195 | F) 196 | fontsize=$OPTARG 197 | ;; 198 | x) 199 | xcol=$OPTARG 200 | ;; 201 | y) 202 | ycol=$OPTARG 203 | ;; 204 | M) 205 | mcol=$OPTARG 206 | ;; 207 | K) 208 | logv_pos=$OPTARG 209 | ;; 210 | Z) 211 | mid_value_use=$OPTARG 212 | ;; 213 | X) 214 | mid_value=$OPTARG 215 | ;; 216 | s) 217 | small=$OPTARG 218 | ;; 219 | m) 220 | maximum=$OPTARG 221 | ;; 222 | N) 223 | generateNA=$OPTARG 224 | ;; 225 | Y) 226 | na_color=$OPTARG 227 | ;; 228 | G) 229 | gradient=$OPTARG 230 | ;; 231 | C) 232 | color_vector=$OPTARG 233 | ;; 234 | O) 235 | givenSepartor=$OPTARG 236 | ;; 237 | e) 238 | execute=$OPTARG 239 | ;; 240 | i) 241 | ist=$OPTARG 242 | ;; 243 | ?) 244 | usage 245 | echo "Unknown parameters" 246 | exit 1 247 | ;; 248 | esac 249 | done 250 | 251 | mid=".hcluster" 252 | 253 | if [ -z $file ] ; then 254 | echo 1>&2 "Please give filename." 255 | usage 256 | exit 1 257 | fi 258 | 259 | 260 | if test "$log" != ''; then 261 | mid=${mid}".$log" 262 | fi 263 | 264 | if test "${scale}" == "TRUE"; then 265 | mid=${mid}".scale" 266 | fi 267 | 268 | if test "${preprocess}" == "TRUE"; then 269 | /bin/mv -f ${file} ${file}".nostd0" 270 | dealWithSTD0.py -i ${file}".nostd0" >${file} 271 | fi 272 | 273 | 274 | cat <${file}${mid}.r 275 | 276 | if ($ist){ 277 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 278 | install.packages("ggdendro", repo="http://cran.us.r-project.org") 279 | install.packages("amap", repo="http://cran.us.r-project.org") 280 | } 281 | 282 | library(ggplot2) 283 | library(ggdendro) 284 | library(amap) 285 | 286 | if($gradient){ 287 | library(RColorBrewer) 288 | } 289 | 290 | data <- read.table(file="$file", sep="\t", header=T, row.names=1, 291 | check.names=F, quote="", comment="") 292 | 293 | 294 | if ("${annotation_col}" != "NA") { 295 | annotation_col <- read.table(file="${annotation_col}", header=T, 296 | row.names=1, sep="\t", quote="", check.names=F, comment="") 297 | levs <- unique(unlist(lapply(annotation_col, unique))) 298 | annotation_col <- data.frame(lapply(annotation_col, factor, 299 | levels=levs), row.names=rownames(annotation_col)) 300 | } else { 301 | annotation_col <- NA 302 | } 303 | 304 | hc <- hcluster(data) 305 | dhc <- as.dendrogram(hc) 306 | dhc_data <- dendro_data(dhc, type="rectangle") 307 | 308 | p <- ggplot(segment(dhc_data)) + 309 | geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) + 310 | theme(axis.line.y=element_blank(), 311 | axis.ticks.y=element_blank(), 312 | axis.text.y=element_blank(), 313 | axis.title.y=element_blank(), 314 | panel.background=element_rect(fill="white"), 315 | panel.grid=element_blank(), 316 | legend.position="top") 317 | 318 | if ("${annotation_col}" != "NA") { 319 | if (${horizontal}){ 320 | p <- p + geom_text(data=dhc_data\$labels, aes(x,y,label=label, 321 | color=annotation_col[,1]), angle=90, size=2, hjust=0) + 322 | oord_flip() + scale_y_reverse(expand=c(0.2, 0)) 323 | }else { 324 | p <- p + geom_text(data=dhc_data\$labels, aes(x,y,label=label, 325 | color=annotation_col[,1]), angle=90, size=2, vjust=0) + 326 | } 327 | } else { 328 | if (${horizontal}){ 329 | p <- p + geom_text(data=dhc_data\$labels, aes(x,y,label=label), 330 | angle=90, size=2, hjust=0) + 331 | oord_flip() + scale_y_reverse(expand=c(0.2, 0)) 332 | }else { 333 | p <- p + geom_text(data=dhc_data\$labels, aes(x,y,label=label), 334 | angle=90, size=2, vjust=0) + 335 | } 336 | } 337 | 338 | if ("${ext}" == "pdf") { 339 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, 340 | height=$vhig, units=c("cm"),colormodel="${colormodel}") 341 | } else { 342 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, 343 | height=$vhig, units=c("cm")) 344 | } 345 | END 346 | 347 | 348 | if [ "$execute" == "TRUE" ]; then 349 | Rscript ${file}${mid}.r 350 | if [ "$?" == "0" ]; then 351 | /bin/rm -f ${file}${mid}.r 352 | /bin/rm -f Rplots.pdf 353 | fi 354 | fi 355 | 356 | if test "${preprocess}" == "TRUE"; then 357 | /bin/mv -f ${file}".nostd0" ${file} 358 | fi 359 | 360 | #convert -density 200 -flatten ${file}${mid}.eps ${first}${mid}.png 361 | -------------------------------------------------------------------------------- /sp_heatmap.2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | usage() 4 | { 5 | cat <$file${mid}.r 212 | 213 | if ($ist){ 214 | install.packages('gplots', repo="http://cran.us.r-project.org") 215 | } 216 | 217 | library(graphics) 218 | library(gplots) 219 | 220 | data1 = read.table("$file", header=$header, 221 | sep="\t",row.names=1, comment.char="", check.names=${checkNames}) 222 | x <- as.matrix(data1) 223 | 224 | if (${symmetric}){ 225 | hv <- heatmap.2(x, Rowv=${row_C}, Colv=${col_C}, 226 | dendrogram=c("${dendrogram}"), scale=c("$scale")) 227 | 228 | if (${row_C}){ 229 | fit_row <- hv\$rowInd 230 | fit_col <- rev(fit_row) 231 | } else if (${col_C}){ 232 | fit_col <- hv\$colInd 233 | fit_row <- rev(fit_col) 234 | } 235 | x <- x[fit_row, ] 236 | t_x <- t(x) 237 | x <- t(t_x[fit_col, ]) 238 | x <- as.matrix(x) 239 | 240 | } 241 | 242 | pdf(file="${file}${mid}.pdf", onefile=FALSE, 243 | paper="special", width=${width}, height = ${height}, 244 | pointsize=${res}) 245 | 246 | 247 | break_v <- c($break_v) 248 | if (length(break_v) > 1) { 249 | 250 | hv <- heatmap.2(x, col=${color}, trace="${trace}", 251 | xlab="$xlab", ylab="$ylab", breaks=break_v, 252 | main="$title", margins=c(7,12), keysize=0.6, Rowv=${row_C}, 253 | Colv=${col_C}, dendrogram=c("${dendrogram}"), scale=c("$scale")) 254 | 255 | } else { 256 | hv <- heatmap.2(x, col=${color}, trace="${trace}", 257 | xlab="$xlab", ylab="$ylab", 258 | main="$title", margins=c(7,12), keysize=0.6, Rowv=${row_C}, 259 | Colv=${col_C}, dendrogram=c("${dendrogram}"), scale=c("$scale")) 260 | } 261 | dev.off() 262 | EOF 263 | 264 | if [ "${den}" = 'TRUE' ]; then 265 | if [ "$row_C" = 'TRUE' ] && [ $col_C = 'TRUE' ]; then 266 | cat <>$file${mid}.r 267 | #postscript(file="${file}${mid}.rowden.eps", onefile=FALSE, horizontal=FALSE, 268 | # paper="special", width=10, height = 12, pointsize=10) 269 | pdf(file="${file}${mid}.pdf", onefile=FALSE, 270 | paper="special", width=${width}, height = ${height}, 271 | pointsize=${res}) 272 | #png(filename="${file}${mid}.rowden.png", width=${width}, 273 | #height=${height}, res=${res} ) 274 | plot(hv\$rowDendrogram) 275 | dev.off() 276 | #postscript(file="${file}${mid}.colden.eps", onefile=FALSE, horizontal=FALSE, 277 | # paper="special", width=10, height = 12, pointsize=10) 278 | #png(filename="${file}${mid}.colden.png", width=${width}, 279 | #height=${height}, res=${res}) 280 | pdf(file="${file}${mid}.pdf", onefile=FALSE, 281 | paper="special", width=${width}, height = ${height}, 282 | pointsize=${res}) 283 | plot(hv\$colDendrogram) 284 | dev.off() 285 | EOF 286 | elif [ "$row_C" = 'TRUE' ]; then 287 | cat <>$file${mid}.r 288 | #postscript(file="${file}${mid}.rowden.eps", onefile=FALSE, horizontal=FALSE, 289 | # paper="special", width=10, height = 12, pointsize=10) 290 | #png(filename="${file}${mid}.rowden.png", width=${width}, 291 | #height=${height}, res=${res}) 292 | pdf(file="${file}${mid}.pdf", onefile=FALSE, 293 | paper="special", width=${width}, height = ${height}, 294 | pointsize=${res}) 295 | plot(hv\$rowDendrogram) 296 | dev.off() 297 | EOF 298 | elif [ "$col_C" = 'TRUE' ]; then 299 | cat <>$file${mid}.r 300 | #postscript(file="${file}${mid}.colden.eps", onefile=FALSE, horizontal=FALSE, 301 | # paper="special", width=10, height = 12, pointsize=10) 302 | #png(filename="${file}${mid}.colden.png", width=${width}, 303 | #height=${height}, res=${res}) 304 | pdf(file="${file}${mid}.pdf", onefile=FALSE, 305 | paper="special", width=${width}, height = ${height}, 306 | pointsize=${res}) 307 | plot(hv\$colDendrogram) 308 | dev.off() 309 | EOF 310 | fi 311 | fi 312 | 313 | 314 | if [ "${execute}" = 'TRUE' ]; then 315 | Rscript $file${mid}.r 316 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 317 | #epstopdf ${file}${mid}.eps 318 | #convert -density 200 -flatten ${file}${mid}.eps ${file}${mid}.png 319 | #-------------208-218--------- 320 | #if [ "${den}" = 'TRUE' ]; then 321 | # if [ "$row_C" = 'TRUE' ] && [ $col_C = 'TRUE' ]; then 322 | # convert -density 200 -flatten ${file}${mid}.rowden.eps ${file}${mid}.rowden.png 323 | # convert -density 200 -flatten ${file}${mid}.colden.eps ${file}${mid}.colden.png 324 | # elif [ "$row_C" = 'TRUE' ]; then 325 | # convert -density 200 -flatten ${file}${mid}.rowden.eps ${file}${mid}.rowden.png 326 | # elif [ "$col_C" = 'TRUE' ]; then 327 | # convert -density 200 -flatten ${file}${mid}.colden.eps ${file}${mid}.colden.png 328 | # fi 329 | #fi 330 | #-------------208-219--------- 331 | fi 332 | -------------------------------------------------------------------------------- /sp_histogram.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <${file}.hist.r 110 | data1 <- read.table("${file}", header=FALSE, sep="\t", quote="") 111 | data2 <- as.vector(data1\$V${col}) 112 | break_p <- "${break_p}" 113 | if (${col_width} != 0){ 114 | break_p=ceiling(max(data2)/${col_width}) 115 | } 116 | png(file="${file}.hist.png", width=600, height=900,res=120) 117 | hist(data2, breaks=break_p, xlab="${xlab}", main=NULL) 118 | dev.off() 119 | END 120 | 121 | Rscript ${file}.hist.r 122 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 123 | 124 | 125 | -------------------------------------------------------------------------------- /sp_horizontalBar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <&2 "Please give filename and count." 100 | usage 101 | exit 1 102 | fi 103 | 104 | 105 | cat <${file}${mid}.r 106 | 107 | if ($ist){ 108 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 109 | } 110 | library(ggplot2) 111 | data <- read.table(file="$file", sep="\t", header=T, row.names=1, quote="") 112 | png(filename="${file}${mid}.png", width=1000, height=1000, res=${dpi}) 113 | 114 | p <- ggplot(data, aes(row.names(data),${count})) 115 | p <- p + geom_bar(stat="identity", fill="deepskyblue") + labs(x="${xlab}", y="${ylab}") + opts(title="${title}") 116 | 117 | #p <- p + opts(axis.text.x=theme_text(size=10)) + opts(axis.text.y=theme_text(size=14)) 118 | 119 | if (! ${normal}){ 120 | p <- p + coord_flip() 121 | } 122 | 123 | if (${log}){ 124 | p <- p + scale_y_continuous(trans="log") 125 | } 126 | p 127 | #Summary of annotation for GC percentage(31%~40%) reads 128 | dev.off() 129 | END 130 | 131 | if [ "$execute" == "TRUE" ]; then 132 | Rscript ${file}${mid}.r 133 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 134 | fi 135 | 136 | #convert -density 200 -flatten ${file}${mid}.eps ${first}${mid}.png 137 | -------------------------------------------------------------------------------- /sp_lines.sh.depleted: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <${file}${mid}.r 244 | 245 | if ($ist){ 246 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 247 | install.packages("reshape2", repo="http://cran.us.r-project.org") 248 | install.packages("grid", repo="http://cran.us.r-project.org") 249 | } 250 | library(ggplot2) 251 | library(reshape2) 252 | library(grid) 253 | 254 | if(! $melted){ 255 | 256 | data <- read.table(file="${file}", sep="\t", header=$header) 257 | data_m <- melt(data, id.vars=c("${xvariable}")) 258 | } else { 259 | data_m <- read.table(file="$file", sep="\t", 260 | header=$header) 261 | } 262 | 263 | if (${y_add} != 0){ 264 | data_m\$value <- data_m\$value + ${y_add} 265 | } 266 | 267 | if ("${level}" != ""){ 268 | level_i <- c(${level}) 269 | data_m\$variable <- factor(data_m\$variable, levels=level_i) 270 | } 271 | 272 | if (${x_type}){ 273 | if ("${x_level}" != ""){ 274 | x_level <- c(${x_level}) 275 | data_m\$${xvariable} <- factor(data_m\$${xvariable},levels=x_level) 276 | }else{ 277 | data_m\$${xvariable} <- factor(data_m\$${xvariable}) 278 | } 279 | } 280 | 281 | p <- ggplot(data_m, aes(x=$xvariable, y=value, color=variable, 282 | group=variable)) + xlab($xlab) + ylab($ylab) + theme_bw() + 283 | theme(legend.title=element_blank(), 284 | panel.grid.major = element_blank(), panel.grid.minor = element_blank()) 285 | 286 | p <- p + theme(axis.ticks.x = element_blank(), legend.key=element_blank()) 287 | #legend.background = element_rect(colour='white')) 288 | 289 | #legend.background = element_rect(fill = "white"), legend.box=NULL, 290 | #legend.margin=unit(0,"cm")) 291 | 292 | if (${smooth}){ 293 | if ("${line_size}" != ""){ 294 | p <- p + stat_smooth(method=${smooth_method}, se=FALSE, 295 | size=${line_size}) 296 | }else{ 297 | p <- p + stat_smooth(method=${smooth_method}, se=FALSE, 298 | size=1) 299 | } 300 | }else{ 301 | if ("${line_size}" != ""){ 302 | p <- p + geom_line(size=${line_size}) 303 | }else{ 304 | p <- p + geom_line() 305 | } 306 | } 307 | 308 | if("$scaleY"){ 309 | p <- p + $scaleY_x 310 | } 311 | 312 | 313 | 314 | top='top' 315 | botttom='bottom' 316 | left='left' 317 | right='right' 318 | none='none' 319 | legend_pos_par <- ${legend_pos} 320 | 321 | p <- p + theme(legend.position=legend_pos_par) 322 | 323 | p <- p${par} 324 | 325 | png(filename="${file}${mid}.png", width=$uwid, height=$vhig, 326 | res=$res) 327 | p 328 | dev.off() 329 | END 330 | 331 | if [ "$execute" == "TRUE" ]; then 332 | Rscript ${file}${mid}.r 333 | fi 334 | 335 | -------------------------------------------------------------------------------- /sp_multiBar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <${file}${mid}.r 207 | 208 | if ($ist){ 209 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 210 | install.packages("reshape2", repo="http://cran.us.r-project.org") 211 | } 212 | library(ggplot2) 213 | library(reshape2) 214 | 215 | if(! $melted){ 216 | 217 | data <- read.table(file="${file}", sep="\t", header=$header, quote="") 218 | if ("${facet}" != "haha"){ 219 | id_vars = c("${xvariable}", "${facet}" ${col_exclu}) 220 | #data_m <- melt(data, id.vars=c("${xvariable}", "${facet}")) 221 | } else { 222 | id_vars = c("${xvariable}" ${col_exclu}) 223 | #data_m <- melt(data, id.vars=c("${xvariable}")) 224 | } 225 | data_m <- melt(data, id.vars=id_vars) 226 | } else { 227 | data_m <- read.table(file="$file", sep="\t", 228 | header=$header, quote="") 229 | } 230 | 231 | if ("${legend_order}" != ""){ 232 | data_m\$variable <- factor(data_m\$variable, 233 | levels=c(${legend_order})) 234 | } 235 | 236 | if ("${xvar_order}" != ""){ 237 | data_m\$${xvariable} <- factor(data_m\$${xvariable}, 238 | levels=c(${xvar_order})) 239 | } 240 | 241 | if ("${facet_order}" != ""){ 242 | data_m\$${facet} <- factor(data_m\$${facet}, 243 | levels=c(${facet_order})) 244 | } 245 | 246 | p <- ggplot(data_m, aes(factor($xvariable), value)) + xlab($xlab) + 247 | ylab($ylab) 248 | 249 | p <- p + geom_bar(aes(fill=factor(variable)), stat="identity", 250 | position="dodge") + theme_bw() 251 | 252 | if ($angle != 0) { 253 | p <- p + theme(axis.text.x=element_text(angle=${angle},hjust=1)) 254 | } 255 | 256 | if ("$facet" != "haha"){ 257 | p <- p + facet_wrap(~${facet}, ncol=${facet_ncol}, 258 | scales="${scales}") 259 | } 260 | 261 | 262 | 263 | if("$scaleY"){ 264 | p <- p + $scaleY_x 265 | } 266 | 267 | 268 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, 269 | height=$vhig, units=c("cm")) 270 | 271 | #png(filename="${file}${mid}.png", width=$uwid, height=$vhig, 272 | #res=$res) 273 | #p 274 | #dev.off() 275 | END 276 | 277 | if [ "$execute" == "TRUE" ]; then 278 | Rscript ${file}${mid}.r 279 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 280 | fi 281 | 282 | -------------------------------------------------------------------------------- /sp_normTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Only for debugging 4 | #set -x 5 | 6 | usage() 7 | { 8 | cat <${file}${mid}.r 148 | 149 | if ($ist){ 150 | install.packages("fBasics", repo="http://cran.us.r-project.org") 151 | } 152 | 153 | if ("${method}" == "lillieTest"){ 154 | library('fBasics') 155 | } 156 | 157 | if(! $melted){ 158 | 159 | data <- read.table(file="${file}", sep="\t", header=$header, 160 | row.names=1, quote="") 161 | if ("$xvariable" != "variable"){ 162 | data_m <- melt(data, id.vars=c("${xvariable}")) 163 | } else { 164 | data_m <- melt(data) 165 | } 166 | } else { 167 | data_m <- read.table(file="$file", sep="\t", 168 | header=$header) 169 | } 170 | 171 | if ("${legend_cut}" != ""){ 172 | data_m\$variable <- cut(data_m\$variable, ${legend_cut}) 173 | } 174 | if ("${x_cut}" != ""){ 175 | data_m\$${xvariable} <- cut(data_m\$${xvariable},${x_cut}) 176 | } 177 | 178 | if ("$xvariable" == "variable"){ 179 | #No Group information 180 | variableL <- unique(data_m\$variable) 181 | len_var <- length(variableL) 182 | for(i in 1:len_var){ 183 | var1 <- variableL[i] 184 | new_data <- data_m[data_m\$variable == var1,]\$value 185 | if ("${method}" == "lillieTest"){ 186 | if (length(new_data) > 4) { 187 | print(paste("### Compute normality for", var1, "###")) 188 | print(${method}(new_data)) 189 | } else { 190 | print(paste("### No enough data for lillieTest:", var1, "###")) 191 | } 192 | } else if ("${method}" == "shapiro.test") { 193 | if (length(new_data) > 2) { 194 | print(paste("### Compute normality for", var1, "###")) 195 | print(${method}(new_data)) 196 | } else { 197 | print(paste("### No enough data for shapiro.test:", 198 | var1, "###")) 199 | } 200 | } else { 201 | print(paste("### Compute normality for", var1, "###")) 202 | print(${method}(new_data)) 203 | } 204 | } 205 | } else { 206 | #Compute several groups 207 | group <- names(summary(data_m\$${xvariable})) 208 | for (i in group){ 209 | tmp <- data_m[data_m\$${xvariable}==i,] 210 | print(paste("*** Compute for Group ", i, " ***")) 211 | 212 | variableL <- unique(tmp\$variable) 213 | len_var <- length(variableL) 214 | for(i in 1:len_var){ 215 | var1 <- variableL[i] 216 | new_data <- tmp[tmp\$variable == var1,]\$value 217 | if ("${method}" == "lillieTest"){ 218 | if (length(new_data) > 4) { 219 | print(paste("### Compute normality for", var1, "###")) 220 | print(${method}(new_data)) 221 | } else { 222 | print(paste("### No enough data for lillieTest:", 223 | var1, "###")) 224 | } 225 | } else if ("${method}" == "shapiro.test") { 226 | if (length(new_data) > 2) { 227 | print(paste("### Compute normality for", var1, "###")) 228 | print(${method}(new_data)) 229 | } else { 230 | print(paste("### No enough data for shapiro.test:", 231 | var1, "###")) 232 | } 233 | }else { 234 | print(paste("### Compute normality for", var1, "###")) 235 | print(${method}(new_data)) 236 | } 237 | } 238 | } 239 | } 240 | 241 | END 242 | 243 | if [ "$execute" == "TRUE" ]; then 244 | Rscript ${file}${mid}.r 245 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 246 | fi 247 | 248 | -------------------------------------------------------------------------------- /sp_png2eps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test $# -lt 1; then 4 | echo 1>&2 "Using $0 file.png [file2.png,...]" 5 | exit 1 6 | fi 7 | 8 | for i in $@; do 9 | prefix=`basename $i .png` 10 | pngtopnm $i >$prefix.pnm 11 | pnmtops -noturn -rle $prefix.pnm >$prefix.ps 2>/dev/null 12 | ps2epsi $prefix.ps 13 | 14 | /bin/rm -f $prefix.ps 15 | /bin/rm -f $prefix.pnm 16 | mv $prefix.epsi $prefix.eps 17 | done 18 | -------------------------------------------------------------------------------- /sp_pretteyHeatmap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ############# 3 | #CT########## 4 | ############# 5 | 6 | #set -x 7 | set -e 8 | set -u 9 | usage() 10 | { 11 | cat <] 60 | -l Parameters for s-plot heatmapS (-f is not needed). 61 | One can add new parameters to override remaining one or set new attributes. 62 | [Default: '-A 90 -T 1.5 -V 0.5 -l top -v 22 -u 15 -F 9 63 | -j TRUE -M yellow -x green -y red -Z TRUE'] 64 | EOF 65 | } 66 | 67 | file= 68 | center= 69 | preprocess=4 70 | plotwithinss='FALSE' 71 | try=10 72 | evaluation='FALSE' 73 | xlab='Value' 74 | ylab='Variable' 75 | mainT='' 76 | ly_default='-A 90 -T 1.5 -V 0.5 -l top -v 22 -u 15 -F 9 -j TRUE -M yellow -x green -y red -Z TRUE' 77 | ly='' 78 | ist='FALSE' 79 | 80 | while getopts "hf:c:P:p:t:e:x:y:m:l:i:" OPTION 81 | do 82 | case $OPTION in 83 | h) 84 | usage 85 | exit 1 86 | ;; 87 | f) 88 | file=$OPTARG 89 | ;; 90 | c) 91 | center=$OPTARG 92 | ;; 93 | P) 94 | preprocess=$OPTARG 95 | ;; 96 | p) 97 | plotwithinss=$OPTARG 98 | ;; 99 | t) 100 | try=$OPTARG 101 | ;; 102 | e) 103 | evaluation=$OPTARG 104 | ;; 105 | x) 106 | xlab=$OPTARG 107 | ;; 108 | y) 109 | ylab=$OPTARG 110 | ;; 111 | m) 112 | mainT=$OPTARG 113 | ;; 114 | i) 115 | ist=$OPTARG 116 | ;; 117 | l) 118 | ly=$OPTARG 119 | ;; 120 | ?) 121 | usage 122 | exit 1 123 | ;; 124 | esac 125 | done 126 | if [ -z $file ]; then 127 | usage 128 | exit 1 129 | fi 130 | mid='' 131 | 132 | cat <${file}${mid}.kmeans.r 133 | if (${ist}){ 134 | install.packages("cluster", repo="http://cran.us.r-project.org") 135 | install.packages("psych", repo="http://cran.us.r-project.org") 136 | install.packages("fpc", repo="http://cran.us.r-project.org") 137 | } 138 | library(cluster) 139 | library(psych) 140 | library(fpc) 141 | data <- read.table(file="$file", sep='\t', header=T, row.names=1, 142 | check.names=FALSE) 143 | data <- as.matrix(data) 144 | #Delete rows containing only zero 145 | data <- data[rowSums(data==0)${file}${mid}.kmeans.sort 188 | 189 | s-plot heatmapS -f ${file}${mid}.kmeans.sort ${ly_default} ${ly} 190 | 191 | /bin/rm -f ${file}${mid}.kmeans.sort ${file}${mid}.kmeans.r 192 | 193 | #if [ "$plotwithinss" == 'TRUE' ]; then 194 | # cat <${file}${mid}.$center.kmeans.chooseClusterNumber.r 195 | #data <- read.table(file="$file", sep='\t', header=T, row.names=1, 196 | #check.names=FALSE) 197 | #data <- as.matrix(data) 198 | ##Delate rows containing only zero 199 | #data <- data[rowSums(data==0)>>Input the cluster number : " center 228 | #else 229 | # echo "Wrong Rscript" 230 | #fi 231 | #fi 232 | 233 | #print("Output the mean value of cluster") 234 | #cluster.mean <- aggregate(data, by=list(fit\$cluster), FUN=mean) 235 | #cluster.mean.colnames <- colnames(cluster.mean) 236 | #cluster.mean.colnames[1] = paste('#',cluster.mean.colnames[1], sep='') 237 | #colnames(cluster.mean) <- cluster.mean.colnames 238 | #write.table(t(cluster.mean), file="${file}${mid}.$center.kmeans.cluster.mean.xls", sep='\t',col.names=F, row.names=T, quote=F) 239 | #print("Output the total sorted cluster name") 240 | #clust.out <- fit\$cluster 241 | #kclust <- as.matrix(clust.out) 242 | #kclust.out <- cbind(kclust, data) 243 | #means of n points in each cluster 244 | #mns <- sapply(split(data, fit\$cluster), function(x) mean(unlist(x))) 245 | #order the data 246 | #data.order <- data[order(order(mns)[fit\$cluster]),] 247 | #write.table(data.order, file="${file}${mid}.$center.kmeans.result", 248 | #sep="\t", row.names=T, col.names=T, quote=F) 249 | -------------------------------------------------------------------------------- /sp_prettyHeatmap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ############# 3 | #CT########## 4 | ############# 5 | 6 | #set -x 7 | set -e 8 | set -u 9 | usage() 10 | { 11 | cat <] 60 | -l Parameters for s-plot heatmapS (-f is not needed). 61 | One can add new parameters to override remaining one or set new attributes. 62 | [Default: '-A 90 -T 1.5 -V 0.5 -l top -v 22 -u 15 -F 9 63 | -j TRUE -M yellow -x green -y red -Z TRUE'] 64 | EOF 65 | } 66 | 67 | file= 68 | center= 69 | preprocess=4 70 | plotwithinss='FALSE' 71 | try=10 72 | evaluation='FALSE' 73 | xlab='Value' 74 | ylab='Variable' 75 | mainT='' 76 | ly_default='-A 90 -T 1.5 -V 0.5 -l top -v 22 -u 15 -F 9 -j TRUE -M yellow -x green -y red -Z TRUE' 77 | ly='' 78 | ist='FALSE' 79 | 80 | while getopts "hf:c:P:p:t:e:x:y:m:l:i:" OPTION 81 | do 82 | case $OPTION in 83 | h) 84 | usage 85 | exit 1 86 | ;; 87 | f) 88 | file=$OPTARG 89 | ;; 90 | c) 91 | center=$OPTARG 92 | ;; 93 | P) 94 | preprocess=$OPTARG 95 | ;; 96 | p) 97 | plotwithinss=$OPTARG 98 | ;; 99 | t) 100 | try=$OPTARG 101 | ;; 102 | e) 103 | evaluation=$OPTARG 104 | ;; 105 | x) 106 | xlab=$OPTARG 107 | ;; 108 | y) 109 | ylab=$OPTARG 110 | ;; 111 | m) 112 | mainT=$OPTARG 113 | ;; 114 | i) 115 | ist=$OPTARG 116 | ;; 117 | l) 118 | ly=$OPTARG 119 | ;; 120 | ?) 121 | usage 122 | exit 1 123 | ;; 124 | esac 125 | done 126 | if [ -z $file ]; then 127 | usage 128 | exit 1 129 | fi 130 | mid='' 131 | 132 | cat <${file}${mid}.kmeans.r 133 | if (${ist}){ 134 | install.packages("cluster", repo="http://cran.us.r-project.org") 135 | install.packages("psych", repo="http://cran.us.r-project.org") 136 | install.packages("fpc", repo="http://cran.us.r-project.org") 137 | } 138 | library(cluster) 139 | library(psych) 140 | library(fpc) 141 | data <- read.table(file="$file", sep='\t', header=T, row.names=1, 142 | check.names=FALSE) 143 | data <- as.matrix(data) 144 | #Delete rows containing only zero 145 | data <- data[rowSums(data==0)${file}${mid}.kmeans.sort 188 | 189 | s-plot heatmapS -f ${file}${mid}.kmeans.sort ${ly_default} ${ly} 190 | 191 | /bin/rm -f ${file}${mid}.kmeans.sort ${file}${mid}.kmeans.r 192 | 193 | #if [ "$plotwithinss" == 'TRUE' ]; then 194 | # cat <${file}${mid}.$center.kmeans.chooseClusterNumber.r 195 | #data <- read.table(file="$file", sep='\t', header=T, row.names=1, 196 | #check.names=FALSE) 197 | #data <- as.matrix(data) 198 | ##Delate rows containing only zero 199 | #data <- data[rowSums(data==0)>>Input the cluster number : " center 228 | #else 229 | # echo "Wrong Rscript" 230 | #fi 231 | #fi 232 | 233 | #print("Output the mean value of cluster") 234 | #cluster.mean <- aggregate(data, by=list(fit\$cluster), FUN=mean) 235 | #cluster.mean.colnames <- colnames(cluster.mean) 236 | #cluster.mean.colnames[1] = paste('#',cluster.mean.colnames[1], sep='') 237 | #colnames(cluster.mean) <- cluster.mean.colnames 238 | #write.table(t(cluster.mean), file="${file}${mid}.$center.kmeans.cluster.mean.xls", sep='\t',col.names=F, row.names=T, quote=F) 239 | #print("Output the total sorted cluster name") 240 | #clust.out <- fit\$cluster 241 | #kclust <- as.matrix(clust.out) 242 | #kclust.out <- cbind(kclust, data) 243 | #means of n points in each cluster 244 | #mns <- sapply(split(data, fit\$cluster), function(x) mean(unlist(x))) 245 | #order the data 246 | #data.order <- data[order(order(mns)[fit\$cluster]),] 247 | #write.table(data.order, file="${file}${mid}.$center.kmeans.result", 248 | #sep="\t", row.names=T, col.names=T, quote=F) 249 | -------------------------------------------------------------------------------- /sp_scatterplot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <&2 "Please give filename, xval and yval." 113 | usage 114 | exit 1 115 | fi 116 | 117 | 118 | if [ ! -z $group ]; then 119 | group='|'$group 120 | legend="TRUE" 121 | fi 122 | 123 | cat <${file}${mid}.r 124 | 125 | if ($ist){ 126 | install.packages("car", repo="http://cran.us.r-project.org") 127 | } 128 | library(car) 129 | data <- read.table(file="$file", sep="\t", header=T, quote="", row.names=1) 130 | #postscript(file="${file}${mid}.eps", onefile=FALSE, 131 | #horizontal=FALSE,paper="special" , width=10, height = 12,pointsize=10) 132 | 133 | if ("$width" != "" && "$height" != "" && "$res" != ""){ 134 | png(filename="${file}${mid}.png", width=$width, height=$height, 135 | res=$res) 136 | }else{ 137 | png(filename="${file}${mid}.png") 138 | } 139 | 140 | 141 | scatterplot($yval~${xval}${group}, data=data, xlab="$xlab", ylab="$ylab", 142 | main="$title", label=row.names(data), id.method="identify", 143 | boxplots="xy", legend.plot=${legend}, ellipse=TRUE) 144 | dev.off() 145 | END 146 | 147 | if [ "$execute" == "TRUE" ]; then 148 | Rscript ${file}${mid}.r 149 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 150 | fi 151 | 152 | #convert -density 200 -flatten ${file}${mid}.eps ${first}${mid}.png 153 | -------------------------------------------------------------------------------- /sp_scatterplotColor.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | 6 | 7 | 8 | usage() 9 | { 10 | cat <&2 "Please give filename, xval and yval." 190 | usage 191 | exit 1 192 | fi 193 | 194 | 195 | if [ -z $col_legend ]; then 196 | col_legend="$color" 197 | fi 198 | 199 | if [ ! -z $log ]; then 200 | log=", trans=\"${log}\"" 201 | fi 202 | 203 | cat <${file}${mid}.r 204 | 205 | if ($ist){ 206 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 207 | } 208 | library(ggplot2) 209 | library(grid) 210 | 211 | data <- read.table(file="$file", sep="\t", header=T, row.names=1, quote="") 212 | 213 | #if ("$width" != "" && "$height" != "" && "$res" != ""){ 214 | # png(filename="${file}${mid}.png", width=$width, height=$height, 215 | # res=$res) 216 | #}else{ 217 | # png(filename="${file}${mid}.png") 218 | #} 219 | 220 | 221 | $facet_o 222 | 223 | p <- ggplot(data, aes(x=${xval},y=${yval})) \ 224 | + geom_point(aes(color=${color})) \ 225 | + scale_colour_gradient(low="green", high="red", 226 | name="$col_legend" ${log}) \ 227 | + labs(x="$xlab", y="$ylab") + labs(title="$title") 228 | 229 | #if ("$facet" != ""){ 230 | # facet=$facet 231 | p <- p ${facet} 232 | #} 233 | 234 | if ("$smooth" == "geom_smooth"){ 235 | p <- p + geom_smooth() 236 | } else 237 | if ("$smooth" == 'lm'){ 238 | p <- p + geom_smooth(method=lm) 239 | } 240 | 241 | #if ("$other" != ''){ 242 | #other=$other 243 | p <- p $other 244 | #} 245 | 246 | 247 | p <- p + theme_bw() + theme(legend.title=element_blank(), 248 | panel.grid.major = element_blank(), panel.grid.minor = element_blank()) 249 | 250 | top='top' 251 | bottom='bottom' 252 | left='left' 253 | right='right' 254 | none='none' 255 | legend_pos_par <- ${legend_pos} 256 | 257 | p <- p + theme(legend.position=legend_pos_par) 258 | 259 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=${width}, 260 | height=${height}, units=c("cm")) 261 | 262 | #p 263 | #dev.off() 264 | #+ geom_point(alpha=1/10) 265 | END 266 | 267 | if [ "$execute" == "TRUE" ]; then 268 | Rscript ${file}${mid}.r 269 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 270 | fi 271 | 272 | if [ ! -z "$log" ]; then 273 | log=', trans=\"'$log'\"' 274 | fi 275 | 276 | #convert -density 200 -flatten ${file}${mid}.eps ${first}${mid}.png 277 | -------------------------------------------------------------------------------- /sp_scatterplotContour.bak.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <&2 "Please give filename, xval and yval." 113 | usage 114 | exit 1 115 | fi 116 | 117 | 118 | if [ ! -z $group ]; then 119 | group='|'$group 120 | legend="TRUE" 121 | fi 122 | 123 | cat <${file}${midname}.r 124 | 125 | if ($ist){ 126 | install.packages("car", repo="http://cran.us.r-project.org") 127 | } 128 | library(car) 129 | data <- read.table(file="$file", sep="\t", header=T, row.names=1) 130 | #postscript(file="${file}${midname}.eps", onefile=FALSE, 131 | #horizontal=FALSE,paper="special" , width=10, height = 12,pointsize=10) 132 | 133 | #if ($width!="" && $width >0 && $height > 0 && $res > 0){ 134 | # png(filename="${file}${midname}.png", width=$width, height=$height, 135 | # res=$res) 136 | #}else{ 137 | png(filename="${file}${midname}.png") 138 | #} 139 | 140 | scatterplot($yval~${xval}${group}, data=data, xlab="$xlab", ylab="$ylab", 141 | main="$title", label=row.names(data), id.method="identify", 142 | boxplots="xy", legend.plot=${legend}, ellipse=TRUE) 143 | dev.off() 144 | END 145 | 146 | if [ "$execute" == "TRUE" ]; then 147 | Rscript ${file}${midname}.r 148 | fi 149 | 150 | #convert -density 200 -flatten ${file}${midname}.eps ${first}${midname}.png 151 | -------------------------------------------------------------------------------- /sp_scatterplotContour.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <&2 "Please give filename, xval and yval." 182 | usage 183 | exit 1 184 | fi 185 | 186 | 187 | #if [ "$log" == "TRUE" ]; then 188 | # log=", trans=\"log\"" 189 | #fi 190 | 191 | mid=".scatterContour" 192 | 193 | if test "${user_mid}" != ""; then 194 | mid=${mid}".${user_mid}" 195 | fi 196 | 197 | cat <${file}${mid}.r 198 | 199 | if ($ist){ 200 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 201 | } 202 | 203 | library(ggplot2) 204 | 205 | data <- read.table(file="$file", sep="\t", header=T, row.names=1) 206 | 207 | data\$${xval} <- data\$${xval} + ${x_add} 208 | data\$${yval} <- data\$${yval} + ${y_add} 209 | 210 | p <- ggplot(data,aes(x=${xval},y=${yval}))+ 211 | labs(x="$xlab", y="$ylab") + ggtitle("$title") 212 | 213 | if ("${fill_contour}" == "..density..") { 214 | p <- p + stat_density2d(aes(fill = ${fill_contour}), geom="tile", 215 | contour=FALSE) 216 | } else if ("${fill_contour}" == "..level.."){ 217 | p <- p + stat_density2d(aes(fill = ${fill_contour}), 218 | geom="polygon") 219 | } 220 | 221 | p <- p + scale_fill_gradient(low="${low}", high="${high}") 222 | 223 | if (${points}){ 224 | p <- p + geom_point(size=0.3, alpha=0.5, color="${point_color}") 225 | } 226 | 227 | if (${scale} || ${x_add} != 0 || ${y_add} != 0) { 228 | p <- p + ${log} 229 | } 230 | 231 | p <- p + theme_bw() + theme(legend.title=element_blank(), 232 | panel.grid.major = element_blank(), panel.grid.minor = element_blank()) 233 | 234 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, 235 | height=$vhig, units=c("cm")) 236 | END 237 | 238 | if [ "$execute" == "TRUE" ]; then 239 | Rscript ${file}${mid}.r 240 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 241 | fi 242 | 243 | #convert -density 200 -flatten ${file}${mid}.eps ${first}${mid}.png 244 | -------------------------------------------------------------------------------- /sp_scatterplotDoubleVariable.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <&2 "Please give filename, xval and yval." 233 | usage 234 | exit 1 235 | fi 236 | 237 | 238 | cat <${file}${mid}.r 239 | 240 | if ($ist){ 241 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 242 | } 243 | library(plyr) 244 | library(stringr) 245 | library(ggplot2) 246 | library(grid) 247 | 248 | data <- read.table(file="$file", sep="\t", quote="", comment="", header=T) 249 | 250 | # First order by Term, then order by Sample 251 | data <- data[order(data\$${yval}, data\$${xval}), ] 252 | 253 | # Get the count of each unique Term 254 | data_freq <- as.data.frame(table(data\$${yval})) 255 | 256 | colnames(data_freq) <- c("${yval}", "ID") 257 | 258 | data2 <- merge(data, data_freq, by="${yval}") 259 | 260 | # Collapse sample for each Term 261 | data_samp <- ddply(data2, "${yval}", summarize, 262 | sam_ct_ct_ct=paste(${xval}, collapse="_")) 263 | 264 | data2 <- merge(data2, data_samp, by="${yval}") 265 | 266 | #print(data2) 267 | 268 | data3 <- data2[order(data2\$ID, data2\$sam_ct_ct_ct, data2\$${xval}, data2\$${color}), ] 269 | 270 | #print(data3) 271 | 272 | term_order <- unique(data3\$${yval}) 273 | 274 | data\$${yval} <- factor(data\$${yval}, levels=term_order, ordered=T) 275 | 276 | xval_ho <- c(${xval_ho}) 277 | 278 | if (length(xval_ho) > 1) { 279 | data\$${xval} <- factor(data\$${xval}, levels=xval_ho, ordered=T) 280 | } else { 281 | data\$${xval} <- factor(data\$${xval}) 282 | } 283 | 284 | #print(data) 285 | rm(data_freq, data2, data3) 286 | 287 | if ("${log}" != "nolog"){ 288 | data\$${log} <- log10(data\$${log}) * (-1) 289 | } 290 | 291 | $facet_o 292 | 293 | color_v <- c(${color_v}) 294 | 295 | p <- ggplot(data, aes(x=${xval},y=${yval})) \ 296 | + labs(x="$xlab", y="$ylab") + labs(title="$title") 297 | 298 | if (("${size}" != "") && ("${color}" != "")) { 299 | p <- p + geom_point(aes(size=${size}, color=${color})) + \ 300 | scale_colour_gradient(low=color_v[1], high=color_v[2], name="${color}") 301 | } else if ("${size}" != "") { 302 | p <- p + geom_point(aes(size=${size})) 303 | } else if ("${color}" != "") { 304 | p <- p + geom_point(aes(color=${color})) + \ 305 | scale_colour_gradient(low="color_v[1]", high=color_v[2], name="${color}") 306 | } 307 | 308 | 309 | p <- p ${facet} 310 | 311 | p <- p + scale_y_discrete(labels=function(x) str_wrap(x, width=60)) 312 | 313 | p <- p $other 314 | 315 | 316 | p <- p + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) 317 | 318 | if (${xtics_angle} != 0){ 319 | p <- p + 320 | theme(axis.text.x=element_text(angle=${xtics_angle},hjust=${hjust}, 321 | vjust=${vjust})) 322 | } 323 | 324 | top='top' 325 | bottom='bottom' 326 | left='left' 327 | right='right' 328 | none='none' 329 | legend_pos_par <- ${legend_pos} 330 | 331 | p <- p + theme(legend.position=legend_pos_par) 332 | 333 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=${width}, 334 | height=${height}, units=c("cm")) 335 | 336 | END 337 | 338 | if [ "$execute" == "TRUE" ]; then 339 | Rscript ${file}${mid}.r 340 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 341 | fi 342 | 343 | if [ ! -z "$log" ]; then 344 | log=', trans=\"'$log'\"' 345 | fi 346 | 347 | #convert -density 200 -flatten ${file}${mid}.eps ${first}${mid}.png 348 | -------------------------------------------------------------------------------- /sp_scatterplotLotsData.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <&2 "Please give filename, xval and yval." 128 | usage 129 | exit 1 130 | fi 131 | 132 | 133 | #if [ "$log" == "TRUE" ]; then 134 | # log=", trans=\"log\"" 135 | #fi 136 | 137 | cat <${file}${mid}.r 138 | 139 | if ($ist){ 140 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 141 | install.packages("hexbin", repo="http://cran.us.r-project.org") 142 | } 143 | library(ggplot2) 144 | data <- read.table(file="$file", sep="\t", header=T, quote="", row.names=${row_names}) 145 | 146 | p <- ggplot(data,aes(x=${xval},y=${yval}))+stat_binhex(bins=${group})+ labs(x="$xlab", 147 | y="$ylab") + ggtitle("$title") 148 | 149 | if ("$log" == "log" || "$log" == "log2"){ 150 | #log <- "trans=\"${log}\", " 151 | p <- p + scale_fill_gradient2(name="Log count", trans="${log}", 152 | low="green",high="red",mid="yellow") 153 | } 154 | 155 | if ("$smooth" == "geom_smooth"){ 156 | p <- p + geom_smooth(method=loose) 157 | } else 158 | if ("$smooth" == 'lm'){ 159 | p <- p + geom_smooth(method=lm) 160 | } 161 | 162 | 163 | p <- p + theme_bw() + theme(legend.title=element_blank(), 164 | panel.grid.major = element_blank(), panel.grid.minor = element_blank()) 165 | 166 | 167 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, 168 | height=$vhig, units=c("cm")) 169 | 170 | #png(filename="${file}${mid}.png", width=1000, height=1000) 171 | #p 172 | #dev.off() 173 | END 174 | 175 | if [ "$execute" == "TRUE" ]; then 176 | Rscript ${file}${mid}.r 177 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 178 | fi 179 | 180 | #convert -density 200 -flatten ${file}${mid}.eps ${first}${mid}.png 181 | -------------------------------------------------------------------------------- /sp_scatterplotMatrix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <&2 "Please give filename, compared columnumn number." 82 | usage 83 | exit 1 84 | fi 85 | 86 | 87 | cat <${file}${mid}.r 88 | 89 | if ($ist){ 90 | install.packages("gclus", repo="http://cran.us.r-project.org") 91 | } 92 | library(gclus) 93 | data <- read.table(file="$file", sep="\t", header=T, row.names=1, 94 | check.names=${checkN}, quote="") 95 | data <- data[c($comp)] #get appointed data 96 | data.r <- abs(cor(data)) #get correlation, default pearson 97 | #get colors, the deepest, the large correlation coefficient 98 | data.col <- dmat.color(data.r) 99 | #reorder variables so those with the highest correlation 100 | # are closest to the diagonal 101 | data.o <- order.single(data.r) 102 | 103 | #postscript(file="${file}${mid}.eps", onefile=FALSE, horizontal=FALSE) 104 | png(filename="${file}${mid}.png", width=1000, height=1000,res=150) 105 | cpairs(data, data.o, panel.colors=data.col, gap=.1, 106 | main="$title") 107 | dev.off() 108 | END 109 | 110 | if [ "$execute" == "TRUE" ]; then 111 | Rscript ${file}${mid}.r 112 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 113 | #convert -density 200 -flatten ${file}${mid}.eps \ 114 | # ${file}${mid}.png 115 | fi 116 | 117 | -------------------------------------------------------------------------------- /sp_upsetView.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | set -e 5 | set -u 6 | 7 | usage() 8 | { 9 | cat <&2 10 | ${txtcyn} 11 | Usage: 12 | 13 | $0 options${txtrst} 14 | 15 | ${bldblu}Function${txtrst}: 16 | 17 | This script is used to do another type of VennDiagram using R package . 18 | 19 | Input file is a matrix: 20 | 21 | (First row would be treated as header line. First column is just a normal column (but needed). 0 represents the sample does not contain the genes in row. 1 represents the containing relationship) 22 | 23 | ID Samp1 Samp2 Samp3 Samp4 Samp5 24 | G1 1 0 1 0 1 25 | G2 0 0 1 1 1 26 | G3 1 1 1 0 1 27 | G4 1 1 1 0 0 28 | G5 0 1 0 1 1 29 | G6 1 0 1 0 0 30 | 31 | The output contains two barplots, horizontal bar represents the number of genes in each sample, which is the sum of all 1 in sample column. Vertical bar represents the number of sample specific and common genes as indicated by linking vertical lines and points (just as the overlapping regions of venndiagram). 32 | 33 | 34 | 35 | ${txtbld}OPTIONS${txtrst}: 36 | -f Data matrix file ${bldred}[NECESSARY]${txtrst} 37 | -u Plot width ${bldred}[Default 14]${txtrst} 38 | -v Plot height ${bldred}[Default 6]${txtrst} 39 | -p Point size ${bldred}[Default 8]${txtrst} 40 | -i Install required packages. 41 | ${bldred}[Default FALSE]${txtrst} 42 | EOF 43 | } 44 | 45 | file= 46 | header='TRUE' 47 | install='FALSE' 48 | width=14 49 | height=6 50 | pointsize=8 51 | 52 | while getopts "hf:i:u:v:p:" OPTION 53 | do 54 | case $OPTION in 55 | h) 56 | usage 57 | exit 1 58 | ;; 59 | f) 60 | file=$OPTARG 61 | ;; 62 | u) 63 | width=$OPTARG 64 | ;; 65 | v) 66 | height=$OPTARG 67 | ;; 68 | p) 69 | pointsize=$OPTARG 70 | ;; 71 | i) 72 | install=$OPTARG 73 | ;; 74 | ?) 75 | usage 76 | exit 1 77 | ;; 78 | esac 79 | done 80 | 81 | if [ -z $file ]; then 82 | usage 83 | exit 1 84 | fi 85 | 86 | mid=".upsetV" 87 | 88 | cat <${file}${mid}.r 89 | 90 | if ($install){ 91 | install.packages("UpSetR", repo="http://cran.us.r-project.org") 92 | } 93 | 94 | library(UpSetR) 95 | 96 | matrix = read.table("${file}", header=T, row.names=NULL, sep="\t") 97 | 98 | nsets = dim(matrix)[2]-1 99 | 100 | pdf(file="${file}${mid}.pdf", onefile=FALSE, paper="special", width=${width}, height=${height}, bg="white", pointsize=${pointsize}) 101 | 102 | upset(matrix, nsets=nsets, sets.bar.color = "#56B4E9", order.by = "freq", empty.intersections = "on") 103 | 104 | dev.off() 105 | 106 | END 107 | 108 | Rscript ${file}${mid}.r 109 | -------------------------------------------------------------------------------- /sp_volcano.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | usage() 6 | { 7 | cat <. 94 | [${bldred}Default "0.05,1". Here pvalue corresponds to the column given to <-y>.${txtrst}] 95 | -l Label the names of significant points in graph. 96 | ${bldred}[Default FALSE, accept a string represents the 97 | colname of labels. Non-hypen (-) strings in this column will be labeled.]${txtrst} 98 | -P Get -log10(pvalue) for column given to <-y> 99 | [${bldred}Default FALSE, accept TRUE.${txtrst}] 100 | -M Maximum transferred -log10(pvalue). Normally this should be 3 or 4. 101 | [${bldred}Default Inf, accept a number.${txtrst}] 102 | -t Title of picture[${txtred}Default empty title${txtrst}] 103 | [Scatter plot of horizontal and vertical variable] 104 | -X Xlab label[${txtred}Default "Log2 fold change"${txtrst}] 105 | -Y Ylab label[${txtred}Default "Negative log10 transformed qvalue"${txtrst}] 106 | -a Transparent alpha value. 107 | [${txtred}Default 0.4, Accept a float from 108 | [0(transparent),1(opaque)]${txtrst}] 109 | -p Point size.[${txtred}Default 1${txtrst}] 110 | -L Legend position[${txtred}Default right. Accept 111 | top,bottom,left,none, or c(0.08,0.8).${txtrst}] 112 | -u The width of output picture.[${txtred}Default 12${txtrst}] 113 | -v The height of output picture.[${txtred}Default 12${txtrst}] 114 | -E The type of output figures.[${txtred}Default pdf, accept 115 | eps/ps, tex (pictex), png, jpeg, tiff, bmp, svg and wmf)${txtrst}] 116 | -r The resolution of output picture.[${txtred}Default NA${txtrst}] 117 | -e Execute or not[${bldred}Default TRUE${txtrst}] 118 | -i Install the required packages[${bldred}Default FALSE${txtrst}] 119 | EOF 120 | 121 | 122 | 123 | 124 | } 125 | 126 | file='' 127 | x_var='' 128 | y_var='' 129 | status_col='' 130 | status_col_level='' 131 | label='CTctctCT' 132 | val_label='' 133 | title='' 134 | x_label='Log2 fold change' 135 | y_label='Negative log10 transformed qvalue' 136 | alpha=0.4 137 | point_size=1 138 | execute='TRUE' 139 | ist='FALSE' 140 | uwid=12 141 | vhig=12 142 | #res='NA' 143 | res=300 144 | symmetry='TRUE' 145 | legend_pos='right' 146 | status_col_level='' 147 | ext='pdf' 148 | colormodel='srgb' 149 | transform_log='FALSE' 150 | max_p='Inf' 151 | filter_threshold='0.05,1' 152 | 153 | while getopts "hf:x:m:y:s:-S:l:L:V:t:X:Y:F:a:p:P:M:u:v:E:r:e:i:" OPTION 154 | do 155 | case $OPTION in 156 | h) 157 | echo "Help mesage" 158 | usage 159 | exit 1 160 | ;; 161 | f) 162 | file=$OPTARG 163 | ;; 164 | x) 165 | x_var=$OPTARG 166 | ;; 167 | m) 168 | symmetry=$OPTARG 169 | ;; 170 | y) 171 | y_var=$OPTARG 172 | ;; 173 | s) 174 | status_col=$OPTARG 175 | ;; 176 | S) 177 | status_col_level=$OPTARG 178 | ;; 179 | F) 180 | filter_threshold=$OPTARG 181 | ;; 182 | l) 183 | label=$OPTARG 184 | ;; 185 | L) 186 | legend_pos=$OPTARG 187 | ;; 188 | V) 189 | val_label=$OPTARG 190 | ;; 191 | t) 192 | title=$OPTARG 193 | ;; 194 | P) 195 | transform_log=$OPTARG 196 | ;; 197 | M) 198 | max_p=$OPTARG 199 | ;; 200 | X) 201 | x_label=$OPTARG 202 | ;; 203 | Y) 204 | y_label=$OPTARG 205 | ;; 206 | a) 207 | alpha=$OPTARG 208 | ;; 209 | p) 210 | point_size=$OPTARG 211 | ;; 212 | u) 213 | uwid=$OPTARG 214 | ;; 215 | v) 216 | vhig=$OPTARG 217 | ;; 218 | r) 219 | res=$OPTARG 220 | ;; 221 | E) 222 | ext=$OPTARG 223 | ;; 224 | e) 225 | execute=$OPTARG 226 | ;; 227 | i) 228 | ist=$OPTARG 229 | ;; 230 | ?) 231 | usage 232 | echo "Unknown parameters" 233 | exit 1 234 | ;; 235 | esac 236 | done 237 | 238 | if [ -z $file ] ; then 239 | echo 1>&2 "Please give filename." 240 | usage 241 | exit 1 242 | fi 243 | 244 | self_compute_status='FALSE' 245 | if [ -z $status_col ] && test "${filter_threshold}" != ""; then 246 | status_col='DE_genes' 247 | self_compute_status='TRUE' 248 | fi 249 | 250 | mid='.volcano' 251 | 252 | cat <${file}${mid}.r 253 | 254 | if ($ist){ 255 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 256 | } 257 | 258 | library(ggplot2) 259 | data <- read.table(file="$file", header=T, sep="\t", quote="") 260 | 261 | if (! ${self_compute_status}){ 262 | sig_level <- c(${status_col_level}) 263 | } else{ 264 | filter_threshold <- c(${filter_threshold}) 265 | pvalue = filter_threshold[1] 266 | fc = filter_threshold[2] 267 | sig_level <- c("UP", "DW", "NoDiff") 268 | data\$${status_col} <- ifelse(data\$${y_var}<=pvalue, ifelse(data\$${x_var}>=fc, "UP", ifelse(data\$${x_var}<=fc*(-1), "DW", "NoDiff")) , "NoDiff") 269 | } 270 | 271 | if (length(sig_level)>1){ 272 | data\$${status_col} <- factor(data\$${status_col},levels=sig_level, 273 | ordered=T) 274 | } 275 | 276 | data\$${y_var} <- (-1)* log10(data\$${y_var}) 277 | data[data\$${y_var}>${max_p}, "${y_var}"] <- ${max_p} 278 | 279 | p <- ggplot(data=data, aes(x=${x_var},y=${y_var},colour=${status_col})) 280 | p <- p + geom_point(alpha=${alpha}, size=${point_size}) 281 | p <- p + theme(legend.position="none") + theme_bw() + 282 | theme(legend.title=element_blank(), 283 | panel.grid.major = element_blank(), panel.grid.minor = element_blank()) 284 | 285 | if("${x_label}" != "NULL") { 286 | p <- p + xlab("${x_label}") 287 | } 288 | 289 | if("${y_label}" != "NULL") { 290 | p <- p + ylab("${y_label}") 291 | } 292 | 293 | if (${symmetry}) { 294 | boundary <- ceiling(max(abs(data\$${x_var}))) 295 | p <- p + xlim(-1 * boundary, boundary) 296 | } 297 | if ("$label" != "CTctctCT"){ 298 | data.l <- data[data\$${label}!="-" & data\$${label}!="",] 299 | p <- p + geom_text(data=data.l, aes(x=${x_var}, y=${y_var}, 300 | label=$label), colour="black") 301 | } 302 | 303 | 304 | top='top' 305 | botttom='bottom' 306 | left='left' 307 | right='right' 308 | none='none' 309 | legend_pos_par <- ${legend_pos} 310 | 311 | #if ("${legend_pos}" != "right"){ 312 | p <- p + theme(legend.position=legend_pos_par) 313 | #} 314 | 315 | 316 | if ("${ext}" == "pdf") { 317 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, 318 | height=$vhig, units=c("cm"),colormodel="${colormodel}") 319 | } else { 320 | ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, 321 | height=$vhig, units=c("cm")) 322 | } 323 | 324 | #png(filename="${file}${mid}.png", width=$uwid, height=$vhig, 325 | #res=$res) 326 | #p 327 | #dev.off() 328 | END 329 | 330 | if [ "$execute" == "TRUE" ]; then 331 | Rscript ${file}${mid}.r 332 | if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi 333 | fi 334 | 335 | #if [ "$quiet" == "TRUE" ]; then 336 | # /bin/rm -f ${file}${mid}.r 337 | #fi 338 | #convert -density 200 -flatten ${file}${mid}.eps ${first}${mid}.png 339 | -------------------------------------------------------------------------------- /swap: -------------------------------------------------------------------------------- 1 | -b The formula for facets.[${bldred}Default no facets, 2 | +facet_grid(level ~ .) means divide by levels of 'level' vertcally. 3 | +facet_grid(. ~ level) means divide by levels of 'level' horizontally. 4 | +facet_grid(lev1 ~ lev2) means divide by lev1 vertically and lev2 5 | horizontally. 6 | +facet_wrap(~level, ncol=2) means wrap horizontally with 2 7 | columns. 8 | Example: +facet_wrap(~Size,ncol=6,scale='free') 9 | ${txtrst}] 10 | -d If facet is given, you may want to specifize the order of 11 | variable in your facet, default alphabetically. 12 | [${txtred}Accept sth like 13 | (one level one sentence, separate by';') 14 | data\$size <- factor(data\$size, levels=c("l1", 15 | "l2",...,"l10"), ordered=T) ${txtrst}] 16 | -------------------------------------------------------------------------------- /swap2: -------------------------------------------------------------------------------- 1 | $facet_o 2 | 3 | p <- ggplot(data, aes(x=${xval},y=${yval})) \ 4 | + geom_point(aes(color=${color})) \ 5 | + scale_colour_gradient(low="green", high="red", 6 | name="$col_legend" ${log}) \ 7 | + labs(x="$xlab", y="$ylab") + labs(title="$title") 8 | 9 | #if ("$facet" != ""){ 10 | # facet=$facet 11 | p <- p ${facet} 12 | -------------------------------------------------------------------------------- /tips: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tips -------------------------------------------------------------------------------- /trash/test: -------------------------------------------------------------------------------- 1 | Term Pop_Hits Bonferroni Sample 2 | hsa04080:Neuroactive ligand-receptor interaction 256 5.21E-06 b 3 | hsa04060:Cytokine-cytokine receptor interaction 262 8.62E-04 b 4 | hsa00830:Retinol metabolism 54 0.124538325 b 5 | hsa04062:Chemokine signaling pathway 187 0.913682422 b 6 | hsa00120:Primary bile acid biosynthesis 16 0.995946178 b 7 | hsa04614:Renin-angiotensin system 17 0.998465518 b 8 | hsa04640:Hematopoietic cell lineage 86 0.99955116 b 9 | hsa04650:Natural killer cell mediated cytotoxicity 133 0.999599558 b 10 | hsa04740:Olfactory transduction 379 6.48E-13 a 11 | hsa04080:Neuroactive ligand-receptor interaction 256 5.21E-06 a 12 | hsa04060:Cytokine-cytokine receptor interaction 262 8.62E-04 a 13 | hsa00830:Retinol metabolism 54 0.124538325 a 14 | hsa04062:Chemokine signaling pathway 187 0.913682422 a 15 | hsa00120:Primary bile acid biosynthesis 16 0.995946178 a 16 | hsa04614:Renin-angiotensin system 17 0.998465518 a 17 | hsa04640:Hematopoietic cell lineage 86 0.99955116 a 18 | hsa04650:Natural killer cell mediated cytotoxicity 133 0.999599558 a 19 | -------------------------------------------------------------------------------- /trash/test.scatterplot.color.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/trash/test.scatterplot.color.pdf -------------------------------------------------------------------------------- /trash/test.scatterplot.dv.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/trash/test.scatterplot.dv.pdf -------------------------------------------------------------------------------- /tutorial/diamond.extract.matrix.boxplot.noOutlier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/diamond.extract.matrix.boxplot.noOutlier.png -------------------------------------------------------------------------------- /tutorial/diamond.extract.matrix.boxplot.noOutlier.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/diamond.extract.matrix.boxplot.noOutlier.r -------------------------------------------------------------------------------- /tutorial/diamond.extract.matrix.boxplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/diamond.extract.matrix.boxplot.png -------------------------------------------------------------------------------- /tutorial/diamond.extract.matrix.boxplot.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/diamond.extract.matrix.boxplot.r -------------------------------------------------------------------------------- /tutorial/diamond.extract.matrix.boxplot.violin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/diamond.extract.matrix.boxplot.violin.png -------------------------------------------------------------------------------- /tutorial/diamond.extract.matrix.boxplot.violin.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/diamond.extract.matrix.boxplot.violin.r -------------------------------------------------------------------------------- /tutorial/diamond.extract.matrix.melt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/diamond.extract.matrix.melt -------------------------------------------------------------------------------- /tutorial/diamond.extract.matrix.melt.boxplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/diamond.extract.matrix.melt.boxplot.png -------------------------------------------------------------------------------- /tutorial/diamond.extract.matrix.melt.boxplot.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/diamond.extract.matrix.melt.boxplot.r -------------------------------------------------------------------------------- /tutorial/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/test -------------------------------------------------------------------------------- /tutorial/test.boxplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/test.boxplot.png -------------------------------------------------------------------------------- /tutorial/test.boxplot.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/test.boxplot.r -------------------------------------------------------------------------------- /tutorial/trash/diamond.matrix.boxplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/trash/diamond.matrix.boxplot.png -------------------------------------------------------------------------------- /tutorial/trash/diamond.matrix.boxplot.r: -------------------------------------------------------------------------------- 1 | 2 | if (FALSE){ 3 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 4 | install.packages("reshape2", repo="http://cran.us.r-project.org") 5 | install.packages("scales", repo="http://cran.us.r-project.org") 6 | } 7 | library(ggplot2) 8 | library(reshape2) 9 | library(scales) 10 | 11 | if(! FALSE){ 12 | ID_var <- c('price','cut','color','clarity') 13 | data <- read.table(file="diamond.matrix", sep="\t", header=TRUE, 14 | row.names=1) 15 | if ("variable" != "variable"){ 16 | if ((ID_var != "")[1]){ 17 | ID_var <- c(ID_var, "variable") 18 | } else { 19 | ID_var <- c("variable") 20 | } 21 | data_m <- melt(data, id.vars=ID_var) 22 | } else { 23 | if ((ID_var != "")[1]){ 24 | data_m <- melt(data, id.vars=ID_var) 25 | } else { 26 | data_m <- melt(data) 27 | } 28 | } 29 | } else { 30 | data_m <- read.table(file="diamond.matrix", sep="\t", 31 | header=TRUE) 32 | } 33 | 34 | if (0 != 0){ 35 | data_m$value <- data_m$value + 0 36 | } 37 | 38 | if ("" != ""){ 39 | data_m$variable <- cut(data_m$variable, ) 40 | } else if ("" != ""){ 41 | level_i <- c() 42 | data_m$variable <- factor(data_m$variable, levels=level_i) 43 | } 44 | if ("" != ""){ 45 | data_m$variable <- cut(data_m$variable,) 46 | }else if ("" != ""){ 47 | x_level <- c() 48 | data_m$variable <- factor(data_m$variable,levels=x_level) 49 | } 50 | 51 | p <- ggplot(data_m, aes(factor(variable), value)) + xlab("NULL") + 52 | ylab("NULL") 53 | 54 | 55 | if (FALSE){ 56 | p <- p + geom_violin(aes(fill=factor(variable)), 57 | stat = "ydensity", position = "dodge", trim = TRUE, 58 | scale = "area") + 59 | geom_boxplot(aes(fill=factor(variable)), alpha=.25, width=0.15, 60 | position = position_dodge(width = .9), outlier.colour='NA', 61 | scale="area") + 62 | stat_summary(aes(group=variable), fun.y=mean, 63 | geom="point", fill="black", shape=19, size=1, 64 | position = position_dodge(width = .9)) 65 | 66 | #+ geom_jitter(height = 0) 67 | } else if (FALSE){ 68 | p <- p + geom_violin(aes(fill=factor(variable)), 69 | stat = "ydensity", position = "dodge", trim = TRUE, 70 | scale = "area") 71 | } else { 72 | if (TRUE){ 73 | if (FALSE){ 74 | p <- p + geom_boxplot(aes(fill=factor(variable)), notch=TRUE, 75 | notchwidth=0.3, outlier.colour='NA') 76 | }else{ 77 | p <- p + geom_boxplot(aes(fill=factor(variable)), notch=TRUE, 78 | notchwidth=0.3) 79 | } 80 | }else { 81 | if (FALSE){ 82 | p <- p + geom_boxplot(aes(fill=factor(variable)), 83 | outlier.colour='NA') 84 | }else{ 85 | p <- p + geom_boxplot(aes(fill=factor(variable))) 86 | } 87 | } 88 | } 89 | 90 | 91 | if(FALSE){ 92 | p <- p + scale_y_log10() 93 | } 94 | 95 | if(FALSE){ 96 | #ylim_zoomin <- boxplot.stats(data_m$value)$stats[c(1,5)] 97 | stats <- boxplot.stats(data_m$value)$stats 98 | ylim_zoomin <- c(stats[1]/1.05, stats[5]*1.05) 99 | p <- p + coord_cartesian(ylim = ylim_zoomin) 100 | } 101 | 102 | if(FALSE){ 103 | p <- p + scale_fill_manual(values=c()) 104 | } 105 | 106 | #Configure the canvas 107 | p <- p + theme_bw() + theme(legend.title=element_blank(), 108 | panel.grid.major = element_blank(), 109 | panel.grid.minor = element_blank(), 110 | legend.key=element_blank(), 111 | axis.text.x=element_text(angle=-90)) 112 | 113 | #Set the position of legend 114 | top='top' 115 | botttom='bottom' 116 | left='left' 117 | right='right' 118 | none='none' 119 | legend_pos_par <- right 120 | 121 | p <- p + theme(legend.position=legend_pos_par) 122 | 123 | #add additional ggplot2 supported commands 124 | 125 | p <- p 126 | 127 | # output pictures 128 | 129 | ggsave(p, filename="diamond.matrix.boxplot.png", dpi=300, width=20, 130 | height=12, units=c("cm")) 131 | 132 | #png(filename="diamond.matrix.boxplot.png", width=20, height=12, 133 | #res=300) 134 | #p 135 | #dev.off() 136 | -------------------------------------------------------------------------------- /tutorial/trash/file.matrix.boxplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tong-Chen/s-plot/290dee11b9f89922a2ec4fa2fbb347671db1f319/tutorial/trash/file.matrix.boxplot.png -------------------------------------------------------------------------------- /tutorial/trash/file.matrix.boxplot.r: -------------------------------------------------------------------------------- 1 | 2 | if (FALSE){ 3 | install.packages("ggplot2", repo="http://cran.us.r-project.org") 4 | install.packages("reshape2", repo="http://cran.us.r-project.org") 5 | install.packages("scales", repo="http://cran.us.r-project.org") 6 | } 7 | library(ggplot2) 8 | library(reshape2) 9 | library(scales) 10 | 11 | if(! FALSE){ 12 | ID_var <- "expression" 13 | data <- read.table(file="file.matrix", sep="\t", header=TRUE, 14 | row.names=1) 15 | if ("variable" != "variable"){ 16 | if (ID_var != ""){ 17 | data_m <- melt(data, id.vars=c("variable", ID_var)) 18 | } else { 19 | data_m <- melt(data, id.vars=c("variable")) 20 | } 21 | } else { 22 | if (ID_var != ""){ 23 | data_m <- melt(data, id.vars=c(ID_var)) 24 | } else { 25 | data_m <- melt(data) 26 | } 27 | } 28 | } else { 29 | data_m <- read.table(file="file.matrix", sep="\t", 30 | header=TRUE) 31 | } 32 | 33 | if (0 != 0){ 34 | data_m$value <- data_m$value + 0 35 | } 36 | 37 | if ("" != ""){ 38 | data_m$variable <- cut(data_m$variable, ) 39 | } else if ("" != ""){ 40 | level_i <- c() 41 | data_m$variable <- factor(data_m$variable, levels=level_i) 42 | } 43 | if ("" != ""){ 44 | data_m$variable <- cut(data_m$variable,) 45 | }else if ("" != ""){ 46 | x_level <- c() 47 | data_m$variable <- factor(data_m$variable,levels=x_level) 48 | } 49 | 50 | p <- ggplot(data_m, aes(factor(variable), value)) + xlab("NULL") + 51 | ylab("NULL") 52 | 53 | 54 | if (FALSE){ 55 | p <- p + geom_violin(aes(fill=factor(variable)), 56 | stat = "ydensity", position = "dodge", trim = TRUE, 57 | scale = "area") + 58 | geom_boxplot(aes(fill=factor(variable)), alpha=.25, width=0.15, 59 | position = position_dodge(width = .9), outlier.colour='NA', 60 | scale="area") + 61 | stat_summary(aes(group=variable), fun.y=mean, 62 | geom="point", fill="black", shape=19, size=1, 63 | position = position_dodge(width = .9)) 64 | 65 | #+ geom_jitter(height = 0) 66 | } else if (FALSE){ 67 | p <- p + geom_violin(aes(fill=factor(variable)), 68 | stat = "ydensity", position = "dodge", trim = TRUE, 69 | scale = "area") 70 | } else { 71 | if (TRUE){ 72 | if (FALSE){ 73 | p <- p + geom_boxplot(aes(fill=factor(variable)), notch=TRUE, 74 | notchwidth=0.3, outlier.colour='NA') 75 | }else{ 76 | p <- p + geom_boxplot(aes(fill=factor(variable)), notch=TRUE, 77 | notchwidth=0.3) 78 | } 79 | }else { 80 | if (FALSE){ 81 | p <- p + geom_boxplot(aes(fill=factor(variable)), 82 | outlier.colour='NA') 83 | }else{ 84 | p <- p + geom_boxplot(aes(fill=factor(variable))) 85 | } 86 | } 87 | } 88 | 89 | 90 | if(FALSE){ 91 | p <- p + scale_y_log10() 92 | } 93 | 94 | if(FALSE){ 95 | #ylim_zoomin <- boxplot.stats(data_m$value)$stats[c(1,5)] 96 | stats <- boxplot.stats(data_m$value)$stats 97 | ylim_zoomin <- c(stats[1]/1.05, stats[5]*1.05) 98 | p <- p + coord_cartesian(ylim = ylim_zoomin) 99 | } 100 | 101 | if(FALSE){ 102 | p <- p + scale_fill_manual(values=c()) 103 | } 104 | 105 | #Configure the canvas 106 | p <- p + theme_bw() + theme(legend.title=element_blank(), 107 | panel.grid.major = element_blank(), 108 | panel.grid.minor = element_blank(), 109 | legend.key=element_blank(), 110 | axis.text.x=element_text(angle=0,hjust=1)) 111 | 112 | #Set the position of legend 113 | top='top' 114 | botttom='bottom' 115 | left='left' 116 | right='right' 117 | none='none' 118 | legend_pos_par <- right 119 | 120 | p <- p + theme(legend.position=legend_pos_par) 121 | 122 | #add additional ggplot2 supported commands 123 | 124 | p <- p 125 | 126 | # output pictures 127 | 128 | ggsave(p, filename="file.matrix.boxplot.png", dpi=300, width=20, 129 | height=12, units=c("cm")) 130 | 131 | #png(filename="file.matrix.boxplot.png", width=20, height=12, 132 | #res=300) 133 | #p 134 | #dev.off() 135 | --------------------------------------------------------------------------------