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  // GeneticVariation.java
20  // Since: 2010/10/13
21  //
22  //--------------------------------------
23  package org.utgenome.util.sv;
24  
25  import org.utgenome.gwt.utgb.client.bio.IUPAC;
26  import org.xerial.lens.SilkLens;
27  import org.xerial.util.log.Logger;
28  
29  /**
30   * genetic variation location [start, end), chr and allele (genotype) information
31   * 
32   * @author leo
33   * 
34   */
35  public class GeneticVariation {
36  
37  	private static Logger _logger = Logger.getLogger(GeneticVariation.class);
38  
39  	/**
40  	 * 
41  	 */
42  	private static final long serialVersionUID = 1L;
43  
44  	public static enum VariationType {
45  		NotAvailable, Mutation, Insertion, Deletion;
46  	};
47  
48  	// locus information 
49  	public VariationType variationType;
50  	public String chr;
51  	public int start = -1; // 1-origin (inclusive, -1 means undefined value)
52  	public String refBase;
53  
54  	// parameters to be determined automatically 
55  	private String genotype;
56  	private IUPAC altBase;
57  
58  	public int indelLength = 0;
59  
60  	public GeneticVariation() {
61  	}
62  
63  	/**
64  	 * @param type
65  	 * @param chr
66  	 * @param start
67  	 *            1-origin (inclusive)
68  	 * @param end
69  	 *            1-origin (exclusive)
70  	 * @param genotype
71  	 *            A, C, AC, ACGT (genotype), *, +A (insertion to reference), -aatT (deletion from reference), etc.
72  	 */
73  	public GeneticVariation(String chr, int start, String genotype) {
74  		this.chr = chr;
75  		this.start = start;
76  		setGenotype(genotype);
77  	}
78  
79  	public GeneticVariation(GeneticVariation other) {
80  		this.start = other.start;
81  		this.variationType = other.variationType;
82  		this.chr = other.chr;
83  		this.genotype = other.genotype;
84  		this.altBase = other.altBase;
85  		this.refBase = other.refBase;
86  		this.indelLength = other.indelLength;
87  	}
88  
89  	VariationType detectVariationType(String allele) {
90  		if (allele == null)
91  			return VariationType.NotAvailable;
92  
93  		String[] alleleList = allele.split("/");
94  
95  		for (String each : alleleList) {
96  			if (each.startsWith("+")) {
97  				indelLength = each.length() - 1;
98  				return VariationType.Insertion;
99  			}
100 			else if (each.startsWith("-")) {
101 				indelLength = each.length() - 1;
102 				return VariationType.Deletion;
103 			}
104 			else {
105 				try {
106 					altBase = IUPAC.find(allele);
107 				}
108 				catch (IllegalArgumentException e) {
109 					// unknown IUPAC code
110 					_logger.warn("unkonwn IUPAC code: " + allele);
111 					altBase = IUPAC.None;
112 				}
113 				return VariationType.Mutation;
114 			}
115 		}
116 
117 		return VariationType.NotAvailable;
118 	}
119 
120 	public IUPAC getAltBase() {
121 		return altBase;
122 	}
123 
124 	public String getGenotype() {
125 		return genotype;
126 	}
127 
128 	public void setGenotype(String genotype) {
129 		this.genotype = genotype;
130 		this.variationType = detectVariationType(genotype);
131 	}
132 
133 	@Override
134 	public String toString() {
135 		return SilkLens.toSilk(this);
136 	}
137 
138 }