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  // SAMReadLight.java
20  // Since: 2010/09/30
21  //
22  //--------------------------------------
23  package org.utgenome.gwt.utgb.client.bio;
24  
25  /**
26   * Light weight SAMRead
27   * 
28   * @author leo
29   * 
30   */
31  public class SAMReadLight extends Interval {
32  
33  	private static final long serialVersionUID = 1L;
34  
35  	//schema record(qname, flag, rname, start, end, mapq, cigar, mrnm, mpos, isize, seq, qual, tag*)
36  	public String qname;
37  	public int flag;
38  	// left-most position on the reference sequence
39  	public int unclippedStart;
40  	public int unclippedEnd;
41  	public String cigar;
42  
43  	public SAMReadLight() {
44  
45  	}
46  
47  	public SAMReadLight(int start, int end) {
48  		super(start, end);
49  	}
50  
51  	@Override
52  	public String toString() {
53  		StringBuilder sb = new StringBuilder();
54  		sb.append("flag=" + flag);
55  		return sb.toString();
56  	}
57  
58  	public boolean isMate(SAMReadLight other) {
59  		if (this.isFirstRead()) {
60  			if (other.isSecondRead())
61  				return qname != null && qname.equals(other.qname);
62  		}
63  		else {
64  			if (other.isFirstRead())
65  				return qname != null && qname.equals(other.qname);
66  		}
67  		return false;
68  	}
69  
70  	@Override
71  	public String getName() {
72  		return qname;
73  	}
74  
75  	@Override
76  	public boolean isSense() {
77  		return (flag & SAMReadFlag.FLAG_STRAND_OF_QUERY) == 0;
78  	}
79  
80  	@Override
81  	public boolean isAntiSense() {
82  		return !isSense();
83  	}
84  
85  	public String getSequence() {
86  		return null;
87  	}
88  
89  	public String getQV() {
90  		return null;
91  	}
92  
93  	//	@Override
94  	//	public void accept(OnGenomeDataVisitor visitor) {
95  	//		visitor.visitSAMReadLight(this);
96  	//	}
97  
98  	public boolean isPairedRead() {
99  		return SAMReadFlag.isPairedRead(this.flag);
100 	}
101 
102 	public boolean isMappedInProperPair() {
103 		return SAMReadFlag.isMappedInProperPair(this.flag);
104 	}
105 
106 	public boolean isFirstRead() {
107 		return SAMReadFlag.isFirstRead(this.flag);
108 	}
109 
110 	public boolean isSecondRead() {
111 		return SAMReadFlag.isSecondRead(this.flag);
112 	}
113 
114 	public boolean isUnmapped() {
115 		return SAMReadFlag.isQueryUnmapped(this.flag);
116 	}
117 
118 	public boolean unclippedSequenceHasOverlapWith(SAMReadLight other) {
119 		if (unclippedStart <= other.unclippedStart)
120 			return other.unclippedStart <= unclippedEnd;
121 		else
122 			return unclippedStart <= other.unclippedEnd;
123 
124 	}
125 
126 	public boolean unclippedSequenceContains(int startOnGenome) {
127 		return unclippedStart <= startOnGenome && startOnGenome <= unclippedEnd;
128 	}
129 
130 	@Override
131 	public void accept(OnGenomeDataVisitor visitor) {
132 		visitor.visitSAMReadLight(this);
133 	}
134 }