List of usage examples for com.mongodb.client.model Filters in
public static <TItem> Bson in(final String fieldName, final Iterable<TItem> values)
From source file:module.script.ImportSupplementaryGSE20711.java
License:Open Source License
public ImportSupplementaryGSE20711() { // ===== Session PostgreSQL ===== SessionFactory sessionFactory = HibernateUtil .buildSessionFactory("config/epimed_semantic.hibernate.cfg.xml"); Session session = sessionFactory.openSession(); // ===== Session Mongo ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collection = db.getCollection("samples"); // ===== Excel data loader ===== String inputfile = this.getInputDirectory() + this.getDirSeparator() + "GSE20711_emmm0003-0726-SD2.xlsx"; System.out.println("LOADING \t " + inputfile); ExcelService excelService = new ExcelService(); excelService.load(inputfile);/*from w w w. ja v a 2 s. c o m*/ String gseNumber = "GSE20711"; for (int i = 0; i < excelService.getData().size(); i++) { List<Object> dataLine = excelService.getData().get(i); String bcString = (String) dataLine.get(0); bcString = bcString.replaceAll("BC", ""); Integer bcNumber = Integer.parseInt(bcString); Document docSample = collection .find(Filters .and(Filters.in("series", gseNumber), Filters.eq("exp_group.sample_title", "Breast tumor from patient P_" + bcNumber + " (expression data)"))) .first(); System.out.println("-------------------------------------------"); System.out.println(dataLine); System.out.println(docSample); } if (session.isOpen()) { session.close(); } sessionFactory.close(); mongoClient.close(); }
From source file:module.script.QueryAvailableData.java
License:Open Source License
public QueryAvailableData() { // ===== Service ===== FormatService formatService = new FormatService(); // ===== Session Mongo ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collectionSeries = db.getCollection("series"); MongoCollection<Document> collectionSamples = db.getCollection("samples"); // ===== Print block ===== Block<Document> printBlock = new Block<Document>() { public void apply(final Document document) { System.out.println(document.toJson()); }//from w ww .ja v a 2 s.c o m }; // ===== Group by topology ===== // db.getCollection('samples').aggregate({ $group: { "_id" : "$exp_group.topology", "total" : {$sum : 1} }}, {$sort : {total : -1}} ) /* List<Document> listDocuments = collectionSamples.aggregate( Arrays.asList( Aggregates.group("$exp_group.topology", Accumulators.sum("total", 1)), Aggregates.sort(Sorts.orderBy(Sorts.descending("total"))) )) .into(new ArrayList<Document>()); */ // ===== Group by sample ===== /* List<Document> listSeries = collectionSeries .find() .projection(Projections.fields(Projections.include("title"))) .sort(Sorts.ascending("_id")) .into(new ArrayList<Document>()); for (Document doc : listSeries) { String idSeries = doc.getString("_id"); Long nbSamples = collectionSamples.count((Filters.eq("series", idSeries))); doc.append("nbSamples", nbSamples); } display(listSeries); */ // === Export Geo for a list of idSeries === // String[] listIdSeries = {"GSE11092","GSE13309", "GSE13159"}; /* List<Document> docExpGroup = collectionSamples .find(Filters.in("series", listIdSeries)) .projection(Projections.fields(Projections.include("exp_group"), Projections.excludeId())) .into(new ArrayList<Document>()); // display(docExpGroup); List<String> header = formatService.extractHeader(docExpGroup, "exp_group"); List<Object> data = formatService.extractData(docExpGroup, header, "exp_group"); System.out.println(header); displayMatrix(data); */ // List<Object> listObjects = formatService.convertHeterogeneousMongoDocuments(docExpGroup, "exp_group"); // displayMatrix(listObjects); // List<Object> listObjects = formatService.convertHomogeneousMongoDocuments(listDocuments); // === Find series === String[] listIdSamples = { "GSM80908", "GSM274639", "GSM274638", "GSM280213" }; List<Document> listDocuments = collectionSamples .aggregate(Arrays.asList(Aggregates.match(Filters.in("_id", listIdSamples)), Aggregates.group("$main_gse_number"), Aggregates.sort(Sorts.orderBy(Sorts.ascending("main_gse_numbe"))))) .into(new ArrayList<Document>()); List<Object> listObjects = formatService.convertHomogeneousMongoDocuments(listDocuments); displayMatrix(listObjects); mongoClient.close(); }
From source file:module.test.SearchSeries.java
License:Open Source License
public SearchSeries() throws ParseException { // ===== Connection ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collectionSamples = db.getCollection("series"); String[] listSeries = { "E-MTAB-365", "GSE3156", "GSE3744", "GSE4922", "GSE5764", "GSE6367", "GSE6883", "GSE8977", "GSE9014", "GSE9195", "GSE10885", "GSE11078", "GSE11352", "GSE12080", "GSE12237", "GSE12276", "GSE14017", "GSE16391", "GSE17215", "GSE17907", "GSE19615", "GSE21653", "GSE28681", "GSE38867" }; List<Document> list = collectionSamples.find(Filters.in("_id", listSeries)).into(new ArrayList<Document>()); Set<String> setGse = new HashSet<String>(); List<String> listGse = new ArrayList<String>(); for (int i = 0; i < list.size(); i++) { Document doc = list.get(i); setGse.add(doc.getString("_id")); }/*from ww w. j av a 2 s.com*/ listGse.addAll(setGse); Collections.sort(listGse); System.out.println("Found " + list.size() + " samples"); System.out.println("List GSE " + listGse); mongoClient.close(); }
From source file:module.UpdateNumberSamples.java
License:Open Source License
public UpdateNumberSamples() { // ===== Connection ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collectionSeries = db.getCollection("series"); MongoCollection<Document> collectionSamples = db.getCollection("sample"); // String [] listIdSeries = {"TISSUE_SPECIFIC_GENES_MM"}; // List<Document> listSeries = collectionSeries.find(Filters.in("_id", listIdSeries)).into(new ArrayList<Document>()); List<Document> listSeries = collectionSeries.find().into(new ArrayList<Document>()); for (Document ser : listSeries) { System.out.println(ser);/*from w w w . j ava 2s. c o m*/ String idSeries = ser.getString("_id"); Bson filter = Filters.in("series", idSeries); Long nbSamples = collectionSamples.count(filter); System.out.println(idSeries + " " + nbSamples); ser.append("nb_samples", nbSamples); collectionSeries.updateOne(Filters.eq("_id", idSeries), new Document("$set", ser)); } mongoClient.close(); }
From source file:module.UpdatePlatformType.java
License:Open Source License
public UpdatePlatformType() { // ===== Connection ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collectionPlatforms = db.getCollection("platform"); MongoCollection<Document> collectionSeries = db.getCollection("series"); // ===== Platforms ===== Bson filters = Filters.eq("type", "unknown"); List<Document> listPlatforms = collectionPlatforms.find(filters).into(new ArrayList<Document>()); for (Document platform : listPlatforms) { System.out.println("--------------------------------------------------------------"); String idPlatform = platform.getString("_id"); System.out.println(platform); List<Document> listSeries = collectionSeries.find(Filters.in("platforms", idPlatform)) .into(new ArrayList<Document>()); for (Document series : listSeries) { System.out.println(" \t -> " + series.getString("_id") + " " + series.getString("title")); }/*from w ww .j a v a2s . c o m*/ // platform.append("type", "expression array"); // collectionPlatforms.updateOne(Filters.eq("_id", idPlatform), new Document("$set", platform)); } mongoClient.close(); }
From source file:mongodb.clients.percunia.mongo.Restriction.java
License:Apache License
public static <T> Bson in(String field, List<T> value) { return Filters.in(field, value); }
From source file:org.eclipse.ditto.services.thingsearch.persistence.read.criteria.visitors.CreateBsonPredicateVisitor.java
License:Open Source License
@Override public Function<String, Bson> visitIn(final List<?> values) { return fieldName -> Filters.in(fieldName, values); }
From source file:org.eclipse.ditto.services.thingsearch.persistence.read.expression.visitors.AbstractFieldBsonCreator.java
License:Open Source License
/** * Create filter BSON for global readability. * * @param authorizationSubjectIds authorization subject IDs for visibility restriction. * @return the BSON filter./* w ww . j ava2s . c o m*/ */ public static Bson getGlobalReadBson(final Iterable<String> authorizationSubjectIds) { return Filters.in(FIELD_GLOBAL_READ, authorizationSubjectIds); }
From source file:org.eclipse.ditto.services.thingsearch.persistence.read.expression.visitors.AbstractFieldBsonCreator.java
License:Open Source License
Optional<Bson> getAuthorizationBson() { return Optional.ofNullable(authorizationSubjectIds) .map(subjectIds -> Filters.and(Filters.in(FIELD_GRANTED, authorizationSubjectIds), Filters.nin(FIELD_REVOKED, authorizationSubjectIds))); }
From source file:org.jnosql.diana.mongodb.document.DocumentQueryConversor.java
License:Open Source License
public static Bson convert(DocumentCondition condition) { Document document = condition.getDocument(); Object value = document.getValue().get(); switch (condition.getCondition()) { case EQUALS:/* www . j a v a2 s. co m*/ return Filters.eq(document.getName(), value); case GREATER_THAN: return Filters.gt(document.getName(), value); case GREATER_EQUALS_THAN: return Filters.gte(document.getName(), value); case LESSER_THAN: return Filters.lt(document.getName(), value); case LESSER_EQUALS_THAN: return Filters.lte(document.getName(), value); case IN: return Filters.in(document.getName(), value); case LIKE: return Filters.regex(document.getName(), value.toString()); case AND: List<Document> andList = condition.getDocument().getValue().get(new TypeReference<List<Document>>() { }); return Filters.and(andList.stream().map(d -> new BasicDBObject(d.getName(), d.getValue().get())) .toArray(BasicDBObject[]::new)); case OR: List<Document> orList = condition.getDocument().getValue().get(new TypeReference<List<Document>>() { }); return Filters.or(orList.stream().map(d -> new BasicDBObject(d.getName(), d.getValue().get())) .toArray(BasicDBObject[]::new)); default: throw new UnsupportedOperationException( "The condition " + condition.getCondition() + " is not supported from mongoDB diana driver"); } }