FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Extracting duplicate code to a method. Some cleanups · biojava/biojava@568a8d4 · GitHub

Commit 568a8d4

Browse files
committed
Extracting duplicate code to a method. Some cleanups
1 parent 45f1d70 commit 568a8d4

3 files changed

Lines changed: 26 additions & 71 deletions

File tree

‎biojava-structure/src/main/java/org/biojava/nbio/structure/cluster/SubunitCluster.java‎

Lines changed: 19 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -325,51 +325,9 @@ public boolean mergeSequence(SubunitCluster other, SubunitClustererParameters pa
325325
}
326326
}
327327

328-
// Do a List intersection to find out which EQR columns to remove
329-
List<Integer> thisRemove = new ArrayList<>();
330-
List<Integer> otherRemove = new ArrayList<>();
331-
332-
for (int t = 0; t < this.subunitEQR.get(this.representative).size(); t++) {
333-
// If the index is aligned do nothing, otherwise mark as removing
334-
if (!thisAligned.contains(this.subunitEQR.get(this.representative)
335-
.get(t)))
336-
thisRemove.add(t);
337-
}
338-
339-
for (int t = 0; t < other.subunitEQR.get(other.representative).size(); t++) {
340-
// If the index is aligned do nothing, otherwise mark as removing
341-
if (!otherAligned.contains(other.subunitEQR.get(
342-
other.representative).get(t)))
343-
otherRemove.add(t);
344-
}
345-
// Now remove unaligned columns, from end to start
346-
Collections.sort(thisRemove);
347-
Collections.reverse(thisRemove);
348-
Collections.sort(otherRemove);
349-
Collections.reverse(otherRemove);
350-
351-
for (Integer column : thisRemove) {
352-
for (List<Integer> eqr : this.subunitEQR) {
353-
eqr.remove(column);
354-
}
355-
}
356-
357-
for (Integer column : otherRemove) {
358-
for (List<Integer> eqr : other.subunitEQR) {
359-
eqr.remove(column);
360-
}
361-
}
362-
363-
// The representative is the longest sequence
364-
if (this.subunits.get(this.representative).size() < other.subunits.get(
365-
other.representative).size())
366-
this.representative = other.representative + subunits.size();
367-
368-
this.subunits.addAll(other.subunits);
369-
this.subunitEQR.addAll(other.subunitEQR);
328+
updateEquivResidues(other, thisAligned, otherAligned);
370329

371330
this.method = SubunitClustererMethod.SEQUENCE;
372-
373331
pseudoStoichiometric = !params.isHighConfidenceScores(sequenceIdentity,sequenceCoverage);
374332

375333
return true;
@@ -443,8 +401,8 @@ public boolean mergeStructure(SubunitCluster other, SubunitClustererParameters p
443401

444402
// Merge clusters
445403
List<List<Integer>> alignedRes = msa.getBlock(0).getAlignRes();
446-
List<Integer> thisAligned = new ArrayList<Integer>();
447-
List<Integer> otherAligned = new ArrayList<Integer>();
404+
List<Integer> thisAligned = new ArrayList<>();
405+
List<Integer> otherAligned = new ArrayList<>();
448406

449407
// Extract the aligned residues of both Subunit
450408
for (int p = 0; p < msa.length(); p++) {
@@ -467,24 +425,30 @@ public boolean mergeStructure(SubunitCluster other, SubunitClustererParameters p
467425
}
468426
}
469427

428+
updateEquivResidues(other, thisAligned, otherAligned);
429+
430+
this.method = SubunitClustererMethod.STRUCTURE;
431+
pseudoStoichiometric = true;
432+
433+
return true;
434+
}
435+
436+
private void updateEquivResidues(SubunitCluster other, List<Integer> thisAligned, List<Integer> otherAligned) {
470437
// Do a List intersection to find out which EQR columns to remove
471-
List<Integer> thisRemove = new ArrayList<Integer>();
472-
List<Integer> otherRemove = new ArrayList<Integer>();
438+
List<Integer> thisRemove = new ArrayList<>();
439+
List<Integer> otherRemove = new ArrayList<>();
473440

474441
for (int t = 0; t < this.subunitEQR.get(this.representative).size(); t++) {
475442
// If the index is aligned do nothing, otherwise mark as removing
476-
if (!thisAligned.contains(this.subunitEQR.get(this.representative)
477-
.get(t)))
443+
if (!thisAligned.contains(this.subunitEQR.get(this.representative).get(t)))
478444
thisRemove.add(t);
479445
}
480446

481447
for (int t = 0; t < other.subunitEQR.get(other.representative).size(); t++) {
482448
// If the index is aligned do nothing, otherwise mark as removing
483-
if (!otherAligned.contains(other.subunitEQR.get(
484-
other.representative).get(t)))
449+
if (!otherAligned.contains(other.subunitEQR.get(other.representative).get(t)))
485450
otherRemove.add(t);
486451
}
487-
488452
// Now remove unaligned columns, from end to start
489453
Collections.sort(thisRemove);
490454
Collections.reverse(thisRemove);
@@ -504,17 +468,12 @@ public boolean mergeStructure(SubunitCluster other, SubunitClustererParameters p
504468
}
505469

506470
// The representative is the longest sequence
507-
if (this.subunits.get(this.representative).size() < other.subunits.get(
508-
other.representative).size())
471+
if (this.subunits.get(this.representative).size() < other.subunits.get(other.representative).size())
509472
this.representative = other.representative + subunits.size();
510473

511474
this.subunits.addAll(other.subunits);
512475
this.subunitEQR.addAll(other.subunitEQR);
513476

514-
this.method = SubunitClustererMethod.STRUCTURE;
515-
pseudoStoichiometric = true;
516-
517-
return true;
518477
}
519478

520479
/**
@@ -564,9 +523,9 @@ public boolean divideInternally(SubunitClustererParameters clusterParams)
564523
List<List<Integer>> alignedRes = result.getMultipleAlignment()
565524
.getBlock(0).getAlignRes();
566525

567-
List<List<Integer>> columns = new ArrayList<List<Integer>>();
526+
List<List<Integer>> columns = new ArrayList<>();
568527
for (int s = 0; s < alignedRes.size(); s++)
569-
columns.add(new ArrayList<Integer>(alignedRes.get(s).size()));
528+
columns.add(new ArrayList<>(alignedRes.get(s).size()));
570529

571530
// Extract the aligned columns of each repeat in the Subunit
572531
for (int col = 0; col < alignedRes.get(0).size(); col++) {

‎biojava-structure/src/main/java/org/biojava/nbio/structure/cluster/SubunitClusterer.java‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ public static Stoichiometry cluster(Structure structure,
5656
return cluster(subunits, params);
5757
}
5858

59-
public static Stoichiometry cluster(List<Subunit> subunits,
60-
SubunitClustererParameters params) {
61-
62-
// The collection of clusters to return
63-
List<SubunitCluster> clusters = new ArrayList<SubunitCluster>();
64-
59+
public static Stoichiometry cluster(List<Subunit> subunits, SubunitClustererParameters params) {
60+
List<SubunitCluster> clusters = new ArrayList<>();
6561
if (subunits.size() == 0)
6662
return new Stoichiometry(clusters);
6763

‎biojava-structure/src/test/java/org/biojava/nbio/structure/cluster/TestSubunitCluster.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public class TestSubunitCluster {
5252
@Test
5353
public void testMergeIdentical() {
5454

55-
// Create an Atom Array of ploy-alanine
56-
List<Atom> atoms = new ArrayList<Atom>(10);
55+
// Create an Atom Array of poly-alanine
56+
List<Atom> atoms = new ArrayList<>(10);
5757
for (int i = 0; i < 10; i++) {
5858
Group g = new AminoAcidImpl();
5959
g.setPDBName("ALA");
@@ -79,7 +79,7 @@ public void testMergeIdentical() {
7979
assertEquals(sc1.length(), 10);
8080

8181
// Create an Atom Array of poly-glycine
82-
List<Atom> atoms2 = new ArrayList<Atom>(10);
82+
List<Atom> atoms2 = new ArrayList<>(10);
8383
for (int i = 0; i < 10; i++) {
8484
Group g = new AminoAcidImpl();
8585
g.setPDBName("GLY");
@@ -112,7 +112,7 @@ public void testMergeIdentical() {
112112
public void testMergeSequence() throws CompoundNotFoundException {
113113

114114
// Create an Atom Array of ploy-alanine
115-
List<Atom> atoms = new ArrayList<Atom>(100);
115+
List<Atom> atoms = new ArrayList<>(100);
116116
for (int i = 0; i < 100; i++) {
117117
Group g = new AminoAcidImpl();
118118
g.setPDBName("ALA");
@@ -163,7 +163,7 @@ public void testMergeSequence() throws CompoundNotFoundException {
163163
assertEquals(sc1.length(), 100);
164164

165165
// Create an Atom Array of 9 glycine and 91 alanine
166-
List<Atom> atoms3 = new ArrayList<Atom>(100);
166+
List<Atom> atoms3 = new ArrayList<>(100);
167167
for (int i = 0; i < 9; i++) {
168168
Group g = new AminoAcidImpl();
169169
g.setPDBName("GLY");

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL