Skip to content

Commit 22931e8

Browse files
committed
Add methods to delete alignment column from an AFPChain
1 parent 69eef76 commit 22931e8

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AlignmentTools.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,4 +1398,96 @@ public static void fillAlignedAtomArrays(AFPChain afpChain, Atom[] ca1,
13981398
}
13991399

14001400
}
1401+
1402+
/**
1403+
* Find the alignment position with the highest atomic distance between the
1404+
* equivalent atomic positions of the arrays and remove it from the
1405+
* alignment.
1406+
*
1407+
* @param afpChain
1408+
* original alignment, will be modified
1409+
* @param ca1
1410+
* atom array, will not be modified
1411+
* @param ca2
1412+
* atom array, will not be modified
1413+
* @return the original alignment, with the alignment position at the
1414+
* highest distance removed
1415+
* @throws StructureException
1416+
*/
1417+
public static AFPChain deleteHighestDistanceColumn(AFPChain afpChain,
1418+
Atom[] ca1, Atom[] ca2) throws StructureException {
1419+
1420+
int[][][] optAln = afpChain.getOptAln();
1421+
1422+
int maxBlock = 0;
1423+
int maxPos = 0;
1424+
double maxDistance = Double.MIN_VALUE;
1425+
1426+
for (int b = 0; b < optAln.length; b++) {
1427+
for (int p = 0; p < optAln[b][0].length; p++) {
1428+
double distance = Calc.getDistance(ca1[optAln[b][0][p]],
1429+
ca2[optAln[b][1][p]]);
1430+
if (distance > maxDistance) {
1431+
maxBlock = b;
1432+
maxPos = p;
1433+
}
1434+
}
1435+
}
1436+
1437+
return deleteColumn(afpChain, ca1, ca2, maxBlock, maxPos);
1438+
}
1439+
1440+
/**
1441+
* Delete an alignment position from the original alignment object.
1442+
*
1443+
* @param afpChain
1444+
* original alignment, will be modified
1445+
* @param ca1
1446+
* atom array, will not be modified
1447+
* @param ca2
1448+
* atom array, will not be modified
1449+
* @param block
1450+
* block of the alignment position
1451+
* @param pos
1452+
* position index in the block
1453+
* @return the original alignment, with the alignment position removed
1454+
* @throws StructureException
1455+
*/
1456+
public static AFPChain deleteColumn(AFPChain afpChain, Atom[] ca1,
1457+
Atom[] ca2, int block, int pos) throws StructureException {
1458+
1459+
// Check validity of the inputs
1460+
if (afpChain.getBlockNum() <= block) {
1461+
throw new IndexOutOfBoundsException(String.format(
1462+
"Block index requested (%d) is higher than the total number of AFPChain blocks (%d).",
1463+
block, afpChain.getBlockNum()));
1464+
}
1465+
if (afpChain.getBlockSize()[block] <= pos) {
1466+
throw new IndexOutOfBoundsException(String.format(
1467+
"Position index requested (%d) is higher than the total number of aligned position in the AFPChain block (%d).",
1468+
block, afpChain.getBlockSize()[block]));
1469+
}
1470+
1471+
int[][][] optAln = afpChain.getOptAln();
1472+
1473+
int[] newPos0 = new int[optAln[block][0].length - 1];
1474+
int[] newPos1 = new int[optAln[block][1].length - 1];
1475+
1476+
int position = 0;
1477+
for (int p = 0; p < optAln[block][0].length; p++) {
1478+
1479+
if (p == pos)
1480+
continue;
1481+
1482+
newPos0[position] = optAln[block][0][position];
1483+
newPos1[position] = optAln[block][1][position];
1484+
1485+
position++;
1486+
}
1487+
1488+
optAln[block][0] = newPos0;
1489+
optAln[block][1] = newPos1;
1490+
1491+
return AlignmentTools.replaceOptAln(optAln, afpChain, ca1, ca2);
1492+
}
14011493
}

0 commit comments

Comments
 (0)