private boolean shiftRow() {

		int su = rnd.nextInt(order); // Select the repeat
		int rl = rnd.nextInt(2); // Select between moving right (0) or left (1)
		int res = rnd.nextInt(length); // Residue as a pivot

		// When the pivot residue is null try to add a residue from the freePool
		if (block.get(su).get(res) == null) {

			int right = res;
			int left = res;
			// Find the boundary to the right abd left
			while (block.get(su).get(right) == null && right < length - 1) {
				right++;
			}
			while (block.get(su).get(left) == null && left > 0) {
				left--;
			}

			// If they both are null the whole block is null
			if (block.get(su).get(left) == null
					&& block.get(su).get(right) == null) {
				return false;
			} else if (block.get(su).get(left) == null) {
				// Choose the sequentially previous residue of the known one
				Integer residue = block.get(su).get(right) - 1;
				if (freePool.contains(residue)) {
					block.get(su).set(res, residue);
					freePool.remove(residue);
				} else
					return false;
			} else if (block.get(su).get(right) == null) {
				// Choose the sequentially next residue of the known one
				Integer residue = block.get(su).get(left) + 1;
				if (freePool.contains(residue)) {
					block.get(su).set(res, residue);
					freePool.remove(residue);
				} else
					return false;
			} else {
				// If boundaries are consecutive swap null and position (R or L)
				if (block.get(su).get(right) == block.get(su).get(left) + 1) {
					switch (rl) {
					case 0: // to the right
						block.get(su).set(right - 1, block.get(su).get(right));
						block.get(su).set(right, null);
						break;
					case 1: // to the left
						block.get(su).set(left + 1, block.get(su).get(left));
						block.get(su).set(left, null);
						break;
					}
				} else {
					// Choose randomly a residue in between left and right to
					// add
					Integer residue = rnd.nextInt(block.get(su).get(right)
							- block.get(su).get(left) - 1)
							+ block.get(su).get(left) + 1;

					if (freePool.contains(residue)) {
						block.get(su).set(res, residue);
						freePool.remove(residue);
					}
				}
			}
			return true;
		}

		// When the residue is different than null
		switch (rl) {
		case 0: // Move to the right

			int leftBoundary = res - 1;
			int leftPrevRes = res;
			while (true) {
				if (leftBoundary < 0)
					break;
				else {
					if (block.get(su).get(leftBoundary) == null) {
						break; // gap
					} else if (block.get(su).get(leftPrevRes) > block.get(su)
							.get(leftBoundary) + 1) {
						break; // discontinuity
					}
				}
				leftPrevRes = leftBoundary;
				leftBoundary--;
			}
			leftBoundary++;

			int rightBoundary = res + 1;
			int rightPrevRes = res;
			while (true) {
				if (rightBoundary == length)
					break;
				else {
					if (block.get(su).get(rightBoundary) == null) {
						break; // gap
					} else if (block.get(su).get(rightPrevRes) + 1 < block.get(
							su).get(rightBoundary)) {
						break; // discontinuity
					}
				}
				rightPrevRes = rightBoundary;
				rightBoundary++;
			}
			rightBoundary--;

			// Residues at the boundary
			Integer residueR0 = block.get(su).get(rightBoundary);
			Integer residueL0 = block.get(su).get(leftBoundary);

			// Remove residue at the right of the block and add to the freePool
			block.get(su).remove(rightBoundary);
			if (residueR0 != null) {
				freePool.add(residueR0);
				Collections.sort(freePool);
			}

			// Add the residue at the left of the block
			residueL0 -= 1; // cannot be null, throw exception if it is
			if (freePool.contains(residueL0)) {
				block.get(su).add(leftBoundary, residueL0);
				freePool.remove(residueL0);
			} else {
				block.get(su).add(leftBoundary, null);
			}
			break;

		case 1: // Move to the left

			int leftBoundary1 = res - 1;
			int leftPrevRes1 = res;
			while (true) {
				if (leftBoundary1 < 0)
					break;
				else {
					if (block.get(su).get(leftBoundary1) == null) {
						break; // gap
					} else if (block.get(su).get(leftPrevRes1) > block.get(su)
							.get(leftBoundary1) + 1) {
						break; // discontinuity
					}
				}
				leftPrevRes1 = leftBoundary1;
				leftBoundary1--;
			}
			leftBoundary1++;

			int rightBoundary1 = res + 1;
			int rightPrevRes1 = res;
			while (true) {
				if (rightBoundary1 == length)
					break;
				else {
					if (block.get(su).get(rightBoundary1) == null) {
						break; // gap
					} else if (block.get(su).get(rightPrevRes1) + 1 < block
							.get(su).get(rightBoundary1)) {
						break; // discontinuity
					}
				}
				rightPrevRes1 = rightBoundary1;
				rightBoundary1++;
			}
			rightBoundary1--;

			// Residues at the boundary
			Integer residueR1 = block.get(su).get(rightBoundary1);
			Integer residueL1 = block.get(su).get(leftBoundary1);

			// Add the residue at the right of the block
			residueR1 += 1; // cannot be null
			if (freePool.contains(residueR1)) {
				if (rightBoundary1 == length - 1)
					block.get(su).add(residueR1);
				else
					block.get(su).add(rightBoundary1 + 1, residueR1);
				freePool.remove(residueR1);
			} else {
				block.get(su).add(rightBoundary1 + 1, null);
			}

			// Remove the residue at the left of the block
			block.get(su).remove(leftBoundary1);
			freePool.add(residueL1);
			Collections.sort(freePool);
			break;
		}
		checkGaps();
		return true;
	}
private boolean shiftRow ( ) { int su = rnd . nextInt ( order ) ; int rl = rnd . nextInt ( 2 ) ; int res = rnd . nextInt ( length ) ; if ( block . get ( su ) . get ( res ) == null ) { int right = res ; int left = res ; while ( block . get ( su ) . get ( right ) == null && right < length - 1 ) { right ++ ; } while ( block . get ( su ) . get ( left ) == null && left > 0 ) { left -- ; } if ( block . get ( su ) . get ( left ) == null && block . get ( su ) . get ( right ) == null ) { return false ; } else if ( block . get ( su ) . get ( left ) == null ) { Integer residue = block . get ( su ) . get ( right ) - 1 ; if ( freePool . contains ( residue ) ) { block . get ( su ) . set ( res , residue ) ; freePool . remove ( residue ) ; } else return false ; } else if ( block . get ( su ) . get ( right ) == null ) { Integer residue = block . get ( su ) . get ( left ) + 1 ; if ( freePool . contains ( residue ) ) { block . get ( su ) . set ( res , residue ) ; freePool . remove ( residue ) ; } else return false ; } else { if ( block . get ( su ) . get ( right ) == block . get ( su ) . get ( left ) + 1 ) { switch ( rl ) { case 0 : block . get ( su ) . set ( right - 1 , block . get ( su ) . get ( right ) ) ; block . get ( su ) . set ( right , null ) ; break ; case 1 : block . get ( su ) . set ( left + 1 , block . get ( su ) . get ( left ) ) ; block . get ( su ) . set ( left , null ) ; break ; } } else { Integer residue = rnd . nextInt ( block . get ( su ) . get ( right ) - block . get ( su ) . get ( left ) - 1 ) + block . get ( su ) . get ( left ) + 1 ; if ( freePool . contains ( residue ) ) { block . get ( su ) . set ( res , residue ) ; freePool . remove ( residue ) ; } } } return true ; } switch ( rl ) { case 0 : int leftBoundary = res - 1 ; int leftPrevRes = res ; while ( true ) { if ( leftBoundary < 0 ) break ; else { if ( block . get ( su ) . get ( leftBoundary ) == null ) { break ; } else if ( block . get ( su ) . get ( leftPrevRes ) > block . get ( su ) . get ( leftBoundary ) + 1 ) { break ; } } leftPrevRes = leftBoundary ; leftBoundary -- ; } leftBoundary ++ ; int rightBoundary = res + 1 ; int rightPrevRes = res ; while ( true ) { if ( rightBoundary == length ) break ; else { if ( block . get ( su ) . get ( rightBoundary ) == null ) { break ; } else if ( block . get ( su ) . get ( rightPrevRes ) + 1 < block . get ( su ) . get ( rightBoundary ) ) { break ; } } rightPrevRes = rightBoundary ; rightBoundary ++ ; } rightBoundary -- ; Integer residueR0 = block . get ( su ) . get ( rightBoundary ) ; Integer residueL0 = block . get ( su ) . get ( leftBoundary ) ; block . get ( su ) . remove ( rightBoundary ) ; if ( residueR0 != null ) { freePool . add ( residueR0 ) ; Collections . sort ( freePool ) ; } residueL0 -= 1 ; if ( freePool . contains ( residueL0 ) ) { block . get ( su ) . add ( leftBoundary , residueL0 ) ; freePool . remove ( residueL0 ) ; } else { block . get ( su ) . add ( leftBoundary , null ) ; } break ; case 1 : int leftBoundary1 = res - 1 ; int leftPrevRes1 = res ; while ( true ) { if ( leftBoundary1 < 0 ) break ; else { if ( block . get ( su ) . get ( leftBoundary1 ) == null ) { break ; } else if ( block . get ( su ) . get ( leftPrevRes1 ) > block . get ( su ) . get ( leftBoundary1 ) + 1 ) { break ; } } leftPrevRes1 = leftBoundary1 ; leftBoundary1 -- ; } leftBoundary1 ++ ; int rightBoundary1 = res + 1 ; int rightPrevRes1 = res ; while ( true ) { if ( rightBoundary1 == length ) break ; else { if ( block . get ( su ) . get ( rightBoundary1 ) == null ) { break ; } else if ( block . get ( su ) . get ( rightPrevRes1 ) + 1 < block . get ( su ) . get ( rightBoundary1 ) ) { break ; } } rightPrevRes1 = rightBoundary1 ; rightBoundary1 ++ ; } rightBoundary1 -- ; Integer residueR1 = block . get ( su ) . get ( rightBoundary1 ) ; Integer residueL1 = block . get ( su ) . get ( leftBoundary1 ) ; residueR1 += 1 ; if ( freePool . contains ( residueR1 ) ) { if ( rightBoundary1 == length - 1 ) block . get ( su ) . add ( residueR1 ) ; else block . get ( su ) . add ( rightBoundary1 + 1 , residueR1 ) ; freePool . remove ( residueR1 ) ; } else { block . get ( su ) . add ( rightBoundary1 + 1 , null ) ; } block . get ( su ) . remove ( leftBoundary1 ) ; freePool . add ( residueL1 ) ; Collections . sort ( freePool ) ; break ; } checkGaps ( ) ; return true ; }
Move all the block residues of one repeat one position to the left or
right and move the corresponding boundary residues from the freePool to
the block, and viceversa.
<p>
The boundaries are determined by any irregularity (either a gap or a
discontinuity in the alignment.