Skip to content

Commit 15808d6

Browse files
Merge branch 'issue712'
2 parents f679dbd + 622c38f commit 15808d6

File tree

6 files changed

+119
-47
lines changed

6 files changed

+119
-47
lines changed

biojava-alignment/src/test/java/org/biojava/nbio/alignment/TestSubOptimalMSA.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public void gapPenalty52() {
5555
Profile<DNASequence, NucleotideCompound> msa = Alignments
5656
.getMultipleSequenceAlignment(sequences, gapP);
5757

58-
assertEquals("TTGGGGCCTCTAAACGGGGTCTT\n"
59-
+ "TTGGGGCCTCTAAACGGG-TCTT\n"
60-
+ "TTGGGGC-TCTAA-CGGG-TCTT\n",
58+
assertEquals("TTGGGGCCTCTAAACGGGGTCTT" + System.lineSeparator()
59+
+ "TTGGGGCCTCTAAACGGG-TCTT" + System.lineSeparator()
60+
+ "TTGGGGC-TCTAA-CGGG-TCTT" + System.lineSeparator(),
6161
msa.toString());
6262

6363
ConcurrencyTools.shutdown();
@@ -71,9 +71,9 @@ public void gapPenaltyDefault() {
7171
.getMultipleSequenceAlignment(sequences, gapP);
7272

7373
// TODO test not passing (see issue 288 in github) - Aleix 03.2016
74-
assertEquals("TTGGGGCCTCTAAACGGGGTCTT\n"
75-
+ "TTGGGGCCTCTAAACGGG-TCTT\n"
76-
+ "TTGGGGC-TCTAA-CGGG-TCTT\n",
74+
assertEquals("TTGGGGCCTCTAAACGGGGTCTT" + System.lineSeparator()
75+
+ "TTGGGGCCTCTAAACGGG-TCTT" + System.lineSeparator()
76+
+ "TTGGGGC-TCTAA-CGGG-TCTT" + System.lineSeparator(),
7777
msa.toString());
7878

7979
ConcurrencyTools.shutdown();

biojava-alignment/src/test/java/org/biojava/nbio/phylo/TestForesterWrapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public void testMSAconversion() throws Exception {
7272
String expected = "";
7373
for (ProteinSequence proteinSequence : proteinSequences.values()) {
7474
msa.addAlignedSequence(proteinSequence);
75-
expected += ">" + proteinSequence.getOriginalHeader() + "\n"
76-
+ proteinSequence.toString() + "\n";
75+
expected += ">" + proteinSequence.getOriginalHeader() + System.lineSeparator()
76+
+ proteinSequence.toString() + System.lineSeparator();
7777
}
7878

7979
// Convert the biojava MSA to a FASTA String
@@ -95,8 +95,8 @@ public String getHeader(ProteinSequence sequence) {
9595

9696
StringBuilder sb = new StringBuilder();
9797
for (int i = 0; i < fMsa.getNumberOfSequences(); i++) {
98-
sb.append(">" + fMsa.getIdentifier(i) + "\n");
99-
sb.append(fMsa.getSequenceAsString(i) + "\n");
98+
sb.append(">" + fMsa.getIdentifier(i) + System.lineSeparator());
99+
sb.append(fMsa.getSequenceAsString(i) + System.lineSeparator());
100100
}
101101
String forester = sb.toString();
102102

biojava-structure/src/main/java/org/biojava/nbio/structure/AminoAcidImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
package org.biojava.nbio.structure;
2525

26+
import java.util.List;
27+
2628
/**
2729
* AminoAcid inherits most from Hetatom. Adds a few AminoAcid
2830
* specific methods.
@@ -173,6 +175,20 @@ public Object clone() {
173175
n.addAtom(atom);
174176
atom.setGroup(n);
175177
}
178+
//copy the bonds.
179+
for (int i=0;i<atoms.size();i++) {
180+
Atom atom1 = atoms.get(i);
181+
List<Bond> bonds1 = atom1.getBonds();
182+
if (bonds1 != null) {
183+
for (Bond b : bonds1) {
184+
int atomAIndex = atoms.indexOf(b.getAtomA());
185+
int atomBIndex = atoms.indexOf(b.getAtomB());
186+
// The order of the atoms are the same on the original and the cloned object, which we use here.
187+
Bond newBond = new BondImpl(n.getAtom(atomAIndex), n.getAtom(atomBIndex), b.getBondOrder(), false);
188+
n.getAtom(i).addBond(newBond);
189+
}
190+
}
191+
}
176192

177193
// copying the alt loc groups if present, otherwise they stay null
178194
if (getAltLocs()!=null && !getAltLocs().isEmpty()) {

biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,21 @@ public Object clone() {
459459
n.addAtom(atom);
460460
atom.setGroup(n);
461461
}
462-
462+
//copy the bonds.
463+
for (int i=0;i<atoms.size();i++) {
464+
Atom atom1 = atoms.get(i);
465+
List<Bond> bonds1 = atom1.getBonds();
466+
if (bonds1 != null) {
467+
for (Bond b : bonds1) {
468+
int atomAIndex = atoms.indexOf(b.getAtomA());
469+
int atomBIndex = atoms.indexOf(b.getAtomB());
470+
// The order of the atoms are the same on the original and the cloned object, which we use here.
471+
Bond newBond = new BondImpl(n.getAtom(atomAIndex), n.getAtom(atomBIndex), b.getBondOrder(), false);
472+
n.getAtom(i).addBond(newBond);
473+
}
474+
}
475+
}
476+
463477
// copying the alt loc groups if present, otherwise they stay null
464478
if (altLocs!=null) {
465479
for (Group altLocGroup:this.altLocs) {

biojava-structure/src/main/java/org/biojava/nbio/structure/NucleotideImpl.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
package org.biojava.nbio.structure;
2525

26+
import java.util.List;
27+
2628
/**
2729
* A nucleotide group is almost the same as a Hetatm group.
2830
* @see HetatomImpl
@@ -107,7 +109,21 @@ public Object clone() {
107109
n.addAtom(atom);
108110
atom.setGroup(n);
109111
}
110-
112+
//copy the bonds.
113+
for (int i=0;i<atoms.size();i++) {
114+
Atom atom1 = atoms.get(i);
115+
List<Bond> bonds1 = atom1.getBonds();
116+
if (bonds1 != null) {
117+
for (Bond b : bonds1) {
118+
int atomAIndex = atoms.indexOf(b.getAtomA());
119+
int atomBIndex = atoms.indexOf(b.getAtomB());
120+
// The order of the atoms are the same on the original and the cloned object, which we use here.
121+
Bond newBond = new BondImpl(n.getAtom(atomAIndex), n.getAtom(atomBIndex), b.getBondOrder(), false);
122+
n.getAtom(i).addBond(newBond);
123+
}
124+
}
125+
}
126+
111127
// copying the alt loc groups if present, otherwise they stay null
112128
if (getAltLocs()!=null && !getAltLocs().isEmpty()) {
113129
for (Group altLocGroup:this.getAltLocs()) {

biojava-structure/src/test/java/org/biojava/nbio/structure/TestCloning.java

Lines changed: 61 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@
2424
*/
2525
package org.biojava.nbio.structure;
2626

27+
import static org.junit.Assert.assertEquals;
28+
import static org.junit.Assert.assertNotEquals;
29+
import static org.junit.Assert.assertNotNull;
2730

2831
import java.io.IOException;
2932
import java.util.Iterator;
33+
import java.util.List;
3034

3135
import org.biojava.nbio.structure.align.util.AtomCache;
3236
import org.biojava.nbio.structure.io.FileParsingParameters;
3337
import org.junit.Test;
34-
import static org.junit.Assert.*;
3538

3639
public class TestCloning {
3740

@@ -40,111 +43,134 @@ public void test1a4wCloning() throws StructureException, IOException {
4043

4144
Structure s;
4245

43-
AtomCache cache = new AtomCache();
44-
FileParsingParameters params = new FileParsingParameters();
46+
final AtomCache cache = new AtomCache();
47+
final FileParsingParameters params = new FileParsingParameters();
4548
params.setAlignSeqRes(true);
4649
cache.setFileParsingParams(params);
4750

4851
StructureIO.setAtomCache(cache);
4952

5053
s = StructureIO.getStructure("1a4w");
5154

52-
Structure c = s.clone();
55+
final Structure c = s.clone();
5356

54-
compareCloned(s,c);
57+
compareCloned(s, c);
5558

5659
}
5760

58-
59-
6061
@Test
6162
public void testAsymUnitCloning() throws StructureException, IOException {
6263

6364
Structure s;
6465

65-
66-
AtomCache cache = new AtomCache();
67-
FileParsingParameters params = new FileParsingParameters();
66+
final AtomCache cache = new AtomCache();
67+
final FileParsingParameters params = new FileParsingParameters();
6868
params.setAlignSeqRes(false);
6969
cache.setFileParsingParams(params);
7070

7171
StructureIO.setAtomCache(cache);
7272

7373
s = StructureIO.getStructure("1stp");
7474

75-
Structure c = s.clone();
75+
final Structure c = s.clone();
7676

77-
compareCloned(s,c);
77+
compareCloned(s, c);
7878
}
7979

8080
@Test
8181
public void testBioUnitCloning() throws StructureException, IOException {
8282

8383
Structure s;
84-
s = StructureIO.getBiologicalAssembly("1stp",1);
84+
s = StructureIO.getBiologicalAssembly("1stp", 1);
8585

86-
Structure c = s.clone();
86+
final Structure c = s.clone();
8787

88-
compareCloned(s,c);
88+
compareCloned(s, c);
8989

9090
}
9191

9292
/**
9393
* A Structure with alt locs, we make sure they are being cloned too
94+
*
9495
* @throws StructureException
9596
* @throws IOException
9697
*/
9798
@Test
9899
public void test3piuCloning() throws StructureException, IOException {
99100

100-
AtomCache cache = new AtomCache();
101-
FileParsingParameters params = new FileParsingParameters();
101+
final AtomCache cache = new AtomCache();
102+
final FileParsingParameters params = new FileParsingParameters();
102103
params.setAlignSeqRes(true);
103104
cache.setFileParsingParams(params);
104105

105106
StructureIO.setAtomCache(cache);
106107

107-
Structure s = StructureIO.getStructure("3piu");
108+
final Structure s = StructureIO.getStructure("3piu");
108109

109-
Structure c = s.clone();
110+
final Structure c = s.clone();
110111

111112
compareCloned(s, c);
112113
}
113114

114-
private void compareCloned(Structure s, Structure c) throws StructureException {
115+
private void compareCloned(final Structure s, final Structure c) throws StructureException {
115116

116117
assertEquals(s.getChains().size(), c.getChains().size());
117118

118-
for ( Chain chain : s.getChains()) {
119+
for (final Chain chain : s.getChains()) {
119120

120-
Chain test = c.getChain(chain.getId());
121+
final Chain test = c.getChain(chain.getId());
121122

122-
assertEquals("Could not correctly clone seqres for chain " + chain.getId() , chain.getSeqResLength(),test.getSeqResLength());
123+
assertEquals("Could not correctly clone seqres for chain " + chain.getId(), chain.getSeqResLength(),
124+
test.getSeqResLength());
123125

124-
assertEquals("Could not correctly clone atom records for chain " + chain.getId() , chain.getAtomLength(),test.getAtomLength());
126+
assertEquals("Could not correctly clone atom records for chain " + chain.getId(), chain.getAtomLength(),
127+
test.getAtomLength());
125128

126129
Iterator<Group> it = test.getAtomGroups().iterator();
127-
for (Group g : chain.getAtomGroups()) {
128-
Group testGroup = it.next();
129-
//if (g.hasAltLoc()) {
130-
// System.out.println(g.toString());
131-
//}
130+
for (final Group g : chain.getAtomGroups()) {
131+
final Group testGroup = it.next();
132+
// if (g.hasAltLoc()) {
133+
// System.out.println(g.toString());
134+
// }
132135
assertEquals(g.getAltLocs().size(), testGroup.getAltLocs().size());
133136
}
134-
137+
135138
it = test.getSeqResGroups().iterator();
136-
for (Group g: chain.getSeqResGroups()) {
137-
Group testGroup = it.next();
139+
for (final Group g : chain.getSeqResGroups()) {
140+
final Group testGroup = it.next();
138141
assertEquals(g.getAltLocs().size(), testGroup.getAltLocs().size());
139142
}
140143
}
141144

142-
Atom[] allAtoms = StructureTools.getAllAtomArray(s);
145+
final Atom[] allAtoms = StructureTools.getAllAtomArray(s);
146+
147+
final Atom[] allAtomsCloned = StructureTools.getAllAtomArray(c);
148+
149+
assertEquals(allAtoms.length, allAtomsCloned.length);
150+
151+
}
152+
153+
@Test
154+
public void testBondCloning() throws IOException, StructureException {
155+
156+
final AtomCache cache = new AtomCache();
157+
cache.setUseMmCif(true);
158+
159+
final FileParsingParameters params = cache.getFileParsingParams();
160+
params.setCreateAtomBonds(true);
161+
cache.setFileParsingParams(params);
143162

144-
Atom[] allAtomsCloned = StructureTools.getAllAtomArray(c);
163+
final Structure s = cache.getStructure("2I13");
164+
final List<Bond> bonds = s.getNonPolyChain("G").getAtomGroup(0).getAtom(0).getBonds();
165+
assertNotNull(bonds);
145166

146-
assertEquals(allAtoms.length,allAtomsCloned.length);
167+
final Structure s2 = s.clone();
168+
final List<Bond> bonds2 = s2.getNonPolyChain("G").getAtomGroup(0).getAtom(0).getBonds();
169+
assertNotNull(bonds2);
147170

171+
assertEquals(bonds.toString(), bonds2.toString());
172+
// But the objects should be different as the atoms are clones
173+
assertNotEquals(bonds.toArray(), bonds2.toArray());
148174
}
149175

150176
}

0 commit comments

Comments
 (0)