use of net.minecraft.server.v1_14_R1.Path in project dishevelled-bio by heuermh.
the class Gfa1ToGfa2 method call.
@Override
public Integer call() throws Exception {
PrintWriter writer = null;
try {
writer = writer(outputGfa2File);
final PrintWriter w = writer;
Gfa1Reader.stream(reader(inputGfa1File), new Gfa1Adapter() {
@Override
public boolean header(final Header header) {
// convert VN:Z:1.0 to VN:Z:2.0 annotation if present
if (header.getAnnotations().containsKey("VN")) {
if (!"1.0".equals(header.getAnnotations().get("VN").getValue())) {
throw new RuntimeException("cannot convert input as GFA 1.0, was " + header.getAnnotations().get("VN").getValue());
}
Map<String, Annotation> annotations = new HashMap<String, Annotation>();
annotations.put("VN", new Annotation("VN", "Z", "2.0"));
for (Annotation annotation : header.getAnnotations().values()) {
if (!"VN".equals(annotation.getName())) {
annotations.put(annotation.getName(), annotation);
}
}
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Header(annotations), w);
} else {
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Header(header.getAnnotations()), w);
}
return true;
}
@Override
public boolean segment(final Segment segment) {
if (segment.getSequence() != null) {
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Segment(segment.getId(), segment.getSequence().length(), segment.getSequence(), segment.getAnnotations()), w);
} else if (segment.getAnnotations().containsKey("LN")) {
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Segment(segment.getId(), Integer.parseInt(segment.getAnnotations().get("LN").getValue()), segment.getSequence(), segment.getAnnotations()), w);
} else {
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Segment(segment.getId(), 0, segment.getSequence(), segment.getAnnotations()), w);
}
return true;
}
@Override
public boolean link(final Link link) {
Position unknown = new Position(0, false);
Alignment alignment = link.getOverlap() == null ? null : Alignment.valueOf(link.getOverlap());
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Edge(null, toGfa2Reference(link.getSource()), toGfa2Reference(link.getTarget()), unknown, unknown, unknown, unknown, alignment, link.getAnnotations()), w);
return true;
}
@Override
public boolean containment(final Containment containment) {
Position unknown = new Position(0, false);
Position targetStart = new Position(containment.getPosition(), false);
Alignment alignment = containment.getOverlap() == null ? null : Alignment.valueOf(containment.getOverlap());
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Edge(null, toGfa2Reference(containment.getContainer()), toGfa2Reference(containment.getContained()), unknown, unknown, targetStart, unknown, alignment, containment.getAnnotations()), w);
return true;
}
@Override
public boolean path(final Path path) {
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Path(path.getName(), toGfa2References(path.getSegments()), path.getAnnotations()), w);
return true;
}
});
return 0;
} finally {
try {
writer.close();
} catch (Exception e) {
// empty
}
}
}
use of net.minecraft.server.v1_14_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
}
}
}
use of net.minecraft.server.v1_14_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);
}
}
use of net.minecraft.server.v1_14_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());
}
});
}
use of net.minecraft.server.v1_14_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);
}
}
Aggregations