예제 #1
0
 public byte getBase(double position) {
   int basePosition = (int) position;
   for (AlignmentBlock block : getAlignmentBlocks()) {
     if (block.contains(basePosition)) {
       int offset = basePosition - block.getStart();
       byte base = block.getBases()[offset];
       return base;
     }
   }
   return 0;
 }
예제 #2
0
 public byte getPhred(double position) {
   int basePosition = (int) position;
   for (AlignmentBlock block : getAlignmentBlocks()) {
     if (block.contains(basePosition)) {
       int offset = basePosition - block.getStart();
       byte score = block.getQuality(offset);
       return score;
     }
   }
   return 0;
 }
예제 #3
0
 private AlignmentBlock[] keepSoftClips(AlignmentBlock[] blocks) {
   int numSoftCLippedBlocks = 0;
   for (AlignmentBlock block : blocks) {
     if (block.isSoftClipped()) numSoftCLippedBlocks++;
   }
   AlignmentBlock[] tmp = new AlignmentBlock[numSoftCLippedBlocks];
   int j = 0;
   for (int i = 0; i < numSoftCLippedBlocks; i++) {
     AlignmentBlock block = blocks[j++];
     if (block.isSoftClipped()) {
       tmp[i] = block;
     }
   }
   return tmp;
 }
예제 #4
0
  private void addSoftClipBlock(
      ObjectArrayList<AlignmentBlock> blocks,
      int position,
      String softClippedBasesLeft,
      byte[] readQualScores,
      boolean hasSoftClippedQuality,
      byte[] softClippedQuality,
      int j) {
    final int length = softClippedBasesLeft.length();
    byte[] bases = new byte[length];
    byte[] scores = new byte[length];

    for (int i = 0; i < length; i++) {
      bases[i] = (byte) softClippedBasesLeft.charAt(i);
      scores[i] = hasSoftClippedQuality ? softClippedQuality[i] : readQualScores[j++];
    }
    final AlignmentBlock alignmentBlock = AlignmentBlock.getInstance(position, bases, scores, this);
    alignmentBlock.setSoftClipped(true);
    blocks.add(alignmentBlock);
  }
예제 #5
0
  private int addBlock(
      ObjectArrayList<AlignmentBlock> blocks,
      int start,
      ByteArrayList bases,
      ByteArrayList scores) {

    blocks.add(
        AlignmentBlock.getInstance(
            start,
            bases.toByteArray(new byte[bases.size()]),
            scores.toByteArray(new byte[scores.size()]),
            this));
    start += bases.size();
    bases.clear();
    scores.clear();
    return start;
  }
예제 #6
0
 public int compare(AlignmentBlock alignmentBlock, AlignmentBlock alignmentBlock1) {
   return alignmentBlock.getStart() - alignmentBlock1.getStart();
 }
예제 #7
0
  /**
   * This method splits blocks whose boundaries contain a read deletion.
   *
   * @param blocks
   * @param alignmentEntry
   * @return
   */
  private ObjectArrayList<AlignmentBlock> introduceDeletions(
      ObjectArrayList<AlignmentBlock> blocks, Alignments.AlignmentEntry alignmentEntry) {

    ObjectArrayList<AlignmentBlock> newBlocks = new ObjectArrayList<AlignmentBlock>();

    for (Alignments.SequenceVariation var : alignmentEntry.getSequenceVariationsList()) {

      for (AlignmentBlock block : blocks) {
        if (!block.isSoftClipped()) {

          final int vrPos = var.getPosition() + entry.getPosition();
          if (hasReadDeletion(var) && vrPos >= block.getStart() && vrPos <= block.getEnd()) {

            ByteList leftBases = new ByteArrayList(block.getBases());
            ByteList leftScores = new ByteArrayList(block.getQualities());
            ByteList rightBases = new ByteArrayList(block.getBases());
            ByteList rightScores = new ByteArrayList(block.getQualities());
            int deletionPosition = var.getPosition() - 1;
            leftBases = leftBases.subList(0, deletionPosition);
            rightBases = rightBases.subList(deletionPosition, rightBases.size());

            leftScores = leftScores.subList(0, deletionPosition);
            rightScores = rightScores.subList(deletionPosition, rightScores.size());

            AlignmentBlock left =
                AlignmentBlock.getInstance(
                    block.getStart(),
                    leftBases.toByteArray(new byte[leftBases.size()]),
                    leftScores.toByteArray(new byte[leftScores.size()]),
                    this);

            AlignmentBlock right =
                AlignmentBlock.getInstance(
                    block.getStart() + leftBases.size() + var.getFrom().length(),
                    rightBases.toByteArray(new byte[rightBases.size()]),
                    rightScores.toByteArray(new byte[rightScores.size()]),
                    this);

            blocks.remove(block);
            newBlocks.add(left);
            newBlocks.add(right);
          }
        }
      }
    }

    newBlocks.addAll(blocks);
    return newBlocks;
  }