Package versusSNP.genome

Source Code of versusSNP.genome.ORF

package versusSNP.genome;

import java.util.Iterator;

import versusSNP.blast.BlastList;
import versusSNP.blast.BlastSet;
import versusSNP.gui.UICaption;

public class ORF implements Comparable<ORF> {
  public static final byte NAME_KEY = 1;
  public static final byte BEGIN_KEY = 2;
  private String name;
  private int begin, end, length;
  private boolean strand;
  private Sequence sequence;
  private BlastList blastList;
  public static byte compare_key = NAME_KEY;
 
  private ORF() {
    super();
    begin = end = length = 0;
    strand = true;
    blastList = new BlastList();
  }
  public ORF(int begin) {
    this();
    this.begin = begin;
  }
  public ORF(String name) {
    this();
    this.name = name;
  }
  public ORF(int begin, int end) {
    this();
    this.begin = begin;
    this.end = end;
    this.length = Math.abs(end - begin) + 1;
    this.strand = begin < end ? true : false;
  }
  public ORF(int begin, int end, boolean strand) {
    this(begin, end);
    this.strand = strand;
  }
  public ORF(int begin, int end, int length, boolean strand) {
    this(begin, end, strand);
    this.length = length;
  }
  public ORF(String name, int begin, int end) {
    this(begin, end);
    this.name = name;
    this.strand = begin < end ? true : false;
  }
  public ORF(String name, int begin, int end, boolean strand) {
    this(name, begin, end);
    this.strand = strand;
  }
  public ORF(String name, int begin, int end, int length, boolean strand) {
    this(name, begin, end, strand);
    this.length = length;
  }
  public String getName() {
    return name;
  }
  public int getBegin() {
    return begin;
  }
  public int getEnd() {
    return end;
  }
  public int getLength() {
    return length;
  }
  public int getPosInGenome(int posInOrf) {
    return getPosInGenome(posInOrf, this);
  }
  public static int getPosInGenome(int posInOrf, ORF orf) {
    return orf.isStrand() ? orf.getBegin() + posInOrf - 1 : orf.getEnd() - posInOrf + 1;
  }
  public char getStrand() {
    return strand ? '+' : '-';
  }
  public boolean isStrand() {
    return strand;
  }
  public Sequence getSequence() {
    return sequence;
  }
  public void setBegin(int begin) {
    this.begin = begin;
    this.length = Math.abs(end - begin) + 1;
  }
  public String getTooltip() {
    return getTooltip(this);
  }
  public String getSummary() {
    return getSummary(this);
  }
  public String getBriefSummary() {
    return getBriefSummary(this);
  }
  public static String getTooltip(final ORF orf) {
    return new StringBuffer().append(UICaption.tooltip_orf_begin).append(orf.getBegin())
      .append(UICaption.tooltip_orf_end).append(orf.getEnd())
      .append(UICaption.tooltip_orf_strand).append(orf.getStrand()).toString();
  }
  public static String getBriefSummary(final ORF orf) {
    return new StringBuffer(UICaption.info_title_summary).append('\n')
      .append(UICaption.info_orf_begin).append(orf.getBegin()).append('\n')
      .append(UICaption.info_orf_end).append(orf.getEnd()).append('\n')
      .append(UICaption.info_orf_length).append(orf.getLength()).append('\n')
      .append(UICaption.info_orf_strand).append(orf.getStrand()).append('\n').toString();
  }
  public static String getSummary(final ORF orf) {
    return new StringBuffer(UICaption.info_title_summary).append('\n')
      .append(UICaption.info_orf_begin).append(orf.getBegin()).append('\n')
      .append(UICaption.info_orf_end).append(orf.getEnd()).append('\n')
      .append(UICaption.info_orf_length).append(orf.getLength()).append('\n')
      .append(UICaption.info_orf_strand).append(orf.getStrand()).append('\n')
      .append(UICaption.info_orf_summary_nt).append(orf.getSequence().getSummary()).append('\n')
      .append(UICaption.info_orf_gc).append(orf.getSequence().gcContent()).append('\n')
      .append(UICaption.info_orf_gc_skew).append(orf.getSequence().gcSkew()).append('\n')
      .append(UICaption.info_orf_ag).append(orf.getSequence().agContent()).append('\n')
      .append(UICaption.info_orf_ag_skew).append(orf.getSequence().agSkew()).append('\n').toString();
  }
  public void setEnd(int end) {
    this.end = end;
    this.length = Math.abs(end - begin) + 1;
  }
  public void setStrand(boolean strand) {
    this.strand = strand;
  }
  public void setSequence(Sequence sequence) {
    this.sequence = sequence;
  }
  public BlastSet getBlastSet(String subjectName) {
    for (Iterator<BlastSet> iter = blastList.iterator(); iter.hasNext();) {
      BlastSet set = iter.next();
      if (set.getSName().equals(subjectName)) {
        return set;
      }
    }
    return null;
  }
  public BlastList getBlastList() {
    return blastList;
  }
  public void addBlastSet(BlastSet blastSet) {
    this.blastList.add(blastSet);
  }
  @Override
  public int compareTo(final ORF o) {
    switch (compare_key) {
    case NAME_KEY:
      return name.compareTo(o.getName());
    case BEGIN_KEY:
      return begin - o.getBegin();

    default:
      return begin - o.getBegin();
    }
  }
 
  public void statSNP() {
    for (Iterator<BlastSet> iter = blastList.iterator(); iter.hasNext();) {
      BlastSet set = iter.next();
      if (!set.isQuerySubjectOrfSet()) return;
      ORF sOrf = set.getSOrf();
      for (Iterator<SNP> iter2 = set.getSNPList().iterator(); iter2.hasNext();) {
        try {
          SNP snp = iter2.next();
          Codon qCodon = new Codon(sequence.subString(
              snp.getQCodonBeginPos(), snp.getQCodonEndPos()));
          Codon sCodon = new Codon(sOrf.getSequence().subString(
              snp.getSCodonBeginPos(), snp.getSCodonEndPos()));
//          System.out.println(sOrf.getName() + ' '+sOrf.getSequence().subString(
//              snp.getSCodonBeginPos()-3, snp.getSCodonEndPos()+3));
          snp.setQPosInCodon(snp.getQCodonBeginPos());
          snp.setSPosInCodon(snp.getSCodonBeginPos());
          snp.setQCodon(qCodon);
          snp.setSCodon(sCodon);
          snp.setQPosInGenome(this);
          snp.setSPosInGenome(set.getSOrf());
          snp.setComplement(set.isComplement());
          snp.setComplementPosInCodon(set.isComplement());
          snp.setType();
          snp.setQOrf(this);
          snp.setSOrf(set.getSOrf());
          snp.setComplete();
        } catch (IndexOutOfBoundsException e) {
          continue;
        }
      }
    }
  }
  @Override
  public String toString() {
    return name;
  }
}
TOP

Related Classes of versusSNP.genome.ORF

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.