use of org.jbei.ice.lib.dto.search.SearchResult in project ice by JBEI.
the class BlastPlus method parseBlastOutputLine.
/**
* Parses a blast output that represents a single hit
*
* @param line blast output for hit
* @return object wrapper around details of the hit
*/
private static SearchResult parseBlastOutputLine(String[] line) {
// extract part information
PartData view = new PartData(EntryType.nameToType(line[1]));
view.setId(Long.decode(line[0]));
view.setName(line[2]);
view.setPartId(line[3]);
String summary = DAOFactory.getEntryDAO().getEntrySummary(view.getId());
view.setShortDescription(summary);
//search result object
SearchResult searchResult = new SearchResult();
searchResult.setEntryInfo(view);
searchResult.seteValue(line[9]);
searchResult.setScore(Float.valueOf(line[11]));
searchResult.setAlignment(line[13]);
searchResult.setQueryLength(Integer.parseInt(line[12]));
searchResult.setNident(Integer.parseInt(line[13]));
return searchResult;
}
use of org.jbei.ice.lib.dto.search.SearchResult in project ice by JBEI.
the class BlastPlus method processBlastOutput.
/**
* Processes the result of a blast search
*
* @param blastOutput result output from running blast on the command line
* @param queryLength length of query sequence
* @return mapping of entryId to search result object containing information about the blast search for that particular hit
*/
private static LinkedHashMap<String, SearchResult> processBlastOutput(String blastOutput, int queryLength) {
LinkedHashMap<String, SearchResult> hashMap = new LinkedHashMap<>();
try (CSVReader reader = new CSVReader(new StringReader(blastOutput))) {
List<String[]> lines = reader.readAll();
reader.close();
for (String[] line : lines) {
SearchResult info = parseBlastOutputLine(line);
info.setQueryLength(queryLength);
String idString = Long.toString(info.getEntryInfo().getId());
SearchResult currentResult = hashMap.get(idString);
// if there is an existing record for same entry with a lower relative score then replace
if (currentResult == null)
hashMap.put(idString, info);
}
} catch (IOException e) {
Logger.error(e);
return null;
}
return hashMap;
}
use of org.jbei.ice.lib.dto.search.SearchResult in project ice by JBEI.
the class StandardBlastDatabase method processBlastOutput.
/**
* Processes the result of a blast search
*
* @param blastOutput result output from running blast on the command line
* @param queryLength length of query sequence
* @return mapping of entryId to search result object containing information about the blast search for that particular hit
*/
private LinkedHashMap<String, SearchResult> processBlastOutput(String blastOutput, int queryLength) {
LinkedHashMap<String, SearchResult> hashMap = new LinkedHashMap<>();
try (CSVReader reader = new CSVReader(new StringReader(blastOutput))) {
List<String[]> lines = reader.readAll();
reader.close();
for (String[] line : lines) {
SearchResult info = parseBlastOutputLine(line);
if (info == null)
continue;
info.setQueryLength(queryLength);
String idString = Long.toString(info.getEntryInfo().getId());
// if there is an existing record for same entry with a lower relative score then replace
hashMap.putIfAbsent(idString, info);
}
} catch (IOException | CsvException e) {
Logger.error(e);
return null;
}
return hashMap;
}
use of org.jbei.ice.lib.dto.search.SearchResult in project ice by JBEI.
the class HibernateSearch method filterBlastResults.
/**
* Intended to be called after running a blast search to filter the results. Blast search runs
* on a fasta file which contains all the sequences. Hibernate search has a security filter for permissions
* and is therefore used to filter out the blast results, as well as to filter based on the entry
* attributes not handled by blast; such as "has sequence" and "bio-safety level"
*
* @param userId identifier for account of user performing search
* @param start paging start
* @param count maximum number of results to return
* @param blastResults raw results of the blast search
* @return wrapper around list of filtered results
*/
public SearchResults filterBlastResults(String userId, int start, int count, SearchQuery searchQuery, final HashMap<String, SearchResult> blastResults) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
FullTextSession fullTextSession = Search.getFullTextSession(session);
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Entry.class).get();
Query query = qb.keyword().onField("visibility").matching(Visibility.OK.getValue()).createQuery();
// todo : there is a limit of 1024 boolean clauses so return only return top blast results
BooleanQuery.Builder builder = new BooleanQuery.Builder();
builder.add(query, BooleanClause.Occur.FILTER);
// wrap Lucene query in a org.hibernate.Query
Class<?>[] classes = SearchFieldFactory.classesForTypes(searchQuery.getEntryTypes());
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(builder.build(), classes);
// enable security filter if an admin
checkEnableSecurityFilter(userId, fullTextQuery);
// enable has attachment/sequence/sample (if needed)
checkEnableHasAttribute(fullTextQuery, searchQuery.getParameters());
// bio-safety level
if (searchQuery.getBioSafetyOption() != null) {
TermContext levelContext = qb.keyword();
Query biosafetyQuery = levelContext.onField("bioSafetyLevel").ignoreFieldBridge().matching(searchQuery.getBioSafetyOption().getValue()).createQuery();
builder.add(biosafetyQuery, BooleanClause.Occur.MUST);
}
// execute search
fullTextQuery.setProjection("id");
// list contains an object array with one Long object
List<?> luceneResult = fullTextQuery.list();
HashSet<String> resultSet = new HashSet<>();
// page
for (Object object : luceneResult) {
Long result = (Long) ((Object[]) object)[0];
resultSet.add(result.toString());
}
blastResults.keySet().removeIf(key -> !resultSet.contains(key));
SearchResult[] searchResults = new SearchResult[count];
int limit = Math.min((start + count), blastResults.size());
LinkedList<SearchResult> list = new LinkedList<>(Arrays.asList(blastResults.values().toArray(searchResults)).subList(start, limit));
SearchResults results = new SearchResults();
results.setResultCount(blastResults.size());
results.setResults(list);
return results;
}
use of org.jbei.ice.lib.dto.search.SearchResult in project ice by JBEI.
the class Entries method getSearchResults.
private List<Long> getSearchResults(SearchQuery searchQuery) {
SearchIndexes searchIndexes = new SearchIndexes();
SearchResults searchResults = searchIndexes.runSearch(userId, searchQuery);
// todo : inefficient: have search return ids only
List<Long> results = new LinkedList<>();
for (SearchResult result : searchResults.getResults()) {
results.add(result.getEntryInfo().getId());
}
return results;
}
Aggregations