@Test(groups = "dev")
  public void autoWrapTest() throws EventDeliveryException {
    ctx.put(MongoSink.AUTO_WRAP, Boolean.toString(true));
    ctx.put(MongoSink.DB_NAME, "test_wrap");

    MongoSink sink = new MongoSink();
    Configurables.configure(sink, ctx);

    sink.setChannel(channel);
    sink.start();

    Transaction tx = channel.getTransaction();
    tx.begin();
    String msg =
        "2012/10/26 11:23:08 [error] 7289#0: *6430831 open() \"/usr/local/nginx/html/50x.html\" failed (2: No such file or directory), client: 10.160.105.161, server: sg15.redatoms.com, request: \"POST /mojo/ajax/embed HTTP/1.0\", upstream: \"fastcgi://unix:/tmp/php-fpm.sock:\", host: \"sg15.redatoms.com\", referrer: \"http://sg15.redatoms.com/mojo/mobile/package\"";

    Event e = EventBuilder.withBody(msg.getBytes());
    channel.put(e);
    tx.commit();
    tx.close();

    sink.process();
    sink.stop();

    DB db = mongo.getDB("test_wrap");
    DBCollection collection = db.getCollection("test_log");
    DBCursor cursor = collection.find(new BasicDBObject(MongoSink.DEFAULT_WRAP_FIELD, msg));
    assertTrue(cursor.hasNext());
    DBObject dbObject = cursor.next();
    assertNotNull(dbObject);
    assertEquals(dbObject.get(MongoSink.DEFAULT_WRAP_FIELD), msg);
    mongo.dropDatabase("test_wrap");
  }
  @Test(groups = "dev")
  public void sinkSingleModelTest() throws EventDeliveryException {
    ctx.put(MongoSink.MODEL, MongoSink.CollectionModel.single.name());

    MongoSink sink = new MongoSink();
    Configurables.configure(sink, ctx);

    sink.setChannel(channel);
    sink.start();

    Transaction tx = channel.getTransaction();
    tx.begin();
    JSONObject msg = new JSONObject();
    msg.put("name", "test");
    msg.put("age", 11);
    msg.put("birthday", new Date().getTime());

    Event e = EventBuilder.withBody(msg.toJSONString().getBytes());
    channel.put(e);
    tx.commit();
    tx.close();

    sink.process();
    sink.stop();

    DB db = mongo.getDB("test_events");
    DBCollection collection = db.getCollection("test_log");
    DBCursor cursor = collection.find(new BasicDBObject(msg));
    assertTrue(cursor.hasNext());
    DBObject dbObject = cursor.next();
    assertNotNull(dbObject);
    assertEquals(dbObject.get("name"), msg.get("name"));
    assertEquals(dbObject.get("age"), msg.get("age"));
    assertEquals(dbObject.get("birthday"), msg.get("birthday"));
  }
Ejemplo n.º 3
0
 /**
  * Returns an object containing basic information about the execution of the query that created
  * this cursor This creates a <code>DBObject</code> with the key/value pairs: "cursor" : cursor
  * type "nScanned" : number of records examined by the database for this query "n" : the number of
  * records that the database returned "millis" : how long it took the database to execute the
  * query
  *
  * @return a <code>DBObject</code>
  * @dochub explain
  */
 public DBObject explain() {
   DBCursor c = copy();
   c._explain = true;
   if (c._limit > 0) {
     // need to pass a negative batchSize as limit for explain
     c._batchSize = c._limit * -1;
     c._limit = 0;
   }
   return c.next();
 }
  @Test(groups = "dev")
  public void timestampExistingFieldTest() throws EventDeliveryException, ParseException {
    ctx.put(MongoSink.MODEL, MongoSink.CollectionModel.dynamic.name());
    String tsField = "createdOn";
    ctx.put(MongoSink.TIMESTAMP_FIELD, tsField);
    MongoSink sink = new MongoSink();
    Configurables.configure(sink, ctx);

    sink.setChannel(channel);
    sink.start();

    JSONObject msg = new JSONObject();
    msg.put("age", 11);
    msg.put("birthday", new Date().getTime());
    String dateText = "2013-02-19T14:20:53+08:00";
    msg.put(tsField, dateText);

    Transaction tx;

    for (int i = 0; i < 10; i++) {
      tx = channel.getTransaction();
      tx.begin();
      msg.put("name", "test" + i);
      JSONObject header = new JSONObject();
      header.put(MongoSink.COLLECTION, "my_events");
      header.put(MongoSink.DB_NAME, "dynamic_db");

      Event e = EventBuilder.withBody(msg.toJSONString().getBytes(), header);
      channel.put(e);
      tx.commit();
      tx.close();
    }
    sink.process();
    sink.stop();

    msg.put(tsField, MongoSink.dateTimeFormatter.parseDateTime(dateText).toDate());
    for (int i = 0; i < 10; i++) {
      msg.put("name", "test" + i);

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

      DB db = mongo.getDB("dynamic_db");
      DBCollection collection = db.getCollection("my_events");
      DBCursor cursor = collection.find(new BasicDBObject(msg));
      assertTrue(cursor.hasNext());
      DBObject dbObject = cursor.next();
      assertNotNull(dbObject);
      assertEquals(dbObject.get("name"), msg.get("name"));
      assertEquals(dbObject.get("age"), msg.get("age"));
      assertEquals(dbObject.get("birthday"), msg.get("birthday"));
      assertTrue(dbObject.get(tsField) instanceof Date);
      System.out.println("ts = " + dbObject.get(tsField));
    }
  }
  public Collection<SpaceTypeDescriptor> loadMetadata() {

    DBCollection metadata = getCollection(METADATA_COLLECTION_NAME);

    DBCursor cursor = metadata.find(new BasicDBObject());

    while (cursor.hasNext()) {
      DBObject type = cursor.next();

      Object b = type.get(TYPE_DESCRIPTOR_FIELD_NAME);

      readMetadata(b);
    }

    return getSortedTypes();
  }
  @Test(groups = "dev")
  public void sinkDynamicDbTest() throws EventDeliveryException {
    ctx.put(MongoSink.MODEL, MongoSink.CollectionModel.dynamic.name());
    MongoSink sink = new MongoSink();
    Configurables.configure(sink, ctx);

    sink.setChannel(channel);
    sink.start();

    JSONObject msg = new JSONObject();
    msg.put("age", 11);
    msg.put("birthday", new Date().getTime());

    Transaction tx;

    for (int i = 0; i < 10; i++) {
      tx = channel.getTransaction();
      tx.begin();
      msg.put("name", "test" + i);
      JSONObject header = new JSONObject();
      header.put(MongoSink.COLLECTION, "my_events");
      header.put(MongoSink.DB_NAME, "dynamic_db");

      Event e = EventBuilder.withBody(msg.toJSONString().getBytes(), header);
      channel.put(e);
      tx.commit();
      tx.close();
    }
    sink.process();
    sink.stop();

    for (int i = 0; i < 10; i++) {
      msg.put("name", "test" + i);

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

      DB db = mongo.getDB("dynamic_db");
      DBCollection collection = db.getCollection("my_events");
      DBCursor cursor = collection.find(new BasicDBObject(msg));
      assertTrue(cursor.hasNext());
      DBObject dbObject = cursor.next();
      assertNotNull(dbObject);
      assertEquals(dbObject.get("name"), msg.get("name"));
      assertEquals(dbObject.get("age"), msg.get("age"));
      assertEquals(dbObject.get("birthday"), msg.get("birthday"));
    }
  }
Ejemplo n.º 7
0
 /**
  * Creates a copy of an existing database cursor. The new cursor is an iterator, even if the
  * original was an array.
  *
  * @return the new cursor
  */
 public DBCursor copy() {
   DBCursor c = new DBCursor(_collection, _query, _keysWanted, _readPref);
   c._orderBy = _orderBy;
   c._hint = _hint;
   c._hintDBObj = _hintDBObj;
   c._limit = _limit;
   c._skip = _skip;
   c._options = _options;
   c._batchSize = _batchSize;
   c._snapshot = _snapshot;
   c._explain = _explain;
   if (_specialFields != null) c._specialFields = new BasicDBObject(_specialFields.toMap());
   return c;
 }
Ejemplo n.º 8
0
    public TaskWrite(Map map1, Map m_max, Map m_min, DBCollection coll, ModbusSlaveSet slave) {

      try {
        synchronized (slave) {
          Calendar calener = Calendar.getInstance();
          Date d1 = calener.getTime();
          Date d2 = new Date(calener.getTime().getTime() - 5000);
          BasicDBObject b2 = new BasicDBObject();
          b2.put("$gte", d2);
          b2.put("$lte", d1);
          DBCursor cursor =
              coll.find(new BasicDBObject("_id", b2)).sort(new BasicDBObject("_id", -1)).limit(1);
          while (cursor.hasNext()) {
            DBObject dbo = cursor.next();
            Set set1 = map1.entrySet();
            Iterator it1 = set1.iterator();
            while (it1.hasNext()) {
              Map.Entry<String, Map<String, String>> entry =
                  (Map.Entry<String, Map<String, String>>) it1.next();
              Map<String, String> map2 = entry.getValue();
              for (Iterator it2 = map2.entrySet().iterator(); it2.hasNext(); ) {
                Map.Entry<String, String> entry2 = (Map.Entry<String, String>) it2.next();
                String name = entry2.getKey().toString();
                String paramAddr = entry2.getValue().toString();
                int fun = (int) (Double.parseDouble(paramAddr));
                if (paramAddr.substring(0, 1).equals("4")) {
                  double value = Double.parseDouble(dbo.get(name).toString());
                  double dmax = (Double) m_max.get(name);
                  double dmin = (Double) m_min.get(name);
                  double dValue = 0;
                  if (value > dmax || value < dmin) {
                    if (value >= 0) {
                      dValue = 32000 * (int) (value / dmax);
                    }
                    if (value < 0) {
                      dValue = -32000 * (int) (value / dmin);
                    }
                    // slave.getProcessImage(3).setInputRegister(fun % 10000, (short) dValue);
                  } else { /// 参数超限报警
                    JOptionPane.showMessageDialog(null, "参数超限");
                    slave.stop();
                  }
                }
                if (paramAddr.substring(0, 1).equals("3")) {
                  double value = Double.parseDouble(dbo.get(name).toString());
                  double dmax = (Double) m_max.get(name);
                  double dmin = (Double) m_min.get(name);
                  double dValue = 0;
                  if (value > dmax || value < dmin) {
                    if (value >= 0) {
                      dValue = 32000 * (int) (value / dmax);
                    }
                    if (value < 0) {
                      dValue = -32000 * (int) (value / dmin);
                    }
                    // slave.getProcessImage(3).setHoldingRegister(fun % 10000, (short) dValue);
                  } else { /// 参数超限报警
                    JOptionPane.showMessageDialog(null, "参数超限");
                    slave.stop();
                  }
                  ;
                }
                if (paramAddr.substring(0, 1).equals("2")) {
                  String value = dbo.get(name).toString();
                  /// slave.getProcessImage(4).setInput(fun % 10000, Boolean.valueOf(value));
                }
                if (paramAddr.substring(0, 1).equals("1")) {
                  String value = dbo.get(name).toString();
                  // slave.getProcessImage(4).setCoil(fun % 10000, Boolean.valueOf(value));
                }
              }
            }
          }
        }
      } catch (Exception ex) {
      }
    }
Ejemplo n.º 9
0
  public void receiveData(
      String ip,
      String paramName,
      String paramNo,
      int paramBote,
      int paramLength,
      int parmParity,
      int parmStopBit,
      int parmDelay) {
    try {
      try {
        m = new Mongo(ip, 27017);
        db = m.getDB(paramName);
        // db.authenticate("test", "123".toCharArray());
      } catch (UnknownHostException ex) {
        ex.printStackTrace();
      } catch (MongoException e) {
        e.printStackTrace();
      }
      final DBCollection coll = db.getCollection("DATAIN");
      final DBCollection collout = db.getCollection("DATAOUT");
      DBCollection meta = db.getCollection("META");

      // 记录数据字段
      final Map map1 = new HashMap();
      final Map map2 = new HashMap();
      Map map00 = new HashMap();
      Map map01 = new HashMap();
      Map map02 = new HashMap();
      Map map03 = new HashMap();

      final Map m_ai_max = new HashMap();
      final Map m_ai_min = new HashMap();
      final Map m_ao_max = new HashMap();
      final Map m_ao_min = new HashMap();

      DBCursor cursor = meta.find();
      while (cursor.hasNext()) {
        // 记录数据类型
        DBObject dbo = cursor.next();
        String name = dbo.get("_id").toString();
        String type = dbo.get("type").toString();
        String addr = dbo.get("addr").toString();
        Double max = (Double) dbo.get("max");
        Double min = (Double) dbo.get("min");
        if (type.equals("AI")) {
          map00.put(name, addr);
          m_ai_max.put(name, max);
          m_ai_min.put(name, min);
        }
        if (type.equals("DI")) {
          map01.put(name, addr);
        }
        if (type.equals("AO")) {
          map02.put(name, addr);
        }
        if (type.equals("DO")) {
          map03.put(name, addr);
        }
      }
      map1.put("AI", map00);
      map1.put("DI", map01);

      map2.put("AO", map02);
      map2.put("DO", map03);

      SerialParameters params = new SerialParameters();
      params.setCommPortId(paramNo);
      params.setBaudRate(paramBote);
      params.setDataBits(paramLength);
      params.setParity(parmParity);
      params.setStopBits(parmStopBit);
      ModbusFactory modbusFactory = new ModbusFactory();
      slave = modbusFactory.createRtuSlave(params);

      slave.addProcessImage(getModscanProcessImage(1, map00, coll));
      slave.addProcessImage(getModscanProcessImage(2, map01, coll));
      slave.addProcessImage(getModscanProcessImage(3, map02, collout));
      slave.addProcessImage(getModscanProcessImage(4, map03, collout));
      new Thread(
              new Runnable() {
                public void run() {
                  try {
                    slave.start();
                    // JOptionPane.showMessageDialog(f, "通讯连接成功!");
                  } catch (ModbusInitException e) {
                    e.printStackTrace();
                  }
                }
              })
          .start();
      ScheduledExecutorService timerRead = Executors.newScheduledThreadPool(1);
      timerRead.scheduleAtFixedRate(
          new Runnable() {
            public void run() {
              new TaskRead(map1, m_ai_max, m_ai_min, coll, slave);
            }
          },
          500,
          parmDelay,
          TimeUnit.MILLISECONDS);
      ScheduledExecutorService timerWrite = Executors.newScheduledThreadPool(2);
      timerWrite.scheduleAtFixedRate(
          new Runnable() {
            public void run() {
              new TaskWrite(map2, m_ao_max, m_ao_min, collout, slave);
            }
          },
          500,
          parmDelay,
          TimeUnit.MILLISECONDS);
    } catch (Exception ex) {
    }
  }
  public QueryResult<VariantInfo> getRecordsMongo(
      int page, int start, int limit, MutableInt count, Map<String, String> options) {

    long startTime = System.currentTimeMillis();
    QueryResult<VariantInfo> queryResult = new QueryResult<>();

    List<VariantInfo> res = new ArrayList<>();
    String sourceId = options.get("studyId");
    DBCollection coll = db.getCollection("variants");

    BasicDBObject elemMatch = new BasicDBObject("sourceId", sourceId);
    DBObject query = new BasicDBObject();
    BasicDBList orList = new BasicDBList();

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

    System.out.println("map = " + options);

    if (options.containsKey("region") && !options.get("region").equals("")) {
      String[] regions = options.get("region").split(",");
      Pattern pattern = Pattern.compile("(\\w+):(\\d+)-(\\d+)");
      Matcher matcher, matcherChr;

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

          DBObject regionClause = new BasicDBObject("chr", chr);
          regionClause.put("pos", new BasicDBObject("$gte", s).append("$lte", e));
          orList.add(regionClause);
        } else {

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

          if (matcherChr.find()) {
            String chr = matcherChr.group();
            DBObject regionClause = new BasicDBObject("chr", chr);
            orList.add(regionClause);
          }
        }
      }
      query.put("$or", orList);

    } else if (options.containsKey("genes") && !options.get("genes").equals("")) {
      orList = processGeneList(options.get("genes"));
      if (orList.size() > 0) {
        query.put("$or", orList);
      } else {
        queryResult.setWarningMsg("Wrong gene name");
        queryResult.setResult(res);
        queryResult.setNumResults(res.size());
        return queryResult;
      }
    }

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

      BasicDBList ctList = new BasicDBList();
      for (String ct : cts) {
        ctList.add(ct);
      }
      elemMatch.put("effects", new BasicDBObject("$in", ctList));
    }

    if (sampleGenotypes.size() > 0) {
      for (Map.Entry<String, List<String>> entry : sampleGenotypes.entrySet()) {
        BasicDBList gtList = new BasicDBList();
        for (String gt : entry.getValue()) {
          gtList.add(gt);
        }
        elemMatch.put("samples." + entry.getKey() + ".GT", new BasicDBObject("$in", gtList));
      }
    }

    if (options.containsKey("miss_gt") && !options.get("miss_gt").equalsIgnoreCase("")) {
      Integer val = Integer.valueOf(options.get("miss_gt"));
      Object missGt = getMongoOption(options.get("option_miss_gt"), val);
      elemMatch.put("stats.missGenotypes", missGt);
    }

    BasicDBList andControls = new BasicDBList();

    if (options.containsKey("maf_1000g_controls")
        && !options.get("maf_1000g_controls").equalsIgnoreCase("")) {
      BasicDBList or = new BasicDBList();
      or.add(new BasicDBObject("attributes.1000G_maf", new BasicDBObject("$exists", false)));
      or.add(
          new BasicDBObject(
              "attributes.1000G_maf",
              new BasicDBObject("$lte", options.get("maf_1000g_controls"))));

      andControls.add(new BasicDBObject("$or", or));
    }

    if (options.containsKey("maf_1000g_afr_controls")
        && !options.get("maf_1000g_afr_controls").equalsIgnoreCase("")) {
      BasicDBList or = new BasicDBList();
      or.add(new BasicDBObject("attributes.1000G_AFR_maf", new BasicDBObject("$exists", false)));
      or.add(
          new BasicDBObject(
              "attributes.1000G_AFR_maf",
              new BasicDBObject("$lte", options.get("maf_1000g_afr_controls"))));

      andControls.add(new BasicDBObject("$or", or));
    }

    if (options.containsKey("maf_1000g_asi_controls")
        && !options.get("maf_1000g_asi_controls").equalsIgnoreCase("")) {
      BasicDBList or = new BasicDBList();
      or.add(new BasicDBObject("attributes.1000G_ASI_maf", new BasicDBObject("$exists", false)));
      or.add(
          new BasicDBObject(
              "attributes.1000G_ASI_maf",
              new BasicDBObject("$lte", options.get("maf_1000g_asi_controls"))));

      andControls.add(new BasicDBObject("$or", or));
    }

    if (options.containsKey("maf_1000g_eur_controls")
        && !options.get("maf_1000g_eur_controls").equalsIgnoreCase("")) {
      System.out.print("EUR");
      BasicDBList or = new BasicDBList();
      or.add(new BasicDBObject("attributes.1000G_EUR_maf", new BasicDBObject("$exists", false)));
      or.add(
          new BasicDBObject(
              "attributes.1000G_EUR_maf",
              new BasicDBObject("$lte", options.get("maf_1000g_eur_controls"))));

      andControls.add(new BasicDBObject("$or", or));
    }
    if (options.containsKey("maf_1000g_ame_controls")
        && !options.get("maf_1000g_ame_controls").equalsIgnoreCase("")) {
      System.out.print("AME");
      BasicDBList or = new BasicDBList();
      or.add(new BasicDBObject("attributes.1000G_AME_maf", new BasicDBObject("$exists", false)));
      or.add(
          new BasicDBObject(
              "attributes.1000G_AME_maf",
              new BasicDBObject("$lte", options.get("maf_1000g_ame_controls"))));

      andControls.add(new BasicDBObject("$or", or));
    }
    if (options.containsKey("maf_evs_controls")
        && !options.get("maf_evs_controls").equalsIgnoreCase("")) {
      BasicDBList or = new BasicDBList();
      or.add(new BasicDBObject("attributes.EVS_maf", new BasicDBObject("$exists", false)));
      or.add(
          new BasicDBObject(
              "attributes.EVS_maf", new BasicDBObject("$lte", options.get("maf_evs_controls"))));

      andControls.add(new BasicDBObject("$or", or));
    }

    if (options.containsKey("maf_bier_controls")
        && !options.get("maf_bier_controls").equalsIgnoreCase("")) {
      BasicDBList or = new BasicDBList();
      or.add(new BasicDBObject("attributes.BIER_maf", new BasicDBObject("$exists", false)));
      or.add(
          new BasicDBObject(
              "attributes.BIER_maf", new BasicDBObject("$lte", options.get("maf_bier_controls"))));

      andControls.add(new BasicDBObject("$or", or));
    }

    if (andControls.size() > 0) {
      elemMatch.append("$and", andControls);
    }

    query.put("sources", new BasicDBObject("$elemMatch", elemMatch));

    System.out.println("#############################");
    System.out.println(query);
    System.out.println("#############################");

    long dbStart = System.currentTimeMillis();

    DBObject sort = null;
    DBCursor cursor;

    if (options.containsKey("sort")) {
      sort = getQuerySort(options.get("sort"));
      cursor = coll.find(query).sort(sort).skip(start).limit(limit);
    } else {
      cursor = coll.find(query).skip(start).limit(limit);
    }

    count.setValue(cursor.count());

    queryResult.setDbTime(dbStart - System.currentTimeMillis());

    for (DBObject obj : cursor) {

      BasicDBObject elem = (BasicDBObject) obj;
      VariantInfo vi = new VariantInfo();
      VariantStats vs = new VariantStats();

      String chr = elem.getString("chr");
      int pos = elem.getInt("pos");

      vi.setChromosome(chr);
      vi.setPosition(pos);

      BasicDBList studies = (BasicDBList) elem.get("sources");

      Iterator<Object> it = studies.iterator();
      while (it.hasNext()) {
        BasicDBObject study = (BasicDBObject) it.next();

        if (study.getString("sourceId").equalsIgnoreCase(sourceId)) {

          BasicDBObject stats = (BasicDBObject) study.get("stats");

          String ref = study.getString("ref");
          BasicDBList alt = (BasicDBList) study.get("alt");
          vi.setRef(ref);
          vi.setAlt(Joiner.on(",").join(alt.toArray()));
          vs.setMaf((float) stats.getDouble("maf"));
          vs.setMgf((float) stats.getDouble("mgf"));
          vs.setMafAllele(stats.getString("alleleMaf"));
          vs.setMgfAllele(stats.getString("genotypeMaf"));
          vs.setMissingAlleles(stats.getInt("missAllele"));
          vs.setMissingGenotypes(stats.getInt("missGenotypes"));
          vs.setMendelinanErrors(stats.getInt("mendelErr"));
          vs.setCasesPercentDominant((float) stats.getDouble("casesPercentDominant"));
          vs.setControlsPercentDominant((float) stats.getDouble("controlsPercentDominant"));
          vs.setCasesPercentRecessive((float) stats.getDouble("casesPercentRecessive"));
          vs.setControlsPercentRecessive((float) stats.getDouble("controlsPercentRecessive"));

          BasicDBObject samples = (BasicDBObject) study.get("samples");

          for (String sampleName : samples.keySet()) {

            DBObject sample = (DBObject) samples.get(sampleName);

            if (sample.containsField("GT")) {
              String sampleGT = (String) sample.get("GT");
              vi.addSammpleGenotype(sampleName, sampleGT);
            }
          }

          vi.setSnpid((String) study.get("snpId"));

          if (study.containsField("effects")) {
            BasicDBList conseqTypes = (BasicDBList) study.get("effects");
            conseqTypes.remove("");
            String cts = Joiner.on(",").join(conseqTypes.iterator());
            vi.addConsequenceTypes(cts);
          }

          if (study.containsField("genes")) {
            BasicDBList genesList = (BasicDBList) study.get("genes");
            String genes = Joiner.on(",").join(genesList.iterator());
            vi.addGenes(genes);
          }

          if (study.containsField("attributes")) {

            BasicDBObject attr = (BasicDBObject) study.get("attributes");

            if (attr.containsField("1000G_maf")) {
              vi.addControl("1000G_maf", (String) attr.get("1000G_maf"));
              vi.addControl("1000G_amaf", (String) attr.get("1000G_amaf"));
              vi.addControl("1000G_gt", (String) attr.get("1000G_gt"));
            }

            if (attr.containsField("1000G_ASI_maf")) {
              vi.addControl("1000G-ASI_maf", (String) attr.get("1000G_ASI_maf"));
              vi.addControl("1000G-ASI_amaf", (String) attr.get("1000G_ASI_amaf"));
              vi.addControl("1000G-ASI_gt", (String) attr.get("1000G_ASI_gt"));
            }

            if (attr.containsField("1000G_AFR_maf")) {
              vi.addControl("1000G-AFR_maf", (String) attr.get("1000G_AFR_maf"));
              vi.addControl("1000G-AFR_amaf", (String) attr.get("1000G_AFR_amaf"));
              vi.addControl("1000G-AFR_gt", (String) attr.get("1000G_AFR_gt"));
            }

            if (attr.containsField("1000G_AME_maf")) {
              vi.addControl("1000G-AME_maf", (String) attr.get("1000G_AME_maf"));
              vi.addControl("1000G-AME_amaf", (String) attr.get("1000G_AME_amaf"));
              vi.addControl("1000G-AME_gt", (String) attr.get("1000G_AME_gt"));
            }

            if (attr.containsField("1000G_EUR_maf")) {
              vi.addControl("1000G-EUR_maf", (String) attr.get("1000G_EUR_maf"));
              vi.addControl("1000G-EUR_amaf", (String) attr.get("1000G_EUR_amaf"));
              vi.addControl("1000G-EUR_gt", (String) attr.get("1000G_EUR_gt"));
            }

            if (attr.containsField("EVS_maf")) {
              vi.addControl("EVS_maf", (String) attr.get("EVS_maf"));
              vi.addControl("EVS_amaf", (String) attr.get("EVS_amaf"));
              vi.addControl("EVS_gt", (String) attr.get("EVS_gt"));
            }

            if (attr.containsField("BIER_maf")) {
              vi.addControl("BIER_maf", (String) attr.get("BIER_maf"));
              vi.addControl("BIER_amaf", (String) attr.get("BIER_amaf"));
              vi.addControl("BIER_gt", (String) attr.get("BIER_gt"));
            }

            if (attr.containsField("PolyphenScore")) {
              vi.setPolyphen_score(Double.parseDouble(attr.getString("PolyphenScore")));
              vi.setPolyphen_effect(Integer.parseInt(attr.getString("PolyphenEffect")));
            }

            if (attr.containsField("SIFTScore")) {
              vi.setSift_score(Double.parseDouble(attr.getString("SIFTScore")));
              vi.setSift_effect(Integer.parseInt(attr.getString("SIFTEffect")));
            }
          }
          continue;
        }
      }
      vi.addStats(vs);
      res.add(vi);
    }

    queryResult.setResult(res);
    queryResult.setTime(startTime - System.currentTimeMillis());

    return queryResult;
  }
  @Override
  public QueryResult getVariantsHistogramByRegion(
      Region region, String sourceId, boolean histogramLogarithm, int histogramMax) {
    QueryResult<ObjectMap> queryResult =
        new QueryResult<>(
            String.format("%s:%d-%d", region.getChromosome(), region.getStart(), region.getEnd()));
    List<ObjectMap> data = new ArrayList<>();
    String startRow = buildRowkey(region.getChromosome(), Long.toString(region.getStart()));
    String stopRow = buildRowkey(region.getChromosome(), Long.toString(region.getEnd()));

    long startTime = System.currentTimeMillis();

    long startDbTime = System.currentTimeMillis();

    BasicDBObject query =
        new BasicDBObject("position", new BasicDBObject("$gte", startRow).append("$lte", stopRow))
            .append("studies.studyId", sourceId);
    DBCollection collection = db.getCollection("variants");
    DBCursor queryResults = collection.find(query);
    queryResult.setDbTime(System.currentTimeMillis() - startDbTime);

    int resultSize = queryResults.size();

    if (resultSize > histogramMax) { // Need to group results to fit maximum size of the histogram
      int sumChunkSize = resultSize / histogramMax;
      int i = 0, j = 0;
      int featuresCount = 0;
      ObjectMap item = null;

      for (DBObject result : queryResults) {
        //                featuresCount += result.getInt("features_count");
        //                if (i == 0) {
        //                    item = new ObjectMap("chromosome", result.getString("chromosome"));
        //                    item.put("chunkId", result.getInt("chunk_id"));
        //                    item.put("start", result.getInt("start"));
        //                } else if (i == sumChunkSize - 1 || j == resultSize - 1) {
        //                    if (histogramLogarithm) {
        //                        item.put("featuresCount", (featuresCount > 0) ?
        // Math.log(featuresCount) : 0);
        //                    } else {
        //                        item.put("featuresCount", featuresCount);
        //                    }
        //                    item.put("end", result.getInt("end"));
        //                    data.add(item);
        //                    i = -1;
        //                    featuresCount = 0;
        //                }
        //                j++;
        //                i++;
      }
    } else {
      for (DBObject result : queryResults) {
        //                ObjectMap item = new ObjectMap("chromosome",
        // result.getString("chromosome"));
        //                item.put("chunkId", result.getInt("chunk_id"));
        //                item.put("start", result.getInt("start"));
        //                if (histogramLogarithm) {
        //                    int features_count = result.getInt("features_count");
        //                    result.put("featuresCount", (features_count > 0) ?
        // Math.log(features_count) : 0);
        //                } else {
        //                    item.put("featuresCount", result.getInt("features_count"));
        //                }
        //                item.put("end", result.getInt("end"));
        //                data.add(item);
      }
    }

    queryResult.setResult(data);
    queryResult.setNumResults(data.size());
    queryResult.setTime(System.currentTimeMillis() - startTime);

    return queryResult;
  }