Package versusSNP.blast

Source Code of versusSNP.blast.BlastSet

package versusSNP.blast;

import versusSNP.blast.util.AlignmentStore;
import versusSNP.blast.util.SNPList;
import versusSNP.genome.ORF;
import versusSNP.genome.SNP;
import versusSNP.gui.UICaption;
import versusSNP.util.Utils;


public class BlastSet {
  private String qName;
  private String sName;
  private int score;
  private int identity1;
  private int identity2;
  private int overlap;
  private int qBegin;
  private int qEnd;
  private int qLen;
  private int sBegin;
  private int sEnd;
  private int sLen;
  private StringBuffer annotation;
  private StringBuffer qSeq;
  private StringBuffer sSeq;
  private boolean strand1;
  private boolean strand2;
  private double expect;
  private SNPList snpList;
  private AlignmentStore alignmentStore;
  private ORF qOrf, sOrf;
  private boolean isQuerySubjectOrfSet; // a flag to indicate qOrf and sOrf are set for this BlastSet
   
  public BlastSet() {
    super();
    qSeq = new StringBuffer();
    sSeq = new StringBuffer();
    annotation = new StringBuffer();
    snpList = new SNPList();
    alignmentStore = new AlignmentStore();
    isQuerySubjectOrfSet = false;
  }

  public BlastSet(String qName) {
    this();
    this.qName = qName;
  }

  public BlastSet(String qName, String sName) {
    this();
    this.qName = qName;
    this.sName = sName;
  }

  public String getQName() {
    return qName;
  }

  public String getSName() {
    return sName;
  }

  public String getAnnotation() {
    return annotation.toString();
  }

  public int getScore() {
    return score;
  }

  public int getIdentity1() {
    return identity1;
  }

  public int getIdentity2() {
    return identity2;
  }

  public int getOverlap() {
    return overlap;
  }

  public int getOverlapPercent() {
    if (qLen != 0 && sLen != 0)
      return Math.min(identity1*100/qLen, identity1*100/sLen);
    return 0;
  }

  public boolean isQStrand() {
    return strand1;
  }

  public boolean isSStrand() {
    return strand2;
  }

  public boolean isComplement() {
    return strand1 != strand2;
  }

  public int getQBegin() {
    return qBegin;
  }

  public int getQEnd() {
    return qEnd;
  }

  public int getQLen() {
    return qLen;
  }

  public int biasQStrand() {
    return strand1 ? 1 : -1;
  }

  public int getSBegin() {
    return sBegin;
  }

  public int getSEnd() {
    return sEnd;
  }

  public int getSLen() {
    return sLen;
  }

  public int biasSStrand() {
    return strand2 ? 1 : -1;
  }
 
  public String getQSeq() {
    return qSeq.toString();
  }

  public String getSSeq() {
    return sSeq.toString();
  }

  public int getQSeqLength() {
    return qSeq.length();
  }

  public int getSSeqLength() {
    return sSeq.length();
  }

  public char atQSeq(int index) {
    return qSeq.charAt(index);
  }

  public char atSSeq(int index) {
    return sSeq.charAt(index);
  }

  public double getExpect() {
    return expect;
  }

  public SNPList getSNPList() {
    return snpList;
  }

  public ORF getQOrf() {
    return qOrf;
  }

  public ORF getSOrf() {
    return sOrf;
  }

  public void setQName(String name) {
    qName = name;
  }

  public void setSName(String name) {
    sName = name;
  }

  public void setAnnotation(String annotation) {
    this.annotation = new StringBuffer(annotation);
  }

  public void addAnnotation(String annotation) {
    this.annotation.append(annotation);
  }

  public void setScore(String score) throws NumberFormatException {
    this.score = Utils.toIntegar(score);
  }

  public void setIdentity1(String identity1) throws NumberFormatException {
    this.identity1 = Utils.toIntegar(identity1);
  }

  public void setIdentity2(String identity2) throws NumberFormatException {
    this.identity2 = Utils.toIntegar(identity2);
  }

  public void setOverlap(String overlap) throws NumberFormatException {
    this.overlap = Utils.toIntegar(overlap);
  }

  public void setStrand1(String strand) {
    this.strand1 = parseStrand(strand);
  }

  public void setStrand2(String strand) {
    this.strand2 = parseStrand(strand);
  }
 
  private static boolean parseStrand(String strand) {
    if (strand.equals("Plus"))
      return true;
    else
      return false;
  }
 
  public void setQBegin(String begin) throws NumberFormatException {
    qBegin = Utils.toIntegar(begin);
  }

  public void setQEnd(String end) throws NumberFormatException {
    qEnd = Utils.toIntegar(end);
  }

  public void setQLen(String len) throws NumberFormatException {
    qLen = Utils.toIntegar(len);
  }

  public void setSBegin(String begin) throws NumberFormatException {
    sBegin = Utils.toIntegar(begin);
  }

  public void setSEnd(String end) throws NumberFormatException {
    sEnd = Utils.toIntegar(end);
  }

  public void setSLen(String len) throws NumberFormatException {
    sLen = Utils.toIntegar(len);
  }

  public void setExpect(String expect) throws NumberFormatException {
    if (expect.charAt(0) == 'e' || expect.charAt(0) == 'E')
      this.expect = Double.parseDouble("0" + expect);
    else
      this.expect = Double.parseDouble(expect);
  }
 
  public void setQSeq(String seq) {
    qSeq = new StringBuffer(seq.toUpperCase());
  }

  public void setSSeq(String seq) {
    sSeq = new StringBuffer(seq.toUpperCase());
  }
 
  public void addQSeq(String seq) {
    qSeq.append(seq.toUpperCase());
  }

  public void addSSeq(String seq) {
    sSeq.append(seq.toUpperCase());
  }
 
  public void addQSeq(String seq, String begin, String end) {
    addQSeq(seq);
    alignmentStore.startsWithQSeq(seq, Utils.toIntegar(begin), Utils.toIntegar(end));
  }

  public void addSSeq(String seq, String begin, String end) {
    addSSeq(seq);
    alignmentStore.endsWithQSeq(seq, Utils.toIntegar(begin), Utils.toIntegar(end));
  }
 
  public void addSNP(SNP snp) {
    this.snpList.add(snp);
  }

  public String getSummary() {
    return getSummary(this);
  }
 
  public String getAlignment() {
    return alignmentStore.getAlignment();
  }
 
  public AlignmentStore getAlignmentStore() {
    return alignmentStore;
  }

  public static String getSummary(final BlastSet set) {
    return new StringBuffer(UICaption.info_title_summary).append('\n')
    .append(UICaption.info_blast_set_qname).append(set.getQName()).append('\n')
    .append(UICaption.info_blast_set_qbegin).append(set.getQBegin()).append('\n')
    .append(UICaption.info_blast_set_qend).append(set.getQEnd()).append('\n')
    .append(UICaption.info_blast_set_qlen).append(set.getQLen()).append('\n')
    .append(UICaption.info_blast_set_sname).append(set.getSName()).append('\n')
    .append(UICaption.info_blast_set_sbegin).append(set.getSBegin()).append('\n')
    .append(UICaption.info_blast_set_send).append(set.getSEnd()).append('\n')
    .append(UICaption.info_blast_set_slen).append(set.getSLen()).append('\n')
    .append(UICaption.info_blast_set_identity).append(set.getIdentity1()).append('/').append(set.getIdentity2()).append('\n')
    .append(UICaption.info_blast_set_overlap).append(set.getOverlap()).append('%').append('\n')
    .append(UICaption.info_blast_set_score).append(set.getScore()).append('\n')
    .append(UICaption.info_blast_set_expect).append(set.getExpect()).append('\n')
    .append(UICaption.info_blast_set_annotation).append(set.getAnnotation()).append('\n')
    .toString();
  }

  public void setQueryOrf(ORF orf) {
    if (qName.equals(orf.getName())) {
      qOrf = orf;
      if (qLen == 0)
        qLen = orf.getLength();
    }
  }

  public void setSubjectOrf(ORF orf) {
    if (sName.equals(orf.getName())) {
      sOrf = orf;
      if (sLen == 0)
        sLen = orf.getLength();
    }
  }
 
  public void setQuerySubjectOrf(ORF qOrf, ORF sOrf) {
    setQueryOrf(qOrf);
    setSubjectOrf(sOrf);
    if (qOrf != null && sOrf != null)
      isQuerySubjectOrfSet = true;
  }

  public boolean isQuerySubjectOrfSet() {
    return isQuerySubjectOrfSet;
  }
 
  public void emptyQuerySubjectSeq() {
    qSeq = null;
    sSeq = null;
  }
}
TOP

Related Classes of versusSNP.blast.BlastSet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.