Search in sources :

Example 1 with Reference

use of com.google.api.expr.v1alpha1.Reference in project xtext-core by eclipse.

the class Bug311337TestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == Bug311337Package.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case Bug311337Package.CHILD:
                sequence_Child(context, (Child) semanticObject);
                return;
            case Bug311337Package.DEFINITION:
                sequence_Definition(context, (Definition) semanticObject);
                return;
            case Bug311337Package.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
            case Bug311337Package.NESTED_REF:
                sequence_Reference(context, (NestedRef) semanticObject);
                return;
            case Bug311337Package.REFERENCE:
                sequence_Reference(context, (Reference) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) NestedRef(org.eclipse.xtext.linking.lazy.bug311337.NestedRef) Action(org.eclipse.xtext.Action) Reference(org.eclipse.xtext.linking.lazy.bug311337.Reference) Definition(org.eclipse.xtext.linking.lazy.bug311337.Definition) Model(org.eclipse.xtext.linking.lazy.bug311337.Model) Parameter(org.eclipse.xtext.Parameter) Child(org.eclipse.xtext.linking.lazy.bug311337.Child) EPackage(org.eclipse.emf.ecore.EPackage)

Example 2 with Reference

use of com.google.api.expr.v1alpha1.Reference in project xtext-core by eclipse.

the class NestedRefImpl method basicSetLeft.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetLeft(Reference newLeft, NotificationChain msgs) {
    Reference oldLeft = left;
    left = newLeft;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Bug311337Package.NESTED_REF__LEFT, oldLeft, newLeft);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : Reference(org.eclipse.xtext.linking.lazy.bug311337.Reference) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 3 with Reference

use of com.google.api.expr.v1alpha1.Reference in project dishevelled by heuermh.

the class AssemblyModel method traversalsFor.

/**
 * Create and return a list of path traversals for the specified path.
 *
 * @param path path, must not be null
 * @return a list of path traversals for the specified path
 */
static List<Traversal> traversalsFor(final Path path) {
    checkNotNull(path);
    int size = path.getSegments().size();
    List<Traversal> traversals = new ArrayList<Traversal>(size);
    Reference source = null;
    Reference target = null;
    String overlap = null;
    Map<String, Annotation> emptyAnnotations = Collections.emptyMap();
    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, emptyAnnotations);
            traversals.add(traversal);
        }
        source = target;
    }
    return traversals;
}
Also used : Reference(org.dishevelled.bio.assembly.gfa1.Reference) ArrayList(java.util.ArrayList) Traversal(org.dishevelled.bio.assembly.gfa1.Traversal) Annotation(org.dishevelled.bio.annotation.Annotation)

Example 4 with Reference

use of com.google.api.expr.v1alpha1.Reference in project dishevelled by heuermh.

the class ImportGfa1Task method run.

@Override
public void run(final TaskMonitor taskMonitor) throws Exception {
    taskMonitor.setTitle("Import a network in Graphical Fragment Assembly (GFA) 1.0 format");
    final Map<String, Segment> segmentsById = new HashMap<String, Segment>();
    final Table<String, Orientation, Segment> segmentsByOrientation = HashBasedTable.create();
    final ListMultimap<String, Traversal> traversalsByPathName = ArrayListMultimap.create();
    taskMonitor.setStatusMessage("Reading segments from file ...");
    try (BufferedReader readable = new BufferedReader(new FileReader(inputFile))) {
        // stream segments, building cache
        stream(readable, new Gfa1Adapter() {

            @Override
            protected boolean segment(final Segment segment) {
                segmentsById.put(segment.getId(), segment);
                return true;
            }
        });
    }
    taskMonitor.setStatusMessage("Finding reverse orientation references ...");
    final List<Path> paths = new ArrayList<Path>();
    final List<Link> links = new ArrayList<Link>();
    try (BufferedReader readable = new BufferedReader(new FileReader(inputFile))) {
        // stream paths and links, looking for reverse orientation references
        stream(readable, new Gfa1Adapter() {

            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
            protected boolean path(final Path path) {
                for (Reference reference : path.getSegments()) {
                    putIfAbsent(reference);
                }
                if (loadPaths) {
                    paths.add(path);
                }
                return true;
            }

            @Override
            protected boolean link(final Link link) {
                putIfAbsent(link.getSource());
                putIfAbsent(link.getTarget());
                links.add(link);
                return true;
            }

            @Override
            protected boolean traversal(final Traversal traversal) {
                traversalsByPathName.put(traversal.getPathName(), traversal);
                return true;
            }
        });
    }
    logger.info("read {} segments, {} links, {} paths, and {} traversals from {}", new Object[] { segmentsById.size(), links.size(), paths.size(), traversalsByPathName.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.getLengthOpt().orElse(null);
            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 links ...");
    for (Link link : links) {
        String sourceId = link.getSource().getId();
        String sourceOrientation = link.getSource().isForwardOrientation() ? "+" : "-";
        String targetId = link.getTarget().getId();
        String targetOrientation = link.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, link.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, "overlap", String.class, link.getOverlapOpt().orElse(null));
        setValue(edgeTable, edgeRow, "readCount", Integer.class, link.getReadCountOpt().orElse(null));
        setValue(edgeTable, edgeRow, "fragmentCount", Integer.class, link.getFragmentCountOpt().orElse(null));
        setValue(edgeTable, edgeRow, "kmerCount", Integer.class, link.getKmerCountOpt().orElse(null));
        setValue(edgeTable, edgeRow, "mappingQuality", Integer.class, link.getMappingQualityOpt().orElse(null));
        setValue(edgeTable, edgeRow, "mismatchCount", Integer.class, link.getMismatchCountOpt().orElse(null));
    }
    logger.info("converted links to " + links.size() + " edges");
    nodes.clear();
    links.clear();
    // pass paths to AssemblyApp if requested
    if (loadPaths && !paths.isEmpty()) {
        taskMonitor.setStatusMessage("Loading paths in path view ...");
        assemblyModel.setInputFileName(inputFile.toString());
        assemblyModel.setPaths(paths, traversalsByPathName);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Traversal(org.dishevelled.bio.assembly.gfa1.Traversal) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) Segment(org.dishevelled.bio.assembly.gfa1.Segment) CyTable(org.cytoscape.model.CyTable) FileReader(java.io.FileReader) CyNode(org.cytoscape.model.CyNode) Path(org.dishevelled.bio.assembly.gfa1.Path) HashBasedTable(com.google.common.collect.HashBasedTable) CyTable(org.cytoscape.model.CyTable) Table(com.google.common.collect.Table) Reference(org.dishevelled.bio.assembly.gfa1.Reference) Orientation(org.dishevelled.bio.assembly.gfa1.Orientation) CyEdge(org.cytoscape.model.CyEdge) BufferedReader(java.io.BufferedReader) Gfa1Adapter(org.dishevelled.bio.assembly.gfa1.Gfa1Adapter) Link(org.dishevelled.bio.assembly.gfa1.Link)

Example 5 with Reference

use of com.google.api.expr.v1alpha1.Reference in project molgenis-emx2 by molgenis.

the class SqlColumnRefBackExecutor method createTriggerForRef.

private static void createTriggerForRef(DSLContext jooq, Column column, boolean isUpdateTrigger) {
    // check if any refBack array has non-existing pkey
    // remove refs from other table if not any more in refBack array
    // update refs from other table to new identifier ( automatic via cascade , nothing to
    // do here)
    // add refs from other table if new in refBack array
    String schemaName = column.getTable().getSchema().getName();
    String triggerName = refBackUpdateTriggerName(column) + (isUpdateTrigger ? "_UPDATE" : "_INSERT");
    List<Reference> columns = column.getReferences();
    // begin
    String sql = "CREATE FUNCTION {0}() RETURNS trigger AS $BODY$ " + "\nDECLARE my_row RECORD;" + "\nBEGIN";
    // add check if the refs actually exist
    sql += "\n\t-- raise error for first refColumn value that does not in refTable key values " + "\n\tFOR my_row IN SELECT {1} FROM newtab EXCEPT (SELECT {2} FROM {3}) LOOP" + "\n\t\tRAISE EXCEPTION USING ERRCODE='23503', " + "\n\t\tMESSAGE = 'insert on table '||{4}||' violates foreign key constraint for refback column(s)'," + "\n\t\tDETAIL = 'Key ('||{5}||')=('|| {6} ||') is not present in table '||{7}||', column '||{8};" + "\n\tEND LOOP;";
    // in case of update, we should also remove the references not in the 'old'
    if (isUpdateTrigger) {
        sql += "\n\t-- remove ref to 'oldtable'.key if not anymore in refarray" + "\n\tFOR my_row IN SELECT {13},{1} FROM oldtab EXCEPT (SELECT {13},{1} FROM newtab) LOOP" + "\n\t\tUPDATE {3} set {9} WHERE {12};" + "\n\tEND LOOP;";
        sql += "\n\t-- set to ref to 'newtable'.key if in refBack values list" + "\n\tFOR my_row IN SELECT {13},{1} FROM newtab EXCEPT (SELECT {13},{1} FROM oldtab) LOOP" + "\n\t\tUPDATE {3} set {11} WHERE {12};" + "\n\tEND LOOP;";
    } else {
        // in case of insert
        sql += "\n\t-- set to ref to 'newtable'.key if in refBack values list" + "\n\tFOR my_row IN SELECT {13},{1} FROM newtab LOOP" + "\n\t\tUPDATE {3} set {11} WHERE {12};" + "\n\tEND LOOP;";
    }
    // end
    sql += "\n\tRETURN NEW;" + "\nEND; $BODY$ LANGUAGE plpgsql;";
    RowCountQuery q = jooq.query(sql, // 0 function name
    name(schemaName, triggerName), // 1 selection of unnested inputs
    keyword(columns.stream().map(r -> "unnest(" + name(r.getName()) + ") as " + name(r.getName())).collect(Collectors.joining(","))), // 2 foreign key column names refBack refers to
    keyword(columns.stream().map(r -> name(r.getRefTo()).toString()).collect(Collectors.joining(","))), // 3 refTable
    table(name(schemaName, column.getRefTableName())), // 4 inline string of table for debug message
    inline(column.getTable().getTableName()), // 5 inline columns
    keyword(columns.stream().map(r -> inline(r.getName()).toString()).collect(Collectors.joining("||','||"))), // 6 concat of the error column values
    keyword(columns.stream().map(r -> "COALESCE(my_row." + name(r.getRefTo()).toString() + ",'NULL')").collect(Collectors.joining("||','||"))), // 7 inline refTable
    inline(column.getRefTable().getTableName()), // 8 inline toColumns
    keyword(columns.stream().map(r -> inline(r.getRefTo()).toString()).collect(Collectors.joining("||','||"))), // 9 set refBack to null
    keyword(column.getRefBackColumn().getReferences().stream().map(r -> name(r.getName()) + "=NULL").collect(Collectors.joining(","))), // 10 where references old key and not new key
    keyword(column.getRefBackColumn().getReferences().stream().map(r -> name(r.getName()) + "=OLD." + name(r.getRefTo())).collect(Collectors.joining(" AND "))), // 11 set to point to this.key(s)
    keyword(column.getRefBackColumn().getReferences().stream().map(r -> name(r.getName()) + "=my_row." + name(r.getRefTo())).collect(Collectors.joining(","))), // 12 where reftable.key=refback
    keyword(columns.stream().map(r -> name(r.getRefTo()) + "=my_row." + name(r.getName())).collect(Collectors.joining(" AND "))), // 13 keys of this table
    keyword(column.getRefBackColumn().getReferences().stream().map(r -> name(r.getRefTo()).toString()).collect(Collectors.joining(","))), // 14 where this keys
    keyword(column.getRefBackColumn().getReferences().stream().map(Reference::getRefTo).map(s -> name(s) + "=NEW." + name(s)).collect(Collectors.joining(" AND "))));
    // System.out.println("sql: " + q.getSQL());
    q.execute();
    String trigger = isUpdateTrigger ? "CREATE TRIGGER {0} " + "\n\tAFTER UPDATE ON {2}" + "\n\tREFERENCING NEW TABLE AS newtab OLD TABLE AS oldtab" + "\n\tEXECUTE PROCEDURE {3}()" : "CREATE TRIGGER {0} " + "\n\tAFTER INSERT ON {2}" + "\n\tREFERENCING NEW TABLE AS newtab" + "\n\tEXECUTE PROCEDURE {3}()";
    jooq.execute(trigger, // 0 name of the trigger
    name(triggerName), // 1 the columns of the refBack that should be set to trigger the trigger
    keyword(columns.stream().map(r -> name(r.getName()).toString()).collect(Collectors.joining(","))), // name of the table
    name(schemaName, column.getTable().getTableName()), // reference to the trigger function
    name(schemaName, triggerName));
}
Also used : Column(org.molgenis.emx2.Column) SqlColumnExecutor.validateColumn(org.molgenis.emx2.sql.SqlColumnExecutor.validateColumn) DataAccessException(org.jooq.exception.DataAccessException) List(java.util.List) DSL(org.jooq.impl.DSL) MolgenisException(org.molgenis.emx2.MolgenisException) Reference(org.molgenis.emx2.Reference) RowCountQuery(org.jooq.RowCountQuery) DSLContext(org.jooq.DSLContext) Collectors(java.util.stream.Collectors) RowCountQuery(org.jooq.RowCountQuery) Reference(org.molgenis.emx2.Reference)

Aggregations

Reference (org.geotoolkit.wps.xml.v200.Reference)34 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)17 Path (java.nio.file.Path)14 Test (org.junit.Test)11 IOException (java.io.IOException)9 URL (java.net.URL)9 HashMap (java.util.HashMap)9 JAXBException (javax.xml.bind.JAXBException)6 AbstractWPSConverterTest (org.geotoolkit.wps.converters.AbstractWPSConverterTest)6 ArrayList (java.util.ArrayList)5 Feature (org.opengis.feature.Feature)5 BufferedReader (java.io.BufferedReader)4 Geometry (org.locationtech.jts.geom.Geometry)4 Type (com.google.api.expr.v1alpha1.Type)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 DataStoreException (org.apache.sis.storage.DataStoreException)3 Reference (org.dishevelled.bio.assembly.gfa1.Reference)3 Traversal (org.dishevelled.bio.assembly.gfa1.Traversal)3 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)2 Decl (com.google.api.expr.v1alpha1.Decl)2