Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Class for storing and working with sam formatted DNA sequence.
- *
- * Upon construction, only the String record is stored.
- * All querying of fields is done on demand, to save time.
- *
- */
- public class SamRecord implements Record {
- private final String read;
- private String id = null;
- private int flag = -1;
- private String referenceName = null;
- private int pos = -1;
- private int mappingQuality = -1;
- private String cigar = null;
- private String mateReferenceName = null;
- private int matePosition = -1;
- private int templateLength = -1;
- private String sequence = null;
- private String quality = null;
- private String variableTerms = null;
- private final static String REPEAT_TERM = "ZS:Z:R";
- private final static String MATCH_TERM = "ZS:Z:NM";
- private final static String QUALITY_CHECK_TERM = "ZS:Z:QC";
- /** Simple constructor for the sam record
- * @param read full read
- */
- public SamRecord(String read) {
- this.read = read;
- }
- public String getRead() {
- return read;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public String getId() {
- if(id == null){
- id = XsamReadQueries.findID(read);
- }
- return id;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public int getFlag() throws NumberFormatException {
- if(flag == -1) {
- flag = Integer.parseInt(XsamReadQueries.findElement(read, 1));
- }
- return flag;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public String getReferenceName() {
- if(referenceName == null){
- referenceName = XsamReadQueries.findReferneceName(read);
- }
- return referenceName;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public int getPos() throws NumberFormatException{
- if(pos == -1){
- pos = Integer.parseInt(XsamReadQueries.findElement(read, 3));
- }
- return pos;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public int getMappingQuality() throws NumberFormatException {
- if(mappingQuality == -1){
- mappingQuality = Integer.parseInt(XsamReadQueries.findElement(read, 4));
- }
- return mappingQuality;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public String getCigar() {
- if(cigar == null){
- cigar = XsamReadQueries.findCigar(read);
- }
- return cigar;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public String getMateReferenceName() {
- if(mateReferenceName == null){
- mateReferenceName = XsamReadQueries.findElement(read, 6);
- }
- return mateReferenceName;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public int getMatePosition() throws NumberFormatException {
- if(matePosition == -1){
- matePosition = Integer.parseInt(XsamReadQueries.findElement(read, 7));
- }
- return matePosition;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public int getTemplateLength() throws NumberFormatException {
- if(templateLength == -1){
- templateLength = Integer.parseInt(XsamReadQueries.findElement(read, 8));
- }
- return templateLength;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public String getSequence() {
- if(sequence == null){
- sequence = XsamReadQueries.findBaseSequence(read);
- }
- return sequence;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public String getQuality() {
- if(quality == null){
- quality = XsamReadQueries.findElement(read, 10);
- }
- return quality;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isRepeat() {
- return read.contains(REPEAT_TERM);
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isMapped() {
- return !read.contains(MATCH_TERM);
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public String getVariableTerms() {
- if(variableTerms == null){
- variableTerms = XsamReadQueries.findVariableRegionSequence(read);
- }
- return variableTerms;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isQualityFailed() {
- return read.contains(QUALITY_CHECK_TERM);
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- SamRecord samRecord = (SamRecord) o;
- return Objects.equals(read, samRecord.read);
- }
- @Override
- public int hashCode() {
- return Objects.hash(read);
- }
- @Override
- public String toString() {
- return read;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement