1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
31
32
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
49 public VariationType variationType;
50 public String chr;
51 public int start = -1;
52 public String refBase;
53
54
55 private String genotype;
56 private IUPAC altBase;
57
58 public int indelLength = 0;
59
60 public GeneticVariation() {
61 }
62
63
64
65
66
67
68
69
70
71
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
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 }