| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6d8e3e7 commit 2c90336
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ | |||
| 11 | 11 | import java.io.File; | |
| 12 | 12 | import java.io.FileWriter; | |
| 13 | 13 | import java.io.IOException; | |
| 14 | + import java.net.URL; | ||
| 14 | 15 | import java.nio.file.Files; | |
| 15 | 16 | import java.util.Arrays; | |
| 16 | 17 | ||
@@ -40,18 +41,8 @@ public void test1A2C() throws IOException, StructureException { | |||
| 40 | 41 | } | |
| 41 | 42 | ||
| 42 | 43 | private static void testRoundTrip(String pdbId) throws IOException, StructureException { | |
| 43 | - AtomCache cache = new AtomCache(); | ||
| 44 | - | ||
| 45 | - StructureIO.setAtomCache(cache); | ||
| 46 | - | ||
| 47 | - cache.setUseCif(true); | ||
| 48 | - | ||
| 49 | - FileParsingParameters params = new FileParsingParameters(); | ||
| 50 | - params.setAlignSeqRes(true); | ||
| 51 | - cache.setFileParsingParams(params); | ||
| 52 | - | ||
| 53 | - assertTrue(StructureIO.getAtomCache().isUseCif()); | ||
| 54 | - Structure originalStruct = StructureIO.getStructure(pdbId); | ||
| 44 | + Structure originalStruct = CifFileConverter.convert(CifReader.readText(new URL("https://files.rcsb.org/download/" + pdbId | ||
| 45 | + + ".cif").openStream())); | ||
| 55 | 46 | ||
| 56 | 47 | File outputFile = File.createTempFile("biojava_testing_", ".cif"); | |
| 57 | 48 | outputFile.deleteOnExit(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,9 +35,12 @@ | |||
| 35 | 35 | import org.biojava.nbio.structure.cath.CathFactory; | |
| 36 | 36 | import org.biojava.nbio.structure.domain.PDPProvider; | |
| 37 | 37 | import org.biojava.nbio.structure.domain.RemotePDPProvider; | |
| 38 | - import org.biojava.nbio.structure.io.*; | ||
| 38 | + import org.biojava.nbio.structure.io.FileParsingParameters; | ||
| 39 | 39 | import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; | |
| 40 | 40 | import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; | |
| 41 | + import org.biojava.nbio.structure.io.MMCIFFileReader; | ||
| 42 | + import org.biojava.nbio.structure.io.MMTFFileReader; | ||
| 43 | + import org.biojava.nbio.structure.io.PDBFileReader; | ||
| 41 | 44 | import org.biojava.nbio.core.util.FileDownloadUtils; | |
| 42 | 45 | import org.biojava.nbio.structure.quaternary.BiologicalAssemblyBuilder; | |
| 43 | 46 | import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; | |
@@ -93,17 +96,8 @@ public class AtomCache { | |||
| 93 | 96 | ||
| 94 | 97 | private String path; | |
| 95 | 98 | ||
| 96 | - /** | ||
| 97 | - * The format for structure data to use. | ||
| 98 | - */ | ||
| 99 | - private Format format; | ||
| 100 | - enum Format { | ||
| 101 | - PDB, | ||
| 102 | - MMCIF, | ||
| 103 | - MMTF, | ||
| 104 | - CIF, | ||
| 105 | - BCIF | ||
| 106 | - } | ||
| 99 | + private boolean useMmCif; | ||
| 100 | + private boolean useMmtf; | ||
| 107 | 101 | ||
| 108 | 102 | /** | |
| 109 | 103 | * Default AtomCache constructor. | |
@@ -156,7 +150,9 @@ public AtomCache(String pdbFilePath, String cachePath) { | |||
| 156 | 150 | currentlyLoading.clear(); | |
| 157 | 151 | params = new FileParsingParameters(); | |
| 158 | 152 | ||
| 153 | + setUseMmCif(false); | ||
| 159 | 154 | setUseMmtf(true); | |
| 155 | + | ||
| 160 | 156 | } | |
| 161 | 157 | ||
| 162 | 158 | /** | |
@@ -169,10 +165,11 @@ public AtomCache(UserConfiguration config) { | |||
| 169 | 165 | this(config.getPdbFilePath(), config.getCacheFilePath()); | |
| 170 | 166 | fetchBehavior = config.getFetchBehavior(); | |
| 171 | 167 | obsoleteBehavior = config.getObsoleteBehavior(); | |
| 168 | + useMmCif = config.getFileFormat().equals( UserConfiguration.MMCIF_FORMAT ); | ||
| 169 | + | ||
| 170 | + if ( useMmCif) | ||
| 171 | + useMmtf = false; | ||
| 172 | 172 | ||
| 173 | - if (config.getFileFormat().equals(UserConfiguration.MMCIF_FORMAT)) { | ||
| 174 | - format = Format.MMCIF; | ||
| 175 | - } | ||
| 176 | 173 | } | |
| 177 | 174 | ||
| 178 | 175 | /** | |
@@ -300,7 +297,8 @@ public Structure getBiologicalAssembly(String pdbId, int bioAssemblyId, boolean | |||
| 300 | 297 | ||
| 301 | 298 | // if we use mmcif or mmtf, then we need to pass useAsymIds=true | |
| 302 | 299 | boolean useAsymIds = false; | |
| 303 | - if (format != Format.PDB) useAsymIds = true; | ||
| 300 | + if (useMmCif) useAsymIds = true; | ||
| 301 | + if (useMmtf) useAsymIds = true; | ||
| 304 | 302 | return builder.rebuildQuaternaryStructure(asymUnit, transformations, useAsymIds, multiModel); | |
| 305 | 303 | ||
| 306 | 304 | } | |
@@ -358,7 +356,8 @@ public Structure getBiologicalAssembly(String pdbId, boolean multiModel) throws | |||
| 358 | 356 | ||
| 359 | 357 | // if we use mmcif or mmtf, then we need to pass useAsymIds=true | |
| 360 | 358 | boolean useAsymIds = false; | |
| 361 | - if (format != Format.PDB) useAsymIds = true; | ||
| 359 | + if (useMmCif) useAsymIds = true; | ||
| 360 | + if (useMmtf) useAsymIds = true; | ||
| 362 | 361 | return builder.rebuildQuaternaryStructure(asymUnit, transformations, useAsymIds, multiModel); | |
| 363 | 362 | ||
| 364 | 363 | } | |
@@ -410,7 +409,8 @@ public List<Structure> getBiologicalAssemblies(String pdbId, boolean multiModel) | |||
| 410 | 409 | ||
| 411 | 410 | // if we use mmcif or mmtf, then we need to pass useAsymIds=true | |
| 412 | 411 | boolean useAsymIds = false; | |
| 413 | - if (format != Format.PDB) useAsymIds = true; | ||
| 412 | + if (useMmCif) useAsymIds = true; | ||
| 413 | + if (useMmtf) useAsymIds = true; | ||
| 414 | 414 | Structure s = builder.rebuildQuaternaryStructure(asymUnit, transformations, useAsymIds, multiModel); | |
| 415 | 415 | assemblies.add(s); | |
| 416 | 416 | } | |
@@ -606,7 +606,7 @@ public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatab | |||
| 606 | 606 | } | |
| 607 | 607 | } | |
| 608 | 608 | boolean alreadyContains = newChain.getAtomGroups().contains(group); // we don't want to add duplicate | |
| 609 | - // ligands | ||
| 609 | + // ligands | ||
| 610 | 610 | if (shouldContain && !alreadyContains) { | |
| 611 | 611 | ||
| 612 | 612 | newChain.addGroup(group); | |
@@ -772,89 +772,37 @@ public void setPdpprovider(PDPProvider pdpprovider) { | |||
| 772 | 772 | * @return the useMmCif | |
| 773 | 773 | */ | |
| 774 | 774 | public boolean isUseMmCif() { | |
| 775 | - return format == Format.MMCIF; | ||
| 775 | + return useMmCif; | ||
| 776 | 776 | } | |
| 777 | 777 | ||
| 778 | 778 | /** | |
| 779 | 779 | * @param useMmCif | |
| 780 | 780 | * the useMmCif to set | |
| 781 | 781 | */ | |
| 782 | 782 | public void setUseMmCif(boolean useMmCif) { | |
| 783 | - if (useMmCif) { | ||
| 784 | - this.format = Format.MMCIF; | ||
| 785 | - } | ||
| 783 | + this.useMmCif = useMmCif; | ||
| 784 | + // Either way the user wants to use PDB or MMCIF | ||
| 785 | + this.useMmtf = false; | ||
| 786 | 786 | } | |
| 787 | 787 | ||
| 788 | 788 | /** | |
| 789 | 789 | * Set whether to use mmtf. | |
| 790 | 790 | * @param useMmtf the input boolean to set | |
| 791 | 791 | */ | |
| 792 | 792 | public void setUseMmtf(boolean useMmtf) { | |
| 793 | - if (useMmtf) { | ||
| 794 | - this.format = Format.MMTF; | ||
| 793 | + this.useMmtf = useMmtf; | ||
| 794 | + if(useMmtf){ | ||
| 795 | + useMmCif=false; | ||
| 795 | 796 | } | |
| 797 | + | ||
| 796 | 798 | } | |
| 797 | 799 | ||
| 798 | 800 | /** Returns useMmtf flag | |
| 799 | 801 | * | |
| 800 | 802 | * @return true if will load data via mmtf file format | |
| 801 | 803 | */ | |
| 802 | 804 | public boolean isUseMmtf(){ | |
| 803 | - return this.format == Format.MMTF; | ||
| 804 | - } | ||
| 805 | - | ||
| 806 | - /** | ||
| 807 | - * The PDB flag. | ||
| 808 | - * @return true if legacy PDB parsing will be employed | ||
| 809 | - */ | ||
| 810 | - public boolean isUsePdb() { | ||
| 811 | - return this.format == Format.PDB; | ||
| 812 | - } | ||
| 813 | - | ||
| 814 | - /** | ||
| 815 | - * The experimental Bcif flag. | ||
| 816 | - * @return true if experimental Bcif parsing will be employed | ||
| 817 | - */ | ||
| 818 | - public boolean isUseBcif() { | ||
| 819 | - return this.format == Format.BCIF; | ||
| 820 | - } | ||
| 821 | - | ||
| 822 | - /** | ||
| 823 | - * The experimental Cif flag. | ||
| 824 | - * @return true if experimental Cif parsing will be employed | ||
| 825 | - */ | ||
| 826 | - public boolean isUseCif() { | ||
| 827 | - return this.format == Format.CIF; | ||
| 828 | - } | ||
| 829 | - | ||
| 830 | - /** | ||
| 831 | - * Use the experimental Bcif parser to acquire structure data. | ||
| 832 | - * @param useBcif use? | ||
| 833 | - */ | ||
| 834 | - public void setUseBcif(boolean useBcif) { | ||
| 835 | - if (useBcif) { | ||
| 836 | - this.format = Format.BCIF; | ||
| 837 | - } | ||
| 838 | - } | ||
| 839 | - | ||
| 840 | - /** | ||
| 841 | - * Use the experimental Cif parser to acquire structure data. | ||
| 842 | - * @param useCif use? | ||
| 843 | - */ | ||
| 844 | - public void setUseCif(boolean useCif) { | ||
| 845 | - if (useCif) { | ||
| 846 | - this.format = Format.CIF; | ||
| 847 | - } | ||
| 848 | - } | ||
| 849 | - | ||
| 850 | - /** | ||
| 851 | - * Use the legacy PDB format to acquire structure data. | ||
| 852 | - * @param usePdb use? | ||
| 853 | - */ | ||
| 854 | - public void usePdb(boolean usePdb) { | ||
| 855 | - if (usePdb) { | ||
| 856 | - this.format = Format.PDB; | ||
| 857 | - } | ||
| 805 | + return this.useMmtf; | ||
| 858 | 806 | } | |
| 859 | 807 | ||
| 860 | 808 | private boolean checkLoading(String name) { | |
@@ -933,25 +881,19 @@ public Structure getStructureForPdbId(String pdbId) throws IOException, Structur | |||
| 933 | 881 | ||
| 934 | 882 | } | |
| 935 | 883 | ||
| 936 | - switch (format) { | ||
| 937 | - case MMTF: | ||
| 938 | - logger.debug("loading from mmtf"); | ||
| 939 | - return loadStructureFromMmtfByPdbId(pdbId); | ||
| 940 | - case MMCIF: | ||
| 941 | - logger.debug("loading from mmcif"); | ||
| 942 | - return loadStructureFromCifByPdbId(pdbId); | ||
| 943 | - case CIF: | ||
| 944 | - logger.debug("loading from experimental cif"); | ||
| 945 | - return loadStructureFromExperimentalCifByPdbId(pdbId); | ||
| 946 | - case PDB: | ||
| 947 | - logger.debug("loading from pdb"); | ||
| 948 | - return loadStructureFromPdbByPdbId(pdbId); | ||
| 949 | - case BCIF: | ||
| 950 | - logger.debug("loading from bcif"); | ||
| 951 | - return loadStructureFromBcifByPdbId(pdbId); | ||
| 952 | - default: | ||
| 953 | - throw new IllegalArgumentException("no strategy implemented for format " + format); | ||
| 884 | + Structure s; | ||
| 885 | + if (useMmtf) { | ||
| 886 | + logger.debug("loading from mmtf"); | ||
| 887 | + s = loadStructureFromMmtfByPdbId(pdbId); | ||
| 888 | + } | ||
| 889 | + else if (useMmCif) { | ||
| 890 | + logger.debug("loading from mmcif"); | ||
| 891 | + s = loadStructureFromCifByPdbId(pdbId); | ||
| 892 | + } else { | ||
| 893 | + logger.debug("loading from pdb"); | ||
| 894 | + s = loadStructureFromPdbByPdbId(pdbId); | ||
| 954 | 895 | } | |
| 896 | + return s; | ||
| 955 | 897 | } | |
| 956 | 898 | ||
| 957 | 899 | /** | |
@@ -969,22 +911,6 @@ private Structure loadStructureFromMmtfByPdbId(String pdbId) throws IOException | |||
| 969 | 911 | return structure; | |
| 970 | 912 | } | |
| 971 | 913 | ||
| 972 | - private Structure loadStructureFromBcifByPdbId(String pdbId) throws IOException { | ||
| 973 | - logger.debug("Loading structure {} from Bcif file.", pdbId); | ||
| 974 | - BcifFileReader reader = new BcifFileReader(); | ||
| 975 | - reader.setFetchBehavior(fetchBehavior); | ||
| 976 | - reader.setObsoleteBehavior(obsoleteBehavior); | ||
| 977 | - return reader.getStructureById(pdbId.toLowerCase()); | ||
| 978 | - } | ||
| 979 | - | ||
| 980 | - private Structure loadStructureFromExperimentalCifByPdbId(String pdbId) throws IOException { | ||
| 981 | - logger.debug("Loading structure {} experimentally from Cif file.", pdbId); | ||
| 982 | - CifFileReader reader = new CifFileReader(); | ||
| 983 | - reader.setFetchBehavior(fetchBehavior); | ||
| 984 | - reader.setObsoleteBehavior(obsoleteBehavior); | ||
| 985 | - return reader.getStructureById(pdbId.toLowerCase()); | ||
| 986 | - } | ||
| 987 | - | ||
| 988 | 914 | protected Structure loadStructureFromCifByPdbId(String pdbId) throws IOException, StructureException { | |
| 989 | 915 | ||
| 990 | 916 | logger.debug("Loading structure {} from mmCIF file {}.", pdbId, path); | |
@@ -1025,4 +951,4 @@ protected Structure loadStructureFromPdbByPdbId(String pdbId) throws IOException | |||
| 1025 | 951 | return s; | |
| 1026 | 952 | } | |
| 1027 | 953 | ||
| 1028 | - } | ||
| 954 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments