001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org 019 * 020 */ 021 022package org.biojava.bio.dp.twohead; 023 024import org.biojava.bio.dp.BackPointer; 025import org.biojava.bio.symbol.IllegalSymbolException; 026import org.biojava.bio.symbol.SymbolList; 027 028 /** 029 * @author Matthew Pocock 030 */ 031 public class MatrixPairDPCursor 032 extends AbstractMatrixPairDPCursor { 033 public MatrixPairDPCursor( 034 SymbolList seq1, 035 SymbolList seq2, 036 int depth1, 037 int depth2, 038 PairDPMatrix matrix, 039 EmissionCache eCache 040 ) throws IllegalSymbolException { 041 super(seq1, seq2, 0, 0, depth1, depth2, matrix, eCache); 042 } 043 044 public boolean hasNext() { 045 return 046 pos[1] <= (seqs[1].length()+1); 047 } 048 049 public void next(Cell[][] cells) { 050 for(int i = 0; i < depth[0]; i++) { 051 Cell[] cellI = cells[i]; 052 int ii = pos[0] - i; 053 boolean outI = ii < 0 || ii > seqs[0].length()+1; 054 if(outI) { 055 for(int j = 0; j < depth[1]; j++) { 056 Cell c = cellI[j]; 057 c.scores = zeroCol; 058 c.emissions = zeroCol; 059 c.backPointers = emptyBP; 060 } 061 } else { 062 double[][] sMatI = this.sMatrix[ii]; 063 double[][] emisI = this.emissions[ii]; 064 BackPointer[][] bPI = this.bPointers[ii]; 065 for(int j = 0; j < depth[1]; j++) { 066 int jj = pos[1] - j; 067 boolean outJ = jj < 0 || jj > seqs[1].length()+1; 068 Cell c = cellI[j]; 069 if(outJ) { 070 c.scores = zeroCol; 071 c.emissions = zeroCol; 072 c.backPointers = emptyBP; 073 } else { 074 c.scores = sMatI[jj]; 075 c.emissions = emisI[jj]; 076 c.backPointers = bPI[jj]; 077 } 078 } 079 } 080 } 081 if(pos[0] <= seqs[0].length()) { 082 pos[0]++; 083 } else { 084 pos[0] = 0; 085 pos[1]++; 086 } 087 } 088 } 089