Search in sources :

Example 6 with Path

use of net.minecraft.server.v1_15_R1.Path in project dishevelled-bio by heuermh.

the class TraversePaths method call.

@Override
public Integer call() throws Exception {
    BufferedReader reader = null;
    PrintWriter writer = null;
    try {
        reader = reader(inputGfa1File);
        writer = writer(outputGfa1File);
        final PrintWriter w = writer;
        Gfa1Reader.stream(reader, new Gfa1Listener() {

            @Override
            public boolean record(final Gfa1Record gfa1Record) {
                Gfa1Writer.write(gfa1Record, w);
                if (gfa1Record instanceof Path) {
                    Path path = (Path) gfa1Record;
                    int size = path.getSegments().size();
                    Reference source = null;
                    Reference target = null;
                    String overlap = null;
                    for (int i = 0; i < size; i++) {
                        target = path.getSegments().get(i);
                        if (i > 0) {
                            overlap = (path.getOverlaps() != null && path.getOverlaps().size() > i) ? path.getOverlaps().get(i - 1) : null;
                        }
                        if (source != null) {
                            Traversal traversal = new Traversal(path.getName(), i - 1, source, target, overlap, EMPTY_ANNOTATIONS);
                            Gfa1Writer.write(traversal, w);
                        }
                        source = target;
                    }
                }
                return true;
            }
        });
        return 0;
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
        // ignore
        }
        try {
            writer.close();
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : Path(org.dishevelled.bio.assembly.gfa1.Path) Gfa1Record(org.dishevelled.bio.assembly.gfa1.Gfa1Record) Reference(org.dishevelled.bio.assembly.gfa1.Reference) BufferedReader(java.io.BufferedReader) Traversal(org.dishevelled.bio.assembly.gfa1.Traversal) Gfa1Listener(org.dishevelled.bio.assembly.gfa1.Gfa1Listener) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException) PrintWriter(java.io.PrintWriter)

Example 7 with Path

use of net.minecraft.server.v1_15_R1.Path in project ets-ogcapi-features10 by opengeospatial.

the class OpenApiUtils method identifyTestPoints.

private static List<Path> identifyTestPoints(OpenApi3 apiModel, String path, PathMatcherFunction<Boolean, String, String> pathMatch) {
    List<Path> pathItems = new ArrayList<>();
    Map<String, Path> pathItemObjects = apiModel.getPaths();
    for (Path pathItemObject : pathItemObjects.values()) {
        String pathString = pathItemObject.getPathString();
        if (pathMatch.apply(pathString, path)) {
            pathItems.add(pathItemObject);
        }
    }
    return pathItems;
}
Also used : Path(com.reprezen.kaizen.oasparser.model3.Path) ArrayList(java.util.ArrayList)

Example 8 with Path

use of net.minecraft.server.v1_15_R1.Path in project jmulticard by ctt-gob-es.

the class CardOS method preloadCertificates.

private void preloadCertificates() throws FileNotFoundException, Iso7816FourCardException, IOException, Asn1Exception, TlvException {
    // Entramos en el directorio PKCS#15
    selectFileByName(PKCS15_NAME);
    // Seleccionamos el ODF, no nos devuelve FCI ni nada
    selectFileById(new byte[] { (byte) 0x50, (byte) 0x31 });
    // Leemos el ODF, que tiene esta estructura en cada uno de sus registros:
    // PKCS15Objects ::= CHOICE {
    // privateKeys         [0] PrivateKeys,
    // publicKeys          [1] PublicKeys,
    // trustedPublicKeys   [2] PublicKeys,
    // secretKeys          [3] SecretKeys,
    // certificates        [4] Certificates,
    // trustedCertificates [5] Certificates,
    // usefulCertificates  [6] Certificates,
    // dataObjects         [7] DataObjects,
    // authObjects         [8] AuthObjects,
    // ... -- For future extensions
    // }
    // A2
    final byte[] odfBytes = readBinaryComplete(162);
    final Odf odf = new Odf();
    odf.setDerValue(odfBytes);
    // Sacamos del ODF la ruta del CDF
    final Path cdfPath = odf.getCdfPath();
    // Seleccionamos el CDF
    selectFileById(cdfPath.getPathBytes());
    // Leemos el CDF mediante registros
    final List<byte[]> cdfRecords = readAllRecords();
    CertificateObject co;
    for (final byte[] b : cdfRecords) {
        try {
            co = new CertificateObject();
            co.setDerValue(HexUtils.subArray(b, 2, b.length - 2));
        } catch (final Exception e) {
            // $NON-NLS-1$
            LOGGER.warning("Omitido registro de certificado por no ser un CertificateObject de PKCS#15: " + e);
            continue;
        }
        final byte[] certPath = co.getPathBytes();
        if (certPath == null || certPath.length != 4) {
            // $NON-NLS-1$
            LOGGER.warning("Se omite una posicion de certificado porque su ruta no es de cuatro octetos: " + co.getAlias());
            continue;
        }
        final byte[] MASTER_FILE = { (byte) 0x50, (byte) 0x15 };
        sendArbitraryApdu(new CommandApdu(// CLA
        getCla(), // INS
        (byte) 0xA4, // P1
        (byte) 0x08, // P2
        (byte) 0x0C, new byte[] { MASTER_FILE[0], MASTER_FILE[1], certPath[0], certPath[1], certPath[2], certPath[3] }, null));
        final byte[] certBytes = readBinaryComplete(9999);
        final X509Certificate cert;
        try {
            cert = CertificateUtils.generateCertificate(certBytes);
        } catch (final CertificateException e) {
            LOGGER.severe(// $NON-NLS-1$ //$NON-NLS-2$
            "No ha sido posible generar el certificado para el alias " + co.getAlias() + ": " + e);
            continue;
        }
        certificatesByAlias.put(co.getAlias(), cert);
    }
}
Also used : Odf(es.gob.jmulticard.asn1.der.pkcs15.Odf) Path(es.gob.jmulticard.asn1.der.pkcs15.Path) CommandApdu(es.gob.jmulticard.apdu.CommandApdu) CertificateObject(es.gob.jmulticard.asn1.der.pkcs15.CertificateObject) CertificateException(java.security.cert.CertificateException) ApduConnectionException(es.gob.jmulticard.apdu.connection.ApduConnectionException) FileNotFoundException(es.gob.jmulticard.card.iso7816four.FileNotFoundException) InvalidCardException(es.gob.jmulticard.card.InvalidCardException) CardNotPresentException(es.gob.jmulticard.apdu.connection.CardNotPresentException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoReadersFoundException(es.gob.jmulticard.apdu.connection.NoReadersFoundException) TlvException(es.gob.jmulticard.asn1.TlvException) Iso7816FourCardException(es.gob.jmulticard.card.iso7816four.Iso7816FourCardException) Asn1Exception(es.gob.jmulticard.asn1.Asn1Exception) X509Certificate(java.security.cert.X509Certificate)

Example 9 with Path

use of net.minecraft.server.v1_15_R1.Path in project Citizens2 by CitizensDev.

the class NMSImpl method getTargetNavigator.

@Override
public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable<Vector> dest, final NavigatorParameters params) {
    List<PathPoint> list = Lists.<PathPoint>newArrayList(Iterables.<Vector, PathPoint>transform(dest, new Function<Vector, PathPoint>() {

        @Override
        public PathPoint apply(Vector input) {
            return new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ());
        }
    }));
    PathPoint last = list.size() > 0 ? list.get(list.size() - 1) : null;
    final PathEntity path = new PathEntity(list, last != null ? new BlockPosition(last.a, last.b, last.c) : null, true);
    return getTargetNavigator(entity, params, new Function<NavigationAbstract, Boolean>() {

        @Override
        public Boolean apply(NavigationAbstract input) {
            return input.a(path, params.speed());
        }
    });
}
Also used : PathPoint(net.minecraft.server.v1_15_R1.PathPoint) Function(com.google.common.base.Function) BlockPosition(net.minecraft.server.v1_15_R1.BlockPosition) NavigationAbstract(net.minecraft.server.v1_15_R1.NavigationAbstract) PathEntity(net.minecraft.server.v1_15_R1.PathEntity) Vector(org.bukkit.util.Vector)

Example 10 with Path

use of net.minecraft.server.v1_15_R1.Path in project dishevelled by heuermh.

the class ImportGfa2Task method run.

@Override
public void run(final TaskMonitor taskMonitor) throws Exception {
    taskMonitor.setTitle("Import a network in Graphical Fragment Assembly (GFA) 2.0 format");
    final Map<String, Segment> segmentsById = new HashMap<String, Segment>();
    taskMonitor.setStatusMessage("Reading segments from file ...");
    try (BufferedReader readable = new BufferedReader(new FileReader(inputFile))) {
        // stream segments, building cache
        stream(readable, new Gfa2Adapter() {

            @Override
            protected boolean segment(final Segment segment) {
                segmentsById.put(segment.getId(), segment);
                return true;
            }
        });
    }
    taskMonitor.setStatusMessage("Finding reverse orientation references ...");
    final Table<String, Orientation, Segment> segmentsByOrientation = HashBasedTable.create();
    final List<Edge> edges = new ArrayList<Edge>();
    final List<Gap> gaps = new ArrayList<Gap>();
    final List<Path> paths = new ArrayList<Path>();
    try (BufferedReader readable = new BufferedReader(new FileReader(inputFile))) {
        // stream edges, gaps, and paths, looking for reverse orientation references
        stream(readable, new Gfa2Adapter() {

            private void putIfAbsent(final Reference reference) {
                Segment segment = segmentsById.get(reference.getId());
                if (segment == null) {
                    throw new RuntimeException("could not find segment by id " + reference.getId());
                }
                if (!segmentsByOrientation.contains(reference.getId(), reference.getOrientation())) {
                    segmentsByOrientation.put(reference.getId(), reference.getOrientation(), segment);
                }
            }

            @Override
            public boolean edge(final Edge edge) {
                putIfAbsent(edge.getSource());
                putIfAbsent(edge.getTarget());
                edges.add(edge);
                return true;
            }

            @Override
            public boolean gap(final Gap gap) {
                putIfAbsent(gap.getSource());
                putIfAbsent(gap.getTarget());
                gaps.add(gap);
                return true;
            }

            @Override
            public boolean path(final Path path) {
                for (Reference reference : path.getReferences()) {
                    putIfAbsent(reference);
                }
                if (loadPaths) {
                    paths.add(path);
                }
                return true;
            }
        });
    }
    logger.info("read {} segments, {} edges, {} gaps, and {} paths from {}", new Object[] { segmentsById.size(), edges.size(), gaps.size(), paths.size(), inputFile });
    segmentsById.clear();
    taskMonitor.setStatusMessage("Building Cytoscape nodes from segments ...");
    final CyNetwork network = applicationManager.getCurrentNetwork();
    final Map<String, CyNode> nodes = new HashMap<String, CyNode>(segmentsByOrientation.size());
    for (Table.Cell<String, Orientation, Segment> c : segmentsByOrientation.cellSet()) {
        String id = c.getRowKey();
        Orientation orientation = c.getColumnKey();
        Segment segment = c.getValue();
        String name = id + (orientation.isForward() ? "+" : "-");
        if (!nodes.containsKey(name)) {
            CyNode node = network.addNode();
            CyTable nodeTable = network.getDefaultNodeTable();
            CyRow nodeRow = nodeTable.getRow(node.getSUID());
            Integer length = segment.getLength();
            Integer readCount = segment.getReadCountOpt().orElse(null);
            Integer fragmentCount = segment.getFragmentCountOpt().orElse(null);
            Integer kmerCount = segment.getKmerCountOpt().orElse(null);
            String sequenceChecksum = segment.containsSequenceChecksum() ? String.valueOf(segment.getSequenceChecksum()) : null;
            String sequenceUri = segment.getSequenceUriOpt().orElse(null);
            setValue(nodeTable, nodeRow, "name", String.class, name);
            setValue(nodeTable, nodeRow, "length", Integer.class, length);
            setValue(nodeTable, nodeRow, "readCount", Integer.class, readCount);
            setValue(nodeTable, nodeRow, "fragmentCount", Integer.class, fragmentCount);
            setValue(nodeTable, nodeRow, "kmerCount", Integer.class, kmerCount);
            setValue(nodeTable, nodeRow, "sequenceChecksum", String.class, sequenceChecksum);
            setValue(nodeTable, nodeRow, "sequenceUri", String.class, sequenceUri);
            // default display length to length
            Integer displayLength = length;
            String sequence = orientation.isForward() ? segment.getSequence() : reverseComplement(segment.getSequence());
            if (sequence != null) {
                Integer sequenceLength = sequence.length();
                String displaySequence = trimFromMiddle(sequence, displaySequenceLimit);
                Integer displaySequenceLength = displaySequence.length();
                if (loadSequences) {
                    setValue(nodeTable, nodeRow, "sequence", String.class, sequence);
                }
                setValue(nodeTable, nodeRow, "sequenceLength", Integer.class, sequenceLength);
                setValue(nodeTable, nodeRow, "displaySequence", String.class, displaySequence);
                setValue(nodeTable, nodeRow, "displaySequenceLength", Integer.class, displaySequenceLength);
                // override display length with sequence length if necessary
                if (length == null || length != sequenceLength) {
                    displayLength = sequenceLength;
                }
            }
            StringBuilder sb = new StringBuilder();
            sb.append(name);
            if (displayLength != null) {
                sb.append("  ");
                sb.append(displayLength);
                sb.append(" bp");
            }
            String displayName = sb.toString();
            if (readCount != null) {
                sb.append(" ");
                sb.append(readCount);
                sb.append(" reads");
            }
            if (fragmentCount != null) {
                sb.append(" ");
                sb.append(fragmentCount);
                sb.append(" fragments");
            }
            if (kmerCount != null) {
                sb.append(" ");
                sb.append(kmerCount);
                sb.append(" kmers");
            }
            String displayLabel = sb.toString();
            setValue(nodeTable, nodeRow, "displayName", String.class, displayName);
            setValue(nodeTable, nodeRow, "displayLength", Integer.class, displayLength);
            setValue(nodeTable, nodeRow, "displayLabel", String.class, displayLabel);
            nodes.put(name, node);
        }
    }
    logger.info("converted segments and orientation to " + nodes.size() + " nodes");
    segmentsByOrientation.clear();
    taskMonitor.setStatusMessage("Building Cytoscape edges from edges and gaps ...");
    for (Edge edge : edges) {
        String sourceId = edge.getSource().getId();
        String sourceOrientation = edge.getSource().isForwardOrientation() ? "+" : "-";
        String targetId = edge.getTarget().getId();
        String targetOrientation = edge.getTarget().isForwardOrientation() ? "+" : "-";
        CyNode sourceNode = nodes.get(sourceId + sourceOrientation);
        CyNode targetNode = nodes.get(targetId + targetOrientation);
        CyEdge cyEdge = network.addEdge(sourceNode, targetNode, true);
        CyTable edgeTable = network.getDefaultEdgeTable();
        CyRow edgeRow = edgeTable.getRow(cyEdge.getSUID());
        setValue(edgeTable, edgeRow, "id", String.class, edge.getIdOpt().orElse(null));
        setValue(edgeTable, edgeRow, "type", String.class, "edge");
        setValue(edgeTable, edgeRow, "sourceId", String.class, sourceId);
        setValue(edgeTable, edgeRow, "sourceOrientation", String.class, sourceOrientation);
        setValue(edgeTable, edgeRow, "targetId", String.class, targetId);
        setValue(edgeTable, edgeRow, "targetOrientation", String.class, targetOrientation);
        setValue(edgeTable, edgeRow, "sourceStart", String.class, edge.getSourceStart().toString());
        setValue(edgeTable, edgeRow, "sourceEnd", String.class, edge.getSourceEnd().toString());
        setValue(edgeTable, edgeRow, "targetStart", String.class, edge.getTargetStart().toString());
        setValue(edgeTable, edgeRow, "targetEnd", String.class, edge.getTargetEnd().toString());
        setValue(edgeTable, edgeRow, "alignment", String.class, edge.hasAlignment() ? edge.getAlignment().toString() : null);
        setValue(edgeTable, edgeRow, "readCount", Integer.class, edge.getReadCountOpt().orElse(null));
        setValue(edgeTable, edgeRow, "fragmentCount", Integer.class, edge.getFragmentCountOpt().orElse(null));
        setValue(edgeTable, edgeRow, "kmerCount", Integer.class, edge.getKmerCountOpt().orElse(null));
        setValue(edgeTable, edgeRow, "mappingQuality", Integer.class, edge.getMappingQualityOpt().orElse(null));
        setValue(edgeTable, edgeRow, "mismatchCount", Integer.class, edge.getMismatchCountOpt().orElse(null));
    }
    logger.info("converted edges to " + edges.size() + " edges");
    for (Gap gap : gaps) {
        String sourceId = gap.getSource().getId();
        String sourceOrientation = gap.getSource().isForwardOrientation() ? "+" : "-";
        String targetId = gap.getTarget().getId();
        String targetOrientation = gap.getTarget().isForwardOrientation() ? "+" : "-";
        CyNode sourceNode = nodes.get(sourceId + sourceOrientation);
        CyNode targetNode = nodes.get(targetId + targetOrientation);
        CyEdge edge = network.addEdge(sourceNode, targetNode, true);
        CyTable edgeTable = network.getDefaultEdgeTable();
        CyRow edgeRow = edgeTable.getRow(edge.getSUID());
        setValue(edgeTable, edgeRow, "id", String.class, gap.getIdOpt().orElse(null));
        setValue(edgeTable, edgeRow, "type", String.class, "gap");
        setValue(edgeTable, edgeRow, "sourceId", String.class, sourceId);
        setValue(edgeTable, edgeRow, "sourceOrientation", String.class, sourceOrientation);
        setValue(edgeTable, edgeRow, "targetId", String.class, targetId);
        setValue(edgeTable, edgeRow, "targetOrientation", String.class, targetOrientation);
        setValue(edgeTable, edgeRow, "distance", Integer.class, gap.getDistance());
        setValue(edgeTable, edgeRow, "variance", Integer.class, gap.getVarianceOpt().orElse(null));
    }
    logger.info("converted gaps to " + gaps.size() + " edges");
    nodes.clear();
    edges.clear();
    gaps.clear();
    // pass paths to AssemblyApp if requested
    if (loadPaths && !paths.isEmpty()) {
        taskMonitor.setStatusMessage("Loading paths in path view ...");
        assemblyModel.setInputFileName(inputFile.toString());
    // todo: convert to gfa1 paths?
    // note paths in gfa2 can have references to segments, edges, or other groups
    // assemblyModel.setPaths(paths, traversalsByPathName);
    }
}
Also used : Gfa2Adapter(org.dishevelled.bio.assembly.gfa2.Gfa2Adapter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) Segment(org.dishevelled.bio.assembly.gfa2.Segment) CyTable(org.cytoscape.model.CyTable) FileReader(java.io.FileReader) CyNode(org.cytoscape.model.CyNode) Path(org.dishevelled.bio.assembly.gfa2.Path) HashBasedTable(com.google.common.collect.HashBasedTable) CyTable(org.cytoscape.model.CyTable) Table(com.google.common.collect.Table) Reference(org.dishevelled.bio.assembly.gfa2.Reference) Orientation(org.dishevelled.bio.assembly.gfa2.Orientation) CyEdge(org.cytoscape.model.CyEdge) Gap(org.dishevelled.bio.assembly.gfa2.Gap) BufferedReader(java.io.BufferedReader) CyEdge(org.cytoscape.model.CyEdge) Edge(org.dishevelled.bio.assembly.gfa2.Edge)

Aggregations

Path (org.dishevelled.bio.assembly.gfa1.Path)7 Path (com.reprezen.kaizen.oasparser.model3.Path)5 BufferedReader (java.io.BufferedReader)5 ArrayList (java.util.ArrayList)5 PrintWriter (java.io.PrintWriter)4 CommandLineParseException (org.dishevelled.commandline.CommandLineParseException)4 HashMap (java.util.HashMap)3 Traversal (org.dishevelled.bio.assembly.gfa1.Traversal)3 HashBasedTable (com.google.common.collect.HashBasedTable)2 Table (com.google.common.collect.Table)2 Parameter (com.reprezen.kaizen.oasparser.model3.Parameter)2 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)2 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)2 TlvException (es.gob.jmulticard.asn1.TlvException)2 Odf (es.gob.jmulticard.asn1.der.pkcs15.Odf)2 Path (es.gob.jmulticard.asn1.der.pkcs15.Path)2 InvalidCardException (es.gob.jmulticard.card.InvalidCardException)2 FileNotFoundException (es.gob.jmulticard.card.iso7816four.FileNotFoundException)2 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)2 FileReader (java.io.FileReader)2