| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,9 +55,9 @@ public void gapPenalty52() { | |||
| 55 | 55 | Profile<DNASequence, NucleotideCompound> msa = Alignments | |
| 56 | 56 | .getMultipleSequenceAlignment(sequences, gapP); | |
| 57 | 57 | ||
| 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(), | ||
| 61 | 61 | msa.toString()); | |
| 62 | 62 | ||
| 63 | 63 | ConcurrencyTools.shutdown(); | |
@@ -71,9 +71,9 @@ public void gapPenaltyDefault() { | |||
| 71 | 71 | .getMultipleSequenceAlignment(sequences, gapP); | |
| 72 | 72 | ||
| 73 | 73 | // 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(), | ||
| 77 | 77 | msa.toString()); | |
| 78 | 78 | ||
| 79 | 79 | ConcurrencyTools.shutdown(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,8 +72,8 @@ public void testMSAconversion() throws Exception { | |||
| 72 | 72 | String expected = ""; | |
| 73 | 73 | for (ProteinSequence proteinSequence : proteinSequences.values()) { | |
| 74 | 74 | msa.addAlignedSequence(proteinSequence); | |
| 75 | - expected += ">" + proteinSequence.getOriginalHeader() + "\n" | ||
| 76 | - + proteinSequence.toString() + "\n"; | ||
| 75 | + expected += ">" + proteinSequence.getOriginalHeader() + System.lineSeparator() | ||
| 76 | + + proteinSequence.toString() + System.lineSeparator(); | ||
| 77 | 77 | } | |
| 78 | 78 | ||
| 79 | 79 | // Convert the biojava MSA to a FASTA String | |
@@ -95,8 +95,8 @@ public String getHeader(ProteinSequence sequence) { | |||
| 95 | 95 | ||
| 96 | 96 | StringBuilder sb = new StringBuilder(); | |
| 97 | 97 | 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()); | ||
| 100 | 100 | } | |
| 101 | 101 | String forester = sb.toString(); | |
| 102 | 102 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,8 @@ | |||
| 23 | 23 | */ | |
| 24 | 24 | package org.biojava.nbio.structure; | |
| 25 | 25 | ||
| 26 | + import java.util.List; | ||
| 27 | + | ||
| 26 | 28 | /** | |
| 27 | 29 | * AminoAcid inherits most from Hetatom. Adds a few AminoAcid | |
| 28 | 30 | * specific methods. | |
@@ -173,6 +175,20 @@ public Object clone() { | |||
| 173 | 175 | n.addAtom(atom); | |
| 174 | 176 | atom.setGroup(n); | |
| 175 | 177 | } | |
| 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 | + } | ||
| 176 | 192 | ||
| 177 | 193 | // copying the alt loc groups if present, otherwise they stay null | |
| 178 | 194 | if (getAltLocs()!=null && !getAltLocs().isEmpty()) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -459,7 +459,21 @@ public Object clone() { | |||
| 459 | 459 | n.addAtom(atom); | |
| 460 | 460 | atom.setGroup(n); | |
| 461 | 461 | } | |
| 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 | + | ||
| 463 | 477 | // copying the alt loc groups if present, otherwise they stay null | |
| 464 | 478 | if (altLocs!=null) { | |
| 465 | 479 | for (Group altLocGroup:this.altLocs) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,8 @@ | |||
| 23 | 23 | */ | |
| 24 | 24 | package org.biojava.nbio.structure; | |
| 25 | 25 | ||
| 26 | + import java.util.List; | ||
| 27 | + | ||
| 26 | 28 | /** | |
| 27 | 29 | * A nucleotide group is almost the same as a Hetatm group. | |
| 28 | 30 | * @see HetatomImpl | |
@@ -107,7 +109,21 @@ public Object clone() { | |||
| 107 | 109 | n.addAtom(atom); | |
| 108 | 110 | atom.setGroup(n); | |
| 109 | 111 | } | |
| 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 | + | ||
| 111 | 127 | // copying the alt loc groups if present, otherwise they stay null | |
| 112 | 128 | if (getAltLocs()!=null && !getAltLocs().isEmpty()) { | |
| 113 | 129 | for (Group altLocGroup:this.getAltLocs()) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,14 +24,17 @@ | |||
| 24 | 24 | */ | |
| 25 | 25 | package org.biojava.nbio.structure; | |
| 26 | 26 | ||
| 27 | + import static org.junit.Assert.assertEquals; | ||
| 28 | + import static org.junit.Assert.assertNotEquals; | ||
| 29 | + import static org.junit.Assert.assertNotNull; | ||
| 27 | 30 | ||
| 28 | 31 | import java.io.IOException; | |
| 29 | 32 | import java.util.Iterator; | |
| 33 | + import java.util.List; | ||
| 30 | 34 | ||
| 31 | 35 | import org.biojava.nbio.structure.align.util.AtomCache; | |
| 32 | 36 | import org.biojava.nbio.structure.io.FileParsingParameters; | |
| 33 | 37 | import org.junit.Test; | |
| 34 | - import static org.junit.Assert.*; | ||
| 35 | 38 | ||
| 36 | 39 | public class TestCloning { | |
| 37 | 40 | ||
@@ -40,111 +43,134 @@ public void test1a4wCloning() throws StructureException, IOException { | |||
| 40 | 43 | ||
| 41 | 44 | Structure s; | |
| 42 | 45 | ||
| 43 | - AtomCache cache = new AtomCache(); | ||
| 44 | - FileParsingParameters params = new FileParsingParameters(); | ||
| 46 | + final AtomCache cache = new AtomCache(); | ||
| 47 | + final FileParsingParameters params = new FileParsingParameters(); | ||
| 45 | 48 | params.setAlignSeqRes(true); | |
| 46 | 49 | cache.setFileParsingParams(params); | |
| 47 | 50 | ||
| 48 | 51 | StructureIO.setAtomCache(cache); | |
| 49 | 52 | ||
| 50 | 53 | s = StructureIO.getStructure("1a4w"); | |
| 51 | 54 | ||
| 52 | - Structure c = s.clone(); | ||
| 55 | + final Structure c = s.clone(); | ||
| 53 | 56 | ||
| 54 | - compareCloned(s,c); | ||
| 57 | + compareCloned(s, c); | ||
| 55 | 58 | ||
| 56 | 59 | } | |
| 57 | 60 | ||
| 58 | - | ||
| 59 | - | ||
| 60 | 61 | @Test | |
| 61 | 62 | public void testAsymUnitCloning() throws StructureException, IOException { | |
| 62 | 63 | ||
| 63 | 64 | Structure s; | |
| 64 | 65 | ||
| 65 | - | ||
| 66 | - AtomCache cache = new AtomCache(); | ||
| 67 | - FileParsingParameters params = new FileParsingParameters(); | ||
| 66 | + final AtomCache cache = new AtomCache(); | ||
| 67 | + final FileParsingParameters params = new FileParsingParameters(); | ||
| 68 | 68 | params.setAlignSeqRes(false); | |
| 69 | 69 | cache.setFileParsingParams(params); | |
| 70 | 70 | ||
| 71 | 71 | StructureIO.setAtomCache(cache); | |
| 72 | 72 | ||
| 73 | 73 | s = StructureIO.getStructure("1stp"); | |
| 74 | 74 | ||
| 75 | - Structure c = s.clone(); | ||
| 75 | + final Structure c = s.clone(); | ||
| 76 | 76 | ||
| 77 | - compareCloned(s,c); | ||
| 77 | + compareCloned(s, c); | ||
| 78 | 78 | } | |
| 79 | 79 | ||
| 80 | 80 | @Test | |
| 81 | 81 | public void testBioUnitCloning() throws StructureException, IOException { | |
| 82 | 82 | ||
| 83 | 83 | Structure s; | |
| 84 | - s = StructureIO.getBiologicalAssembly("1stp",1); | ||
| 84 | + s = StructureIO.getBiologicalAssembly("1stp", 1); | ||
| 85 | 85 | ||
| 86 | - Structure c = s.clone(); | ||
| 86 | + final Structure c = s.clone(); | ||
| 87 | 87 | ||
| 88 | - compareCloned(s,c); | ||
| 88 | + compareCloned(s, c); | ||
| 89 | 89 | ||
| 90 | 90 | } | |
| 91 | 91 | ||
| 92 | 92 | /** | |
| 93 | 93 | * A Structure with alt locs, we make sure they are being cloned too | |
| 94 | + * | ||
| 94 | 95 | * @throws StructureException | |
| 95 | 96 | * @throws IOException | |
| 96 | 97 | */ | |
| 97 | 98 | @Test | |
| 98 | 99 | public void test3piuCloning() throws StructureException, IOException { | |
| 99 | 100 | ||
| 100 | - AtomCache cache = new AtomCache(); | ||
| 101 | - FileParsingParameters params = new FileParsingParameters(); | ||
| 101 | + final AtomCache cache = new AtomCache(); | ||
| 102 | + final FileParsingParameters params = new FileParsingParameters(); | ||
| 102 | 103 | params.setAlignSeqRes(true); | |
| 103 | 104 | cache.setFileParsingParams(params); | |
| 104 | 105 | ||
| 105 | 106 | StructureIO.setAtomCache(cache); | |
| 106 | 107 | ||
| 107 | - Structure s = StructureIO.getStructure("3piu"); | ||
| 108 | + final Structure s = StructureIO.getStructure("3piu"); | ||
| 108 | 109 | ||
| 109 | - Structure c = s.clone(); | ||
| 110 | + final Structure c = s.clone(); | ||
| 110 | 111 | ||
| 111 | 112 | compareCloned(s, c); | |
| 112 | 113 | } | |
| 113 | 114 | ||
| 114 | - private void compareCloned(Structure s, Structure c) throws StructureException { | ||
| 115 | + private void compareCloned(final Structure s, final Structure c) throws StructureException { | ||
| 115 | 116 | ||
| 116 | 117 | assertEquals(s.getChains().size(), c.getChains().size()); | |
| 117 | 118 | ||
| 118 | - for ( Chain chain : s.getChains()) { | ||
| 119 | + for (final Chain chain : s.getChains()) { | ||
| 119 | 120 | ||
| 120 | - Chain test = c.getChain(chain.getId()); | ||
| 121 | + final Chain test = c.getChain(chain.getId()); | ||
| 121 | 122 | ||
| 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()); | ||
| 123 | 125 | ||
| 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()); | ||
| 125 | 128 | ||
| 126 | 129 | 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 | + // } | ||
| 132 | 135 | assertEquals(g.getAltLocs().size(), testGroup.getAltLocs().size()); | |
| 133 | 136 | } | |
| 134 | - | ||
| 137 | + | ||
| 135 | 138 | 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(); | ||
| 138 | 141 | assertEquals(g.getAltLocs().size(), testGroup.getAltLocs().size()); | |
| 139 | 142 | } | |
| 140 | 143 | } | |
| 141 | 144 | ||
| 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); | ||
| 143 | 162 | ||
| 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); | ||
| 145 | 166 | ||
| 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); | ||
| 147 | 170 | ||
| 171 | + assertEquals(bonds.toString(), bonds2.toString()); | ||
| 172 | + // But the objects should be different as the atoms are clones | ||
| 173 | + assertNotEquals(bonds.toArray(), bonds2.toArray()); | ||
| 148 | 174 | } | |
| 149 | 175 | ||
| 150 | 176 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments