Search in sources :

Example 21 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project goci by EBISPOT.

the class JsonProcessingService method getEfoTraits.

private Map<String, String> getEfoTraits(JsonNode doc) {
    Map<String, String> traits = new HashMap<>();
    String trait = "";
    String uri = "";
    if (doc.get("efoLink") != null) {
        for (JsonNode efoLink : doc.get("efoLink")) {
            String[] data = efoLink.asText().trim().split("\\|");
            if (trait == "") {
                trait = data[0];
                uri = data[2];
            } else {
                trait = trait.concat(", ").concat(data[0]);
                uri = uri.concat(", ").concat(data[2]);
            }
        }
    }
    traits.put("trait", trait);
    traits.put("uri", uri);
    return traits;
}
Also used : HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 22 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project goci by EBISPOT.

the class JsonProcessingService method getRepGene.

private String getRepGene(JsonNode doc) {
    String genes = "";
    if (doc.get("reportedGene") != null) {
        int it = 0;
        for (JsonNode gene : doc.get("reportedGene")) {
            if (it > 0) {
                genes = genes.concat(", ");
            }
            genes = genes.concat(gene.asText().trim());
            it++;
        }
    }
    return genes;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 23 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project goci by EBISPOT.

the class JsonProcessingService method processJson.

public String processJson() throws IOException {
    String header;
    if (type.equals("study") && !includeAncestry) {
        header = "DATE ADDED TO CATALOG\tPUBMEDID\tFIRST AUTHOR\tDATE\tJOURNAL\tLINK\tSTUDY\tDISEASE/TRAIT\tINITIAL SAMPLE SIZE\tREPLICATION SAMPLE SIZE\tPLATFORM [SNPS PASSING QC]\tASSOCIATION COUNT";
    } else if (includeAncestry) {
        header = "STUDY ACCCESSION\tPUBMEDID\tFIRST AUTHOR\tDATE\tINITIAL SAMPLE DESCRIPTION\tREPLICATION SAMPLE DESCRIPTION\tSTAGE\tNUMBER OF INDIVDUALS\tBROAD ANCESTRAL CATEGORY\tCOUNTRY OF ORIGIN\tCOUNTRY OF RECRUITMENT\tADDITONAL ANCESTRY DESCRIPTION";
    } else {
        header = "DATE ADDED TO CATALOG\tPUBMEDID\tFIRST AUTHOR\tDATE\tJOURNAL\tLINK\tSTUDY\tDISEASE/TRAIT\tINITIAL SAMPLE SIZE\tREPLICATION SAMPLE SIZE\tREGION\tCHR_ID\tCHR_POS\tREPORTED GENE(S)\tMAPPED_GENE\tUPSTREAM_GENE_ID\tDOWNSTREAM_GENE_ID\tSNP_GENE_IDS\tUPSTREAM_GENE_DISTANCE\tDOWNSTREAM_GENE_DISTANCE\tSTRONGEST SNP-RISK ALLELE\tSNPS\tMERGED\tSNP_ID_CURRENT\tCONTEXT\tINTERGENIC\tRISK ALLELE FREQUENCY\tP-VALUE\tPVALUE_MLOG\tP-VALUE (TEXT)\tOR or BETA\t95% CI (TEXT)\tPLATFORM [SNPS PASSING QC]\tCNV";
    }
    if (includeAnnotations) {
        header = header.concat("\tMAPPED_TRAIT\tMAPPED_TRAIT_URI\tSTUDY ACCESSION");
    }
    header = header.concat("\r\n");
    StringBuilder result = new StringBuilder();
    result.append(header);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode node = mapper.readTree(json);
    JsonNode responseNode = node.get("response");
    JsonNode docs = responseNode.get("docs");
    for (JsonNode doc : docs) {
        StringBuilder line = new StringBuilder();
        if (type.equals("study") && !includeAncestry) {
            processStudyJson(line, doc);
        } else if (includeAncestry) {
            if (doc.get("ancestryLinks") != null) {
                for (JsonNode a : doc.get("ancestryLinks")) {
                    processAncestryJson(line, doc, a);
                }
            }
        } else {
            processAssociationJson(line, doc);
        }
        result.append(line.toString());
    }
    return result.toString();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 24 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project midpoint by Evolveum.

the class AbstractJsonLexicalProcessor method parseToPrimitive.

private <T> PrimitiveXNode<T> parseToPrimitive(JsonParsingContext ctx) throws IOException, SchemaException {
    PrimitiveXNode<T> primitive = new PrimitiveXNode<T>();
    Object tid = ctx.parser.getTypeId();
    if (tid != null) {
        QName typeName = tagToTypeName(tid, ctx);
        primitive.setTypeQName(typeName);
        primitive.setExplicitTypeDeclaration(true);
    } else {
    // We don't try to determine XNode type from the implicit JSON/YAML type (integer, number, ...),
    // because XNode type prescribes interpretation in midPoint. E.g. YAML string type would be interpreted
    // as xsd:string, even if the schema would expect e.g. timestamp.
    }
    JsonNode jn = ctx.parser.readValueAs(JsonNode.class);
    ValueParser<T> vp = new JsonValueParser<T>(ctx.parser, jn);
    primitive.setValueParser(vp);
    return primitive;
}
Also used : PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) QName(javax.xml.namespace.QName) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 25 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project textdb by TextDB.

the class TupleJsonDeserializer method deserialize.

@Override
public Tuple deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    JsonNode node = p.getCodec().readTree(p);
    JsonNode schemaNode = node.get(JsonConstants.SCHEMA);
    JsonNode fieldsNode = node.get(JsonConstants.FIELDS);
    Schema schema = new ObjectMapper().treeToValue(schemaNode, Schema.class);
    ArrayList<IField> fields = new ArrayList<>();
    for (int i = 0; i < schema.getAttributes().size(); i++) {
        AttributeType attributeType = schema.getAttributes().get(i).getAttributeType();
        JsonNode fieldNode = fieldsNode.get(i);
        IField field = new ObjectMapper().treeToValue(fieldNode, attributeType.getFieldClass());
        fields.add(field);
    }
    return new Tuple(schema, fields);
}
Also used : AttributeType(edu.uci.ics.textdb.api.schema.AttributeType) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IField(edu.uci.ics.textdb.api.field.IField) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)4105 Test (org.junit.Test)1257 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)802 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)544 IOException (java.io.IOException)532 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)384 ArrayList (java.util.ArrayList)315 Test (org.junit.jupiter.api.Test)277 HashMap (java.util.HashMap)249 Map (java.util.Map)201 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)174 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)127 List (java.util.List)122 InputStream (java.io.InputStream)116 KernelTest (com.twosigma.beakerx.KernelTest)114 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)84 Response (javax.ws.rs.core.Response)79 File (java.io.File)78 HttpGet (org.apache.http.client.methods.HttpGet)75 ByteArrayInputStream (java.io.ByteArrayInputStream)70