Search in sources :

Example 36 with Structure

use of de.bioforscher.jstructure.model.structure.Structure in project jstructure by JonStargaryen.

the class AccessibleSurfaceAreaCalculatorTest method getJStructureASA.

private static List<Double> getJStructureASA(String id) {
    // load structure
    Structure protein = StructureParser.fromPdbId(id).parse();
    // assign states
    new AccessibleSurfaceAreaCalculator().process(protein);
    // return complete DSSP annotation string from jstructrue
    return protein.aminoAcids().map(residue -> residue.getFeature(AccessibleSurfaceArea.class).getAccessibleSurfaceArea()).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) AsaCalculator(org.biojava.nbio.structure.asa.AsaCalculator) Structure(de.bioforscher.jstructure.model.structure.Structure) Test(org.junit.Test) IOException(java.io.IOException) StructureParser(de.bioforscher.jstructure.model.structure.StructureParser) Collectors(java.util.stream.Collectors) GroupAsa(org.biojava.nbio.structure.asa.GroupAsa) StructureException(org.biojava.nbio.structure.StructureException) List(java.util.List) SetOperations(de.bioforscher.jstructure.mathematics.SetOperations) Assert(org.junit.Assert) PDBFileReader(org.biojava.nbio.structure.io.PDBFileReader) Structure(de.bioforscher.jstructure.model.structure.Structure)

Example 37 with Structure

use of de.bioforscher.jstructure.model.structure.Structure in project jstructure by JonStargaryen.

the class Demo method test.

@Test
public void test() {
    // fetch a structure or load from local PDB if setup
    Structure structure = StructureParser.fromPdbId("1brr").parse();
    // select a chain
    Chain chainB = structure.select().chainId("B").asChain();
    // or a residue
    AminoAcid aminoAcid1 = chainB.select().residueNumber(60).asAminoAcid();
    // and another one
    AminoAcid aminoAcid2 = chainB.select().residueNumber(100).asAminoAcid();
    // compute their distance
    System.out.println("distance of " + aminoAcid1 + " and " + aminoAcid2 + ": " + StandardFormat.format(aminoAcid1.calculate().centroid().distance(aminoAcid2.calculate().centroid())));
    // access amino acid-specific atoms
    chainB.select().aminoAcids().groupName("TRP").asFilteredGroups().map(Tryptophan.class::cast).map(tryptophan -> tryptophan + " CG position: " + Arrays.toString(tryptophan.getCg().getCoordinates())).forEach(System.out::println);
    // compute features on-the-fly and resolve dependencies
    // e.g. assign some random value to each amino acid
    structure.aminoAcids().forEach(aminoAcid -> aminoAcid.getFeatureContainer().addFeature(new Feature(new Random().nextDouble())));
    chainB.aminoAcids().map(aminoAcid -> aminoAcid + " random feature: " + StandardFormat.format(aminoAcid.getFeature(Feature.class).getValue())).forEach(System.out::println);
    System.out.println("averages among chains:");
    structure.chainsWithAminoAcids().map(chain -> chain.getChainIdentifier() + "'s average random feature: " + StandardFormat.format(chain.aminoAcids().map(aminoAcid -> aminoAcid.getFeature(Feature.class)).mapToDouble(Feature::getValue).average().getAsDouble())).forEach(System.out::println);
}
Also used : Tryptophan(de.bioforscher.jstructure.model.structure.aminoacid.Tryptophan) Arrays(java.util.Arrays) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) Structure(de.bioforscher.jstructure.model.structure.Structure) Test(org.junit.Test) Random(java.util.Random) FeatureContainerEntry(de.bioforscher.jstructure.model.feature.FeatureContainerEntry) StructureParser(de.bioforscher.jstructure.model.structure.StructureParser) Chain(de.bioforscher.jstructure.model.structure.Chain) Random(java.util.Random) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Tryptophan(de.bioforscher.jstructure.model.structure.aminoacid.Tryptophan) Structure(de.bioforscher.jstructure.model.structure.Structure) Test(org.junit.Test)

Example 38 with Structure

use of de.bioforscher.jstructure.model.structure.Structure in project jstructure by JonStargaryen.

the class S01_CreateEarlyFoldingDatabase method main.

public static void main(String[] args) {
    StringJoiner efoldmineScript = new StringJoiner(System.lineSeparator());
    List<String> lines = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("nrpdb.list"))).lines().collect(Collectors.toList());
    Structure lastStructure = null;
    String lastPdbId = null;
    for (String line : lines) {
        String[] split = line.split("\t");
        String pdbId = split[0];
        String chainId = split[1];
        String id = pdbId + "_" + chainId;
        System.out.println(id);
        try {
            Structure structure;
            if (pdbId.equals(lastPdbId)) {
                structure = lastStructure;
            } else {
                structure = StructureParser.fromPdbId(pdbId).parse();
            }
            Chain chain = structure.select().chainId(chainId).asChain();
            String sequence = chain.getAminoAcidSequence();
            FileUtils.write(BASE_DIR.resolve("sequences").resolve(id + ".fasta"), ">" + id + System.lineSeparator() + sequence);
            efoldmineScript.add("python2 EFoldMine.py pdb-motifs/sequences/" + id + ".fasta -o pdb-motifs/ef-predictions/" + id + ".out");
            lastPdbId = pdbId;
            lastStructure = structure;
        } catch (Exception e) {
            System.err.println("could not process: " + line);
            e.printStackTrace();
        }
    }
    FileUtils.write(BASE_DIR.getParent().resolve("efoldmine-pdb-motifs.sh"), efoldmineScript.toString());
}
Also used : Chain(de.bioforscher.jstructure.model.structure.Chain) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Structure(de.bioforscher.jstructure.model.structure.Structure) StringJoiner(java.util.StringJoiner)

Example 39 with Structure

use of de.bioforscher.jstructure.model.structure.Structure in project jstructure by JonStargaryen.

the class S02_ExtractEarlyFoldingMotifs method main.

public static void main(String[] args) {
    FileUtils.list(Paths.get("/home/bittrich/git/phd_sb_repo/data/aars/EFoldMine_code/pdb-motifs/ef-predictions/")).parallel().forEach(earlyFoldingPredictionPath -> {
        String id = earlyFoldingPredictionPath.toFile().getName().split("\\.")[0];
        System.out.println(id);
        Path motifPath = earlyFoldingPredictionPath.getParent().getParent().resolve("motifs").resolve(id + ".pdb");
        String[] split = id.split("_");
        String pdbId = split[0];
        String chainId = split[1];
        try {
            Structure structure = StructureParser.fromPdbId(pdbId).parse();
            Chain chain = structure.select().chainId(chainId).asChain();
            List<AminoAcid> aminoAcids = chain.getAminoAcids();
            List<String> earlyFoldingPredictionLines = Files.readAllLines(earlyFoldingPredictionPath);
            List<Double> earlyFoldingPredictions = earlyFoldingPredictionLines.stream().skip(1).filter(line -> !line.startsWith("*")).map(line -> line.split("\\s+")[1]).map(Double::valueOf).collect(Collectors.toList());
            if (aminoAcids.size() != earlyFoldingPredictions.size()) {
                System.err.println("erroneous data for " + id);
                return;
            }
            StringJoiner output = new StringJoiner(System.lineSeparator());
            output.add(structure.getHeader());
            List<AminoAcid> earlyFoldingResidues = new ArrayList<>();
            for (int i = 0; i < aminoAcids.size(); i++) {
                if (earlyFoldingPredictions.get(i) > CUTOFF) {
                    continue;
                }
                // is predicted as early folding
                earlyFoldingResidues.add(aminoAcids.get(i));
            }
            Structure earlyFoldingStructure = earlyFoldingResidues.stream().collect(StructureCollectors.toIsolatedStructure());
            FileUtils.write(motifPath, earlyFoldingStructure.getPdbRepresentation());
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
}
Also used : Path(java.nio.file.Path) FileUtils(de.bioforscher.testutil.FileUtils) Files(java.nio.file.Files) Structure(de.bioforscher.jstructure.model.structure.Structure) StructureCollectors(de.bioforscher.jstructure.model.structure.StructureCollectors) IOException(java.io.IOException) StructureParser(de.bioforscher.jstructure.model.structure.StructureParser) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Paths(java.nio.file.Paths) StringJoiner(java.util.StringJoiner) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) Path(java.nio.file.Path) Chain(de.bioforscher.jstructure.model.structure.Chain) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Structure(de.bioforscher.jstructure.model.structure.Structure) StringJoiner(java.util.StringJoiner)

Example 40 with Structure

use of de.bioforscher.jstructure.model.structure.Structure in project jstructure by JonStargaryen.

the class S03_CreateSaneNrPdbList method filterValidChains.

private static boolean filterValidChains(Path path) {
    System.out.println("processing " + path);
    Structure structure = StructureParser.fromPath(path).parse();
    return structure.getGroups().size() > 1;
}
Also used : Structure(de.bioforscher.jstructure.model.structure.Structure)

Aggregations

Structure (de.bioforscher.jstructure.model.structure.Structure)61 IOException (java.io.IOException)45 Collectors (java.util.stream.Collectors)40 Chain (de.bioforscher.jstructure.model.structure.Chain)39 Files (java.nio.file.Files)35 StructureParser (de.bioforscher.jstructure.model.structure.StructureParser)30 Path (java.nio.file.Path)26 AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)23 List (java.util.List)22 StandardFormat (de.bioforscher.jstructure.StandardFormat)21 Logger (org.slf4j.Logger)20 LoggerFactory (org.slf4j.LoggerFactory)20 Test (org.junit.Test)19 Group (de.bioforscher.jstructure.model.structure.Group)18 UncheckedIOException (java.io.UncheckedIOException)18 Pattern (java.util.regex.Pattern)17 Stream (java.util.stream.Stream)17 Jsoup (org.jsoup.Jsoup)17 ComputationException (de.bioforscher.jstructure.model.feature.ComputationException)16 java.util (java.util)15