View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2010 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-core Project
18  //
19  // ReadDisplayStyle.java
20  // Since: 2010/09/30
21  //
22  //--------------------------------------
23  package org.utgenome.gwt.utgb.client.canvas;
24  
25  import org.utgenome.gwt.utgb.client.bio.Interval;
26  import org.utgenome.gwt.utgb.client.bio.OnGenome;
27  import org.utgenome.gwt.utgb.client.bio.SAMReadLight;
28  import org.utgenome.gwt.utgb.client.db.ValueDomain;
29  import org.utgenome.gwt.utgb.client.db.datatype.StringType;
30  import org.utgenome.gwt.utgb.client.track.TrackConfig;
31  
32  import com.google.gwt.widgetideas.graphics.client.Color;
33  
34  /**
35   * Configuration of ReadTrack display
36   * 
37   * @author leo
38   * 
39   */
40  public class ReadDisplayStyle {
41  
42  	String DEFAULT_READ_COLOR = "#CCCCCC";
43  	String FORWARD_READ_COLOR = "#d80067";
44  	String REVERSE_READ_COLOR = "#0067d8";
45  	String PADDING_COLOR = "#333333";
46  
47  	String WEIRED_READ_COLOR_F = "#FF9966";
48  	String WEIRED_READ_COLOR_R = "#6699FF";
49  
50  	String ORPHAN_READ_COLOR_F = "#FF6699";
51  	String ORPHAN_READ_COLOR_R = "#6699FF";
52  
53  	public boolean showLabels = true;
54  	public boolean drawShadow = true;
55  	public boolean showBaseQuality = false;
56  	public boolean overlapPairedReads = true;
57  	public boolean showStrand = true;
58  
59  	public int numReadsMax = 500;
60  	public float clippedRegionAlpha = 0.2f;
61  
62  	public int readHeight = 12;
63  	public int minReadHeight = 2;
64  	public String coverageStyle = "default";
65  	public String layout = "pileup";
66  
67  	public final static String CONFIG_LAYOUT = "layout";
68  	public final static String CONFIG_SHOW_LABELS = "showLabels";
69  	public final static String CONFIG_READ_HEIGHT = "read height";
70  	public final static String CONFIG_MIN_READ_HEIGHT = "min read height";
71  	public final static String CONFIG_NUM_READ_MAX = "num reads to display";
72  	public final static String CONFIG_SHOW_BASE_QUALITY = "show base quality";
73  	public final static String CONFIG_PE_OVERLAP = "overlap paired reads";
74  	public final static String CONFIG_COVERAGE_STYLE = "coverage.style";
75  	public final static String CONFIG_DRAW_SHADOW = "draw shadow";
76  	public final static String CONFIG_SHOW_STRAND = "show strand";
77  
78  	public void setup(TrackConfig config) {
79  		ValueDomain layoutTypes = ValueDomain.createNewValueDomain(new String[] { "pileup", "coverage" });
80  		config.addConfig("Layout", new StringType(CONFIG_LAYOUT, layoutTypes), "pileup");
81  		config.addConfigBoolean("Show Labels", CONFIG_SHOW_LABELS, showLabels);
82  		config.addConfigInteger("Read Height", CONFIG_READ_HEIGHT, readHeight);
83  		config.addConfigInteger("Read Height (min)", CONFIG_MIN_READ_HEIGHT, minReadHeight);
84  		config.addConfigInteger("# of Reads to Cache", CONFIG_NUM_READ_MAX, numReadsMax);
85  		config.addConfigBoolean("Overlap Paired-End Reads", CONFIG_PE_OVERLAP, overlapPairedReads);
86  		config.addConfigBoolean("Show Base Quality", CONFIG_SHOW_BASE_QUALITY, showBaseQuality);
87  		config.addConfigBoolean("Draw Read Shadow", CONFIG_DRAW_SHADOW, drawShadow);
88  		config.addConfigBoolean("Show Strand", CONFIG_SHOW_STRAND, showStrand);
89  
90  		config.addConfig("Coverage Display Style",
91  				new StringType(CONFIG_COVERAGE_STYLE, ValueDomain.createNewValueDomain(new String[] { "default", "smooth" })), coverageStyle);
92  	}
93  
94  	public void loadConfig(TrackConfig config) {
95  
96  		layout = config.getString(CONFIG_LAYOUT, layout);
97  		numReadsMax = config.getInt(CONFIG_NUM_READ_MAX, 500);
98  		showLabels = config.getBoolean(CONFIG_SHOW_LABELS, showLabels);
99  		readHeight = config.getInt(CONFIG_READ_HEIGHT, readHeight);
100 		minReadHeight = config.getInt(CONFIG_MIN_READ_HEIGHT, minReadHeight);
101 		coverageStyle = config.getString(CONFIG_COVERAGE_STYLE, coverageStyle);
102 		overlapPairedReads = config.getBoolean(CONFIG_PE_OVERLAP, overlapPairedReads);
103 		showBaseQuality = config.getBoolean(CONFIG_SHOW_BASE_QUALITY, showBaseQuality);
104 		drawShadow = config.getBoolean(CONFIG_DRAW_SHADOW, drawShadow);
105 		showStrand = config.getBoolean(CONFIG_SHOW_STRAND, showStrand);
106 
107 	}
108 
109 	public Color getSAMReadColor(SAMReadLight r) {
110 		if (r.isPairedRead()) {
111 			if (r.isMappedInProperPair())
112 				return getReadColor(r);
113 			else
114 				return ColorUtil.toColor(r.isSense() ? WEIRED_READ_COLOR_F : WEIRED_READ_COLOR_R);
115 		}
116 		else {
117 			return ColorUtil.toColor(r.isSense() ? ORPHAN_READ_COLOR_F : ORPHAN_READ_COLOR_R);
118 		}
119 	}
120 
121 	public Color getClippedReadColor(OnGenome g) {
122 		return ColorUtil.toColor(getReadColorHex(g), clippedRegionAlpha);
123 	}
124 
125 	public Color getPaddingColor() {
126 		return ColorUtil.toColor(PADDING_COLOR);
127 	}
128 
129 	private String getReadColorHex(OnGenome g) {
130 		if (showStrand) {
131 			if (g instanceof Interval) {
132 				Interval r = (Interval) g;
133 				if (r.getColor() != null)
134 					return r.getColor();
135 
136 				return r.isSense() ? FORWARD_READ_COLOR : REVERSE_READ_COLOR;
137 			}
138 		}
139 		return DEFAULT_READ_COLOR;
140 	}
141 
142 	public Color getReadColor(OnGenome g) {
143 		return ColorUtil.toColor(getReadColorHex(g));
144 	}
145 
146 	public Color getReadColor(OnGenome g, float alpha) {
147 		return ColorUtil.toColor(getReadColorHex(g), alpha);
148 	}
149 
150 	public static ReadDisplayStyle defaultStyle() {
151 		return new ReadDisplayStyle();
152 	}
153 
154 	public static ReadDisplayStyle highlightImproperMate() {
155 		ReadDisplayStyle s = new ReadDisplayStyle();
156 		s.showStrand = true;
157 		return s;
158 	}
159 
160 }