Example usage for java.util Map.Entry get

List of usage examples for java.util Map.Entry get

Introduction

In this page you can find the example usage for java.util Map.Entry get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:io.hops.hopsworks.api.jobs.JobService.java

/**
 * Get application run info for the specified job
 * <p>/*  w  w w  .j a va  2 s.  c o  m*/
 * @param appId
 * @param sc
 * @param req
 * @return url
 */
@GET
@Path("/{appId}/appinfo")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
public Response getAppInfo(@PathParam("appId") String appId, @Context SecurityContext sc,
        @Context HttpServletRequest req) {
    Response response = checkAccessRight(appId);
    if (response != null) {
        return response;
    } else {
        Execution execution = exeFacade.findByAppId(appId);
        try {
            long startTime = System.currentTimeMillis() - 60000;
            long endTime = System.currentTimeMillis();
            boolean running = true;
            if (execution != null) {
                startTime = execution.getSubmissionTime().getTime();
                endTime = startTime + execution.getExecutionDuration();
                running = false;
                if (!execution.getState().isFinalState()) {
                    running = true;
                }
            }

            InfluxDB influxDB = InfluxDBFactory.connect(settings.getInfluxDBAddress(),
                    settings.getInfluxDBUser(), settings.getInfluxDBPW());

            // Transform application_1493112123688_0001 to 1493112123688_0001
            // application_ = 12 chars
            String timestamp_attempt = appId.substring(12);

            Query query = new Query("show tag values from nodemanager with key=\"source\" "
                    + "where source =~ /^.*" + timestamp_attempt + ".*$/", "graphite");
            QueryResult queryResult = influxDB.query(query, TimeUnit.MILLISECONDS);

            int nbExecutors = 0;
            HashMap<Integer, List<String>> executorInfo = new HashMap<>();
            int index = 0;
            if (queryResult != null && queryResult.getResults() != null) {
                for (QueryResult.Result res : queryResult.getResults()) {
                    if (res.getSeries() != null) {
                        for (QueryResult.Series series : res.getSeries()) {
                            List<List<Object>> values = series.getValues();
                            if (values != null) {
                                nbExecutors += values.size();
                                for (List<Object> l : values) {
                                    executorInfo.put(index,
                                            Stream.of(Objects.toString(l.get(1))).collect(Collectors.toList()));
                                    index++;
                                }
                            }
                        }
                    }
                }
            }

            /*
             * At this point executor info contains the keys and a list with a single value, the YARN container id
             */
            String vCoreTemp = null;
            HashMap<String, String> hostnameVCoreCache = new HashMap<>();

            for (Map.Entry<Integer, List<String>> entry : executorInfo.entrySet()) {
                query = new Query(
                        "select MilliVcoreUsageAvgMilliVcores, hostname from nodemanager where source = \'"
                                + entry.getValue().get(0) + "\' limit 1",
                        "graphite");
                queryResult = influxDB.query(query, TimeUnit.MILLISECONDS);

                if (queryResult != null && queryResult.getResults() != null
                        && queryResult.getResults().get(0) != null
                        && queryResult.getResults().get(0).getSeries() != null) {
                    List<List<Object>> values = queryResult.getResults().get(0).getSeries().get(0).getValues();
                    String hostname = Objects.toString(values.get(0).get(2)).split("=")[1];
                    entry.getValue().add(hostname);

                    if (!hostnameVCoreCache.containsKey(hostname)) {
                        // Not in cache, get the vcores of the host machine
                        query = new Query("select AllocatedVCores+AvailableVCores from nodemanager "
                                + "where hostname =~ /.*" + hostname + ".*/ limit 1", "graphite");
                        queryResult = influxDB.query(query, TimeUnit.MILLISECONDS);

                        if (queryResult != null && queryResult.getResults() != null
                                && queryResult.getResults().get(0) != null
                                && queryResult.getResults().get(0).getSeries() != null) {
                            values = queryResult.getResults().get(0).getSeries().get(0).getValues();
                            vCoreTemp = Objects.toString(values.get(0).get(1));
                            entry.getValue().add(vCoreTemp);
                            hostnameVCoreCache.put(hostname, vCoreTemp); // cache it
                        }
                    } else {
                        // It's a hit, skip the database query
                        entry.getValue().add(hostnameVCoreCache.get(hostname));
                    }
                }
            }

            influxDB.close();

            AppInfoDTO appInfo = new AppInfoDTO(appId, startTime, running, endTime, nbExecutors, executorInfo);

            return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(appInfo).build();

        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "exception while geting job ui " + e.getLocalizedMessage(), e);
        }
        return noCacheResponse.getNoCacheResponseBuilder(Response.Status.NOT_FOUND).build();
    }
}

From source file:com.espertech.esper.core.InternalEventRouterImpl.java

private NullableObject<InternalEventRouterPreprocessor> initialize(EventType eventType) {
    EventTypeSPI eventTypeSPI = (EventTypeSPI) eventType;
    List<InternalEventRouterEntry> desc = new ArrayList<InternalEventRouterEntry>();

    // determine which ones to process for this types, and what priority and drop
    Set<String> eventPropertiesWritten = new HashSet<String>();
    for (Map.Entry<UpdateDesc, IRDescEntry> entry : descriptors.entrySet()) {
        boolean applicable = entry.getValue().getEventType() == eventType;
        if (!applicable) {
            if (eventType.getDeepSuperTypes() != null) {
                for (Iterator<EventType> it = eventType.getDeepSuperTypes(); it.hasNext();) {
                    if (it.next() == entry.getValue().getEventType()) {
                        applicable = true;
                        break;
                    }/*  www. j  a va2s. co  m*/
                }
            }
        }

        if (!applicable) {
            continue;
        }

        int priority = 0;
        boolean isDrop = false;
        Annotation[] annotations = entry.getValue().getAnnotations();
        for (int i = 0; i < annotations.length; i++) {
            if (annotations[i] instanceof Priority) {
                priority = ((Priority) annotations[i]).value();
            }
            if (annotations[i] instanceof Drop) {
                isDrop = true;
            }
        }

        List<String> properties = new ArrayList<String>();
        ExprNode[] expressions = new ExprNode[entry.getKey().getAssignments().size()];
        for (int i = 0; i < entry.getKey().getAssignments().size(); i++) {
            OnTriggerSetAssignment assignment = entry.getKey().getAssignments().get(i);
            expressions[i] = assignment.getExpression();
            properties.add(assignment.getVariableName());
            eventPropertiesWritten.add(assignment.getVariableName());
        }
        EventBeanWriter writer = eventTypeSPI.getWriter(properties.toArray(new String[properties.size()]));
        desc.add(new InternalEventRouterEntry(priority, isDrop, entry.getKey().getOptionalWhereClause(),
                expressions, writer, entry.getValue().getWideners(), entry.getValue().getOutputView()));
    }

    EventBeanCopyMethod copyMethod = eventTypeSPI
            .getCopyMethod(eventPropertiesWritten.toArray(new String[eventPropertiesWritten.size()]));
    if (copyMethod == null) {
        return new NullableObject<InternalEventRouterPreprocessor>(null);
    }
    return new NullableObject<InternalEventRouterPreprocessor>(
            new InternalEventRouterPreprocessor(copyMethod, desc));
}

From source file:com.espertech.esper.core.service.InternalEventRouterImpl.java

private NullableObject<InternalEventRouterPreprocessor> initialize(EventType eventType) {
    EventTypeSPI eventTypeSPI = (EventTypeSPI) eventType;
    List<InternalEventRouterEntry> desc = new ArrayList<InternalEventRouterEntry>();

    // determine which ones to process for this types, and what priority and drop
    Set<String> eventPropertiesWritten = new HashSet<String>();
    for (Map.Entry<UpdateDesc, IRDescEntry> entry : descriptors.entrySet()) {
        boolean applicable = entry.getValue().getEventType() == eventType;
        if (!applicable) {
            if (eventType.getDeepSuperTypes() != null) {
                for (Iterator<EventType> it = eventType.getDeepSuperTypes(); it.hasNext();) {
                    if (it.next() == entry.getValue().getEventType()) {
                        applicable = true;
                        break;
                    }/*from w  w w .  ja  va 2s. co m*/
                }
            }
        }

        if (!applicable) {
            continue;
        }

        int priority = 0;
        boolean isDrop = false;
        Annotation[] annotations = entry.getValue().getAnnotations();
        for (int i = 0; i < annotations.length; i++) {
            if (annotations[i] instanceof Priority) {
                priority = ((Priority) annotations[i]).value();
            }
            if (annotations[i] instanceof Drop) {
                isDrop = true;
            }
        }

        List<String> properties = new ArrayList<String>();
        ExprNode[] expressions = new ExprNode[entry.getKey().getAssignments().size()];
        for (int i = 0; i < entry.getKey().getAssignments().size(); i++) {
            OnTriggerSetAssignment assignment = entry.getKey().getAssignments().get(i);
            Pair<String, ExprNode> assignmentPair = ExprNodeUtility
                    .checkGetAssignmentToProp(assignment.getExpression());
            expressions[i] = assignmentPair.getSecond();
            properties.add(assignmentPair.getFirst());
            eventPropertiesWritten.add(assignmentPair.getFirst());
        }
        EventBeanWriter writer = eventTypeSPI.getWriter(properties.toArray(new String[properties.size()]));
        desc.add(new InternalEventRouterEntry(priority, isDrop, entry.getKey().getOptionalWhereClause(),
                expressions, writer, entry.getValue().getWideners(), entry.getValue().getOutputView(),
                entry.getValue().getAgentInstanceLock(), entry.getValue().hasSubselect));
    }

    EventBeanCopyMethod copyMethod = eventTypeSPI
            .getCopyMethod(eventPropertiesWritten.toArray(new String[eventPropertiesWritten.size()]));
    if (copyMethod == null) {
        return new NullableObject<InternalEventRouterPreprocessor>(null);
    }
    return new NullableObject<InternalEventRouterPreprocessor>(
            new InternalEventRouterPreprocessor(copyMethod, desc));
}

From source file:org.apache.solr.cloud.FullSolrCloudTest.java

protected void updateMappingsFromZk(List<JettySolrRunner> jettys, List<SolrServer> clients)
        throws Exception, IOException, KeeperException, URISyntaxException {
    zkStateReader.updateCloudState(true);
    shardToClient.clear();/*  ww w .ja  v  a  2  s  .  c o m*/
    shardToJetty.clear();
    jettyToInfo.clear();

    CloudState cloudState = zkStateReader.getCloudState();
    Map<String, Slice> slices = cloudState.getSlices(DEFAULT_COLLECTION);

    if (slices == null) {
        throw new RuntimeException(
                "No slices found for collection " + DEFAULT_COLLECTION + " in " + cloudState.getCollections());
    }

    for (SolrServer client : clients) {
        // find info for this client in zk 
        nextClient:
        // we find ou state by simply matching ports...
        for (Map.Entry<String, Slice> slice : slices.entrySet()) {
            Map<String, ZkNodeProps> theShards = slice.getValue().getShards();
            for (Map.Entry<String, ZkNodeProps> shard : theShards.entrySet()) {
                int port = new URI(((HttpSolrServer) client).getBaseURL()).getPort();

                if (shard.getKey().contains(":" + port + "_")) {
                    CloudSolrServerClient csc = new CloudSolrServerClient();
                    csc.client = client;
                    csc.shardName = shard.getValue().get(ZkStateReader.NODE_NAME_PROP);
                    boolean isLeader = shard.getValue().containsKey(ZkStateReader.LEADER_PROP);
                    clientToInfo.put(csc, shard.getValue());
                    List<SolrServer> list = shardToClient.get(slice.getKey());
                    if (list == null) {
                        list = new ArrayList<SolrServer>();
                        shardToClient.put(slice.getKey(), list);
                    }
                    list.add(client);

                    if (isLeader) {
                        shardToLeaderClient.put(slice.getKey(), client);
                    }
                    break nextClient;
                }
            }
        }
    }

    for (Map.Entry<String, Slice> slice : slices.entrySet()) {
        // check that things look right
        assertEquals(slice.getValue().getShards().size(), shardToClient.get(slice.getKey()).size());
    }

    for (JettySolrRunner jetty : jettys) {
        int port = jetty.getLocalPort();
        if (port == -1) {
            continue; // If we cannot get the port, this jetty is down
        }

        nextJetty: for (Map.Entry<String, Slice> slice : slices.entrySet()) {
            Map<String, ZkNodeProps> theShards = slice.getValue().getShards();
            for (Map.Entry<String, ZkNodeProps> shard : theShards.entrySet()) {
                if (shard.getKey().contains(":" + port + "_")) {
                    jettyToInfo.put(jetty, shard.getValue());
                    List<CloudJettyRunner> list = shardToJetty.get(slice.getKey());
                    if (list == null) {
                        list = new ArrayList<CloudJettyRunner>();
                        shardToJetty.put(slice.getKey(), list);
                    }
                    boolean isLeader = shard.getValue().containsKey(ZkStateReader.LEADER_PROP);
                    CloudJettyRunner cjr = new CloudJettyRunner();
                    cjr.jetty = jetty;
                    cjr.nodeName = shard.getValue().get(ZkStateReader.NODE_NAME_PROP);
                    cjr.coreNodeName = shard.getKey();
                    list.add(cjr);
                    if (isLeader) {
                        shardToLeaderJetty.put(slice.getKey(), cjr);
                    }
                    break nextJetty;
                }
            }
        }
    }

    // # of jetties may not match replicas in shard here, because we don't map
    // jetties that are not running - every shard should have at least one
    // running jetty though
    for (Map.Entry<String, Slice> slice : slices.entrySet()) {
        // check that things look right
        List<CloudJettyRunner> jetties = shardToJetty.get(slice.getKey());
        assertNotNull("Test setup problem: We found no jetties for shard: " + slice.getKey() + " just:"
                + shardToJetty.keySet(), jetties);
        assertTrue(jetties.size() > 0);
    }
}

From source file:org.opencb.opencga.storage.variant.sqlite.VariantSqliteDBAdaptor.java

@Override
public List<VariantInfo> getRecords(Map<String, String> options) {
    Connection con;//from w ww.j a va 2 s  . co m
    Statement stmt;
    List<VariantInfo> list = new ArrayList<>(100);

    String dbName = options.get("db_name");
    showDb(dbName);
    try {
        Class.forName("org.sqlite.JDBC");
        con = DriverManager.getConnection("jdbc:sqlite:" + dbName);

        List<String> whereClauses = new ArrayList<>(10);

        Map<String, List<String>> sampleGenotypes;
        Map<String, String> controlsMAFs = new LinkedHashMap<>();
        sampleGenotypes = processSamplesGT(options);

        if (options.containsKey("region_list") && !options.get("region_list").equals("")) {

            StringBuilder regionClauses = new StringBuilder("(");
            String[] regions = options.get("region_list").split(",");
            Pattern patternReg = Pattern.compile("(\\w+):(\\d+)-(\\d+)");
            Matcher matcherReg, matcherChr;

            for (int i = 0; i < regions.length; i++) {
                String region = regions[i];
                matcherReg = patternReg.matcher(region);
                if (matcherReg.find()) {
                    String chr = matcherReg.group(1);
                    int start = Integer.valueOf(matcherReg.group(2));
                    int end = Integer.valueOf(matcherReg.group(3));

                    regionClauses.append("( variant_stats.chromosome='").append(chr).append("' AND ");
                    regionClauses.append("variant_stats.position>=").append(start).append(" AND ");
                    regionClauses.append("variant_stats.position<=").append(end).append(" )");

                    if (i < (regions.length - 1)) {
                        regionClauses.append(" OR ");

                    }
                } else {
                    Pattern patternChr = Pattern.compile("(\\w+)");
                    matcherChr = patternChr.matcher(region);

                    if (matcherChr.find()) {
                        String chr = matcherChr.group();
                        regionClauses.append("( variant_stats.chromosome='").append(chr).append("')");

                        if (i < (regions.length - 1)) {
                            regionClauses.append(" OR ");
                        }
                    } else {
                        System.err.println("ERROR: Region (" + region + ")");
                    }
                }
            }
            regionClauses.append(" ) ");
            whereClauses.add(regionClauses.toString());
        }

        if (options.containsKey("chr_pos") && !options.get("chr_pos").equals("")) {

            whereClauses.add("variant_stats.chromosome='" + options.get("chr_pos") + "'");
            if (options.containsKey("start_pos") && !options.get("start_pos").equals("")) {
                whereClauses.add("variant_stats.position>=" + options.get("start_pos"));
            }

            if (options.containsKey("end_pos") && !options.get("end_pos").equals("")) {
                whereClauses.add("variant_stats.position<=" + options.get("end_pos"));
            }
        }

        if (options.containsKey("mend_error") && !options.get("mend_error").equals("")) {
            String val = options.get("mend_error");
            String opt = options.get("option_mend_error");
            whereClauses.add("variant_stats.mendel_err " + opt + " " + val);

        }

        if (options.containsKey("is_indel") && options.get("is_indel").equalsIgnoreCase("on")) {
            whereClauses.add("variant_stats.is_indel=1");
        }

        if (options.containsKey("maf") && !options.get("maf").equals("")) {
            String val = options.get("maf");
            String opt = options.get("option_maf");
            whereClauses.add("variant_stats.maf " + opt + " " + val);

        }

        if (options.containsKey("mgf") && !options.get("mgf").equals("")) {
            String val = options.get("mgf");
            String opt = options.get("option_mgf");
            whereClauses.add("variant_stats.mgf " + opt + " " + val);

        }

        if (options.containsKey("miss_allele") && !options.get("miss_allele").equals("")) {
            String val = options.get("miss_allele");
            String opt = options.get("option_miss_allele");
            whereClauses.add("variant_stats.miss_allele " + opt + " " + val);
        }
        if (options.containsKey("miss_gt") && !options.get("miss_gt").equals("")) {
            String val = options.get("miss_gt");
            String opt = options.get("option_miss_gt");
            whereClauses.add("variant_stats.miss_gt " + opt + " " + val);

        }
        if (options.containsKey("cases_percent_dominant")
                && !options.get("cases_percent_dominant").equals("")) {
            String val = options.get("cases_percent_dominant");
            String opt = options.get("option_cases_dom");
            whereClauses.add("variant_stats.cases_percent_dominant " + opt + " " + val);
        }

        if (options.containsKey("controls_percent_dominant")
                && !options.get("controls_percent_dominant").equals("")) {
            String val = options.get("controls_percent_dominant");
            String opt = options.get("option_controls_dom");
            whereClauses.add("variant_stats.controls_percent_dominant " + opt + " " + val);
        }

        if (options.containsKey("cases_percent_recessive")
                && !options.get("cases_percent_recessive").equals("")) {
            String val = options.get("cases_percent_recessive");
            String opt = options.get("option_cases_rec");
            whereClauses.add("variant_stats.cases_percent_recessive " + opt + " " + val);
        }

        if (options.containsKey("controls_percent_recessive")
                && !options.get("controls_percent_recessive").equals("")) {
            String val = options.get("controls_percent_recessive");
            String opt = options.get("option_controls_rec");
            whereClauses.add("variant_stats.controls_percent_recessive " + opt + " " + val);
        }

        if (options.containsKey("biotype") && !options.get("biotype").equals("")) {
            String[] biotypes = options.get("biotype").split(",");

            StringBuilder biotypesClauses = new StringBuilder(" ( ");

            for (int i = 0; i < biotypes.length; i++) {
                biotypesClauses.append("variant_effect.feature_biotype LIKE '%").append(biotypes[i])
                        .append("%'");

                if (i < (biotypes.length - 1)) {
                    biotypesClauses.append(" OR ");
                }
            }

            biotypesClauses.append(" ) ");
            whereClauses.add(biotypesClauses.toString());
        }

        if (options.containsKey("exc_1000g_controls")
                && options.get("exc_1000g_controls").equalsIgnoreCase("on")) {
            whereClauses.add("(key NOT LIKE '1000G%' OR key is null)");
        } else if (options.containsKey("maf_1000g_controls") && !options.get("maf_1000g_controls").equals("")) {
            controlsMAFs.put("1000G", options.get("maf_1000g_controls"));
        }

        if (options.containsKey("exc_bier_controls")
                && options.get("exc_bier_controls").equalsIgnoreCase("on")) {
            whereClauses.add("(key NOT LIKE 'BIER%' OR key is null)");
        } else if (options.containsKey("maf_bier_controls") && !options.get("maf_bier_controls").equals("")) {
            controlsMAFs.put("BIER", options.get("maf_bier_controls"));
        }

        if (options.containsKey("exc_evs_controls") && options.get("exc_evs_controls").equalsIgnoreCase("on")) {
            whereClauses.add("(key NOT LIKE 'EVS%' OR key is null)");
        } else if (options.containsKey("maf_evs_controls") && !options.get("maf_evs_controls").equals("")) {
            controlsMAFs.put("BIER", options.get("maf_evs_controls"));
        }

        if (options.containsKey("conseq_type[]") && !options.get("conseq_type[]").equals("")) {
            whereClauses.add(processConseqType(options.get("conseq_type[]")));
        }

        if (options.containsKey("genes") && !options.get("genes").equals("")) {
            whereClauses.add(processGeneList(options.get("genes")));
            //                processGeneList(options.get("genes"));
        }

        if (sampleGenotypes.size() > 0) {
            StringBuilder sg = new StringBuilder();
            int csg = 0;
            sg.append("(");
            for (Map.Entry<String, List<String>> entry : sampleGenotypes.entrySet()) {
                sg.append("(");
                sg.append("sample_name='").append(entry.getKey()).append("' AND (");

                for (int i = 0; i < entry.getValue().size(); i++) {
                    String[] aux = entry.getValue().get(i).split("/");
                    sg.append("(");
                    sg.append("allele_1=").append(aux[0]).append(" AND allele_2=").append(aux[1]);
                    sg.append(")");

                    if (i + 1 < entry.getValue().size()) {
                        sg.append(" OR ");
                    }
                }

                sg.append(")");

                sg.append(" OR sample_name<>'").append(entry.getKey()).append("'");

                sg.append(")");

                if (csg + 1 < sampleGenotypes.entrySet().size()) {
                    sg.append(" AND ");
                }
                csg++;
            }
            sg.append(")");
            System.out.println(sg);
            whereClauses.add(sg.toString());
        }

        String sql = "SELECT count(*) as count FROM sample ;";

        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        int numSamples = 0;

        while (rs.next()) {

            numSamples = rs.getInt("count");
        }

        stmt.close();

        System.out.println("controlsMAFs = " + controlsMAFs);

        System.out.println("sampleGenotypes = " + sampleGenotypes);

        String innerJoinVariantSQL = " left join variant_info on variant.id_variant=variant_info.id_variant ";
        //            String innerJoinEffectSQL = " inner join variant_effect on variant_effect.chromosome=variant.chromosome AND variant_effect.position=variant.position AND variant_effect.reference_allele=variant.ref AND variant_effect.alternative_allele = variant.alt ";

        sql = "SELECT distinct variant.genes,variant.consequence_types, variant.id_variant, variant_info.key, variant_info.value, sample_info.sample_name, sample_info.allele_1, sample_info.allele_2, variant_stats.chromosome ,"
                + "variant_stats.position , variant_stats.allele_ref , variant_stats.allele_alt , variant_stats.id , variant_stats.maf , variant_stats.mgf, "
                + "variant_stats.allele_maf , variant_stats.genotype_maf , variant_stats.miss_allele , variant_stats.miss_gt , variant_stats.mendel_err ,"
                + "variant_stats.is_indel , variant_stats.cases_percent_dominant , variant_stats.controls_percent_dominant , variant_stats.cases_percent_recessive , variant_stats.controls_percent_recessive, "
                + "variant.polyphen_score, variant.polyphen_effect, variant.sift_score, variant.sift_effect "
                + " FROM variant_stats "
                + "inner join variant on variant_stats.chromosome=variant.chromosome AND variant_stats.position=variant.position AND variant_stats.allele_ref=variant.ref AND variant_stats.allele_alt=variant.alt "
                + "inner join sample_info on variant.id_variant=sample_info.id_variant " + innerJoinVariantSQL;

        if (whereClauses.size() > 0) {
            StringBuilder where = new StringBuilder(" where ");

            for (int i = 0; i < whereClauses.size(); i++) {
                where.append(whereClauses.get(i));
                if (i < whereClauses.size() - 1) {
                    where.append(" AND ");
                }
            }

            sql += where.toString()
                    + " ORDER BY variant_stats.chromosome , variant_stats.position , variant_stats.allele_ref , variant_stats.allele_alt ;";
        }

        System.out.println(sql);

        System.out.println("Start SQL");
        long start = System.currentTimeMillis();
        stmt = con.createStatement();

        rs = stmt.executeQuery(sql);

        VariantStats vs;
        VariantInfo vi = null;

        String chr = "";
        int pos = 0;
        String ref = "", alt = "";

        System.out.println("End SQL: " + ((System.currentTimeMillis() - start) / 1000.0) + " s.");
        System.out.println("Processing");

        while (rs.next()) {
            if (!rs.getString("chromosome").equals(chr) || rs.getInt("position") != pos
                    || !rs.getString("allele_ref").equals(ref) || !rs.getString("allele_alt").equals(alt)) {

                chr = rs.getString("chromosome");
                pos = rs.getInt("position");
                ref = rs.getString("allele_ref");
                alt = rs.getString("allele_alt");

                if (vi != null && filterGenotypes(vi, numSamples) && filterControls(vi, controlsMAFs)) {
                    list.add(vi);
                }
                vi = new VariantInfo(chr, pos, ref, alt);
                vs = new VariantStats(chr, pos, ref, alt, rs.getDouble("maf"), rs.getDouble("mgf"),
                        rs.getString("allele_maf"), rs.getString("genotype_maf"), rs.getInt("miss_allele"),
                        rs.getInt("miss_gt"), rs.getInt("mendel_err"), rs.getInt("is_indel") == 1,
                        rs.getDouble("cases_percent_dominant"), rs.getDouble("controls_percent_dominant"),
                        rs.getDouble("cases_percent_recessive"), rs.getDouble("controls_percent_recessive"));
                vs.setId(rs.getString("id"));

                // vi.addGenotypes(rs.getString("genotypes"));

                vi.addStats(vs);
                vi.addGenes(rs.getString("genes"));
                vi.addConsequenceTypes(rs.getString("consequence_types"));
                vi.setPolyphen_score(rs.getDouble("polyphen_score"));
                vi.setSift_score(rs.getDouble("sift_score"));
                vi.setPolyphen_effect(rs.getInt("polyphen_effect"));
                vi.setSift_effect(rs.getInt("sift_effect"));

            }

            if (rs.getString("key") != null && rs.getString("value") != null) {
                vi.addControl(rs.getString("key"), rs.getString("value"));
            }

            String sample = rs.getString("sample_name");
            String gt = rs.getInt("allele_1") + "/" + rs.getInt("allele_2");

            vi.addSammpleGenotype(sample, gt);
            // vi.addGeneAndConsequenceType(rs.getString("gene_name"), rs.getString("consequence_type_obo"));

        }

        if (vi != null && filterGenotypes(vi, numSamples) && filterControls(vi, controlsMAFs)) {
            list.add(vi);
        }
        stmt.close();

        System.out.println("Total: (" + list.size() + ")");
        System.out.println("End processing: " + ((System.currentTimeMillis() - start) / 1000.0) + " s.");

        con.close();

    } catch (ClassNotFoundException | SQLException e) {
        System.err.println("STATS: " + e.getClass().getName() + ": " + e.getMessage());
    }

    return list;
}

From source file:edu.emory.cci.aiw.umls.UMLSDatabaseConnection.java

@Override
public Map<String, MapToIdResult<AtomUID>> mapToAUI(String phrase, List<SAB> sab) throws UMLSQueryException {
    Map<String, MapToIdResult<AtomUID>> result = new HashMap<String, MapToIdResult<AtomUID>>();
    try {//  w  w w  .j  a  v  a 2s.  com
        setupConn();
        Map<String, List<String>> matches = matches(phrase, mapToId(phrase, IdType.AUI_IDTYPE, sab));
        if (matches.containsKey(phrase)) {
            for (Map.Entry<String, List<String>> entry : matches.entrySet()) {
                result.put(entry.getKey(),
                        MapToIdResult.<AtomUID>fromUidAndStr(AtomUID.fromString(entry.getValue().get(0)),
                                UMLSQueryStringValue.fromString(entry.getValue().get(1))));
            }
            return result;
        } else {
            String[] words = phrase.split("\\s");
            for (String[] p : allLengthPermutations(words)) {
                if (p.length == 1 && p[0].length() < 4) {
                    continue;
                }
                String permutedString = StringUtils.join(p, ' ');
                matches = (matches(permutedString, mapToId(permutedString, IdType.AUI_IDTYPE, sab)));
                for (Map.Entry<String, List<String>> entry : matches.entrySet()) {
                    result.put(entry.getKey(),
                            MapToIdResult.<AtomUID>fromUidAndStr(AtomUID.fromString(entry.getValue().get(0)),
                                    UMLSQueryStringValue.fromString(entry.getValue().get(1))));
                }
            }
            return result;
        }
    } catch (SQLException sqle) {
        throw new UMLSQueryException(sqle);
    } catch (MalformedUMLSUniqueIdentifierException muuie) {
        throw new UMLSQueryException(muuie);
    } finally {
        tearDownConn();
    }
}

From source file:edu.emory.cci.aiw.umls.UMLSDatabaseConnection.java

@Override
public Map<String, MapToIdResult<StringUID>> mapToSUI(String phrase, List<SAB> sab) throws UMLSQueryException {
    Map<String, MapToIdResult<StringUID>> result = new HashMap<String, MapToIdResult<StringUID>>();
    try {/*from w w w  .  j a  v a  2  s  .co  m*/
        setupConn();
        Map<String, List<String>> matches = matches(phrase, mapToId(phrase, IdType.CUI_IDTYPE, sab));
        if (matches.containsKey(phrase)) {
            for (Map.Entry<String, List<String>> entry : matches.entrySet()) {
                result.put(entry.getKey(),
                        MapToIdResult.<StringUID>fromUidAndStr(StringUID.fromString(entry.getValue().get(0)),
                                UMLSQueryStringValue.fromString(entry.getValue().get(1))));
            }
            return result;
        } else {
            String[] words = phrase.split("\\s");
            for (String[] p : allLengthPermutations(words)) {
                if (p.length == 1 && p[0].length() < 4) {
                    continue;
                }
                String permutedString = StringUtils.join(p, ' ');
                matches = (matches(permutedString, mapToId(permutedString, IdType.CUI_IDTYPE, sab)));
                for (Map.Entry<String, List<String>> entry : matches.entrySet()) {
                    result.put(entry.getKey(),
                            MapToIdResult.<StringUID>fromUidAndStr(
                                    StringUID.fromString(entry.getValue().get(0)),
                                    UMLSQueryStringValue.fromString(entry.getValue().get(1))));
                }
            }
            return result;
        }
    } catch (SQLException sqle) {
        throw new UMLSQueryException(sqle);
    } catch (MalformedUMLSUniqueIdentifierException muuie) {
        throw new UMLSQueryException(muuie);
    } finally {
        tearDownConn();
    }
}

From source file:edu.emory.cci.aiw.umls.UMLSDatabaseConnection.java

@Override
public Map<String, MapToIdResult<ConceptUID>> mapToCUI(String phrase, List<SAB> sab) throws UMLSQueryException {
    Map<String, MapToIdResult<ConceptUID>> result = new HashMap<String, MapToIdResult<ConceptUID>>();
    try {/* w ww .  j a v  a 2 s . co m*/
        setupConn();
        Map<String, List<String>> matches = matches(phrase, mapToId(phrase, IdType.CUI_IDTYPE, sab));
        if (matches.containsKey(phrase)) {
            for (Map.Entry<String, List<String>> entry : matches.entrySet()) {
                result.put(entry.getKey(),
                        MapToIdResult.<ConceptUID>fromUidAndStr(ConceptUID.fromString(entry.getValue().get(0)),
                                UMLSQueryStringValue.fromString(entry.getValue().get(1))));
            }
            return result;
        } else {
            String[] words = phrase.split("\\s");
            for (String[] p : allLengthPermutations(words)) {
                if (p.length == 1 && p[0].length() < 4) {
                    continue;
                }
                String permutedString = StringUtils.join(p, ' ');
                matches = (matches(permutedString, mapToId(permutedString, IdType.CUI_IDTYPE, sab)));
                for (Map.Entry<String, List<String>> entry : matches.entrySet()) {
                    result.put(entry.getKey(),
                            MapToIdResult.<ConceptUID>fromUidAndStr(
                                    ConceptUID.fromString(entry.getValue().get(0)),
                                    UMLSQueryStringValue.fromString(entry.getValue().get(1))));
                }
            }
            return result;
        }
    } catch (SQLException sqle) {
        throw new UMLSQueryException(sqle);
    } catch (MalformedUMLSUniqueIdentifierException muuie) {
        throw new UMLSQueryException(muuie);
    } finally {
        tearDownConn();
    }
}

From source file:edu.emory.cci.aiw.umls.UMLSDatabaseConnection.java

@Override
public Map<String, MapToIdResult<LexicalUID>> mapToLUI(String phrase, List<SAB> sab) throws UMLSQueryException {
    Map<String, MapToIdResult<LexicalUID>> result = new HashMap<String, MapToIdResult<LexicalUID>>();
    try {/* w  ww  .j a v a  2s  . c o m*/
        setupConn();
        Map<String, List<String>> matches = matches(phrase, mapToId(phrase, IdType.LUI_IDTYPE, sab));
        if (matches.containsKey(phrase)) {
            for (Map.Entry<String, List<String>> entry : matches.entrySet()) {
                result.put(entry.getKey(),
                        MapToIdResult.<LexicalUID>fromUidAndStr(LexicalUID.fromString(entry.getValue().get(0)),
                                UMLSQueryStringValue.fromString(entry.getValue().get(1))));
            }
            return result;
        } else {
            String[] words = phrase.split("\\s");
            for (String[] p : allLengthPermutations(words)) {
                if (p.length == 1 && p[0].length() < 4) {
                    continue;
                }
                String permutedString = StringUtils.join(p, ' ');
                matches = (matches(permutedString, mapToId(permutedString, IdType.LUI_IDTYPE, sab)));
                for (Map.Entry<String, List<String>> entry : matches.entrySet()) {
                    result.put(entry.getKey(),
                            MapToIdResult.<LexicalUID>fromUidAndStr(
                                    LexicalUID.fromString(entry.getValue().get(0)),
                                    UMLSQueryStringValue.fromString(entry.getValue().get(1))));
                }
            }
            return result;
        }
    } catch (SQLException sqle) {
        throw new UMLSQueryException(sqle);
    } catch (MalformedUMLSUniqueIdentifierException muuie) {
        throw new UMLSQueryException(muuie);
    } finally {
        tearDownConn();
    }
}

From source file:org.apache.falcon.resource.AbstractEntityManager.java

private boolean isEntityFiltered(Entity entity, EntityList.EntityFilterByFields filter,
        Map.Entry<String, List<String>> pair) {
    switch (filter) {
    case TYPE:/*from  w  w w  .j  a v  a  2s.  c o  m*/
        return !containsIgnoreCase(pair.getValue(), entity.getEntityType().toString());

    case NAME:
        return !containsIgnoreCase(pair.getValue(), entity.getName());

    case STATUS:
        return !containsIgnoreCase(pair.getValue(), getStatusString(entity));

    case PIPELINES:
        if (!entity.getEntityType().equals(EntityType.PROCESS)) {
            throw FalconWebException.newException(
                    "Invalid filterBy key for non process entities " + pair.getKey(),
                    Response.Status.BAD_REQUEST);
        }
        return !EntityUtil.getPipelines(entity).contains(pair.getValue().get(0));

    case CLUSTER:
        return !EntityUtil.getClustersDefined(entity).contains(pair.getValue().get(0));

    case TAGS:
        return isFilteredByTags(getFilterByTags(pair.getValue()), EntityUtil.getTags(entity));

    default:
        return false;
    }
}