List of usage examples for org.apache.commons.collections.keyvalue MultiKey MultiKey
public MultiKey(Object[] keys, boolean makeClone)
From source file:org.intermine.bio.dataconversion.IdResolver.java
/** * For the given id return a set of matching primary identifiers in the given * taxonId. In many cases the set will have just one element. Some will have * zero element.// w w w . j a v a 2 s .c o m * @param taxonId the organism to search within * @param clsName go term * @param id the identifier to resolve * @return a set of matching primary identifiers */ public Set<String> resolveId(String taxonId, String clsName, String id) { checkTaxonId(taxonId, clsName); // if this is a primary identifier, just return it if (isPrimaryIdentifier(taxonId, clsName, id)) { return Collections.singleton(id); } if (orgMainMaps.containsKey(new MultiKey(taxonId, clsName)) && orgMainMaps.get(new MultiKey(taxonId, clsName)).containsKey(id)) { return orgMainMaps.get(new MultiKey(taxonId, clsName)).get(id); } if (orgSynMaps.containsKey(new MultiKey(taxonId, clsName)) && orgSynMaps.get(new MultiKey(taxonId, clsName)).containsKey(id)) { return orgSynMaps.get(new MultiKey(taxonId, clsName)).get(id); } return Collections.emptySet(); }
From source file:org.intermine.bio.dataconversion.IdResolver.java
/** * For a particular primary identifier fetch a set of synonyms or return * null if id is not a primary identifier for the taxonId given. * @param taxonId the organism to do a lookup for * @param clsName go term//w w w . j a v a2 s . c o m * @param id the primary identifier to look up * @return a set of synonyms or null if id is not a primary identifier */ public Set<String> getSynonyms(String taxonId, String clsName, String primaryIdentifier) { checkTaxonId(taxonId, clsName); if (!isPrimaryIdentifier(taxonId, clsName, primaryIdentifier)) { return null; } return orgIdMaps.get(new MultiKey(taxonId, clsName)).get(primaryIdentifier); }
From source file:org.intermine.bio.dataconversion.IdResolver.java
/** * Check if resolver has taxon id and class name * @param taxonId taxon id as string/*from ww w . jav a 2s.co m*/ * @param clsName class name as string */ public boolean hasTaxonAndClassName(String taxonId, String clsName) { return orgIdMaps.keySet().contains(new MultiKey(taxonId, clsName)); }
From source file:org.intermine.bio.dataconversion.IdResolver.java
/** * Check if resolver has a set of keys (taxon id + class name) * @param taxonIdAndClsNameMap data structure to hold keys * @return boolean value/*from w w w . j a va2 s. c om*/ */ public boolean hasTaxonsAndClassNames(Map<String, Set<String>> taxonIdAndClsNameMap) { Set<MultiKey> keySet = new HashSet<MultiKey>(); for (Entry<String, Set<String>> e : taxonIdAndClsNameMap.entrySet()) { for (String clsName : e.getValue()) { keySet.add(new MultiKey(e.getKey(), clsName)); } } return orgIdMaps.keySet().containsAll(keySet); }
From source file:org.intermine.bio.dataconversion.IdResolver.java
/** * Add an entry to the IdResolver, a primary identifier and any number of synonyms. * @param taxonId the organism of the identifier * @param clsName go term/* w ww . j ava 2s .c o m*/ * @param primaryIdentifier the main identifier * @param synonyms a set of synonyms * @param mainId if true these are main ids, otherwise synonms */ protected void addEntry(String taxonId, String clsName, String primaryIdentifier, Collection<String> ids, Boolean mainId) { Map<String, Set<String>> idMap = orgIdMaps.get(new MultiKey(taxonId, clsName)); if (idMap == null) { idMap = new LinkedHashMap<String, Set<String>>(); orgIdMaps.put(new MultiKey(taxonId, clsName), idMap); } addToMapList(idMap, primaryIdentifier, ids); Map<String, Set<String>> lookupMap = null; Map<String, Set<String>> reverseMap = null; if (mainId.booleanValue()) { lookupMap = orgMainMaps.get(new MultiKey(taxonId, clsName)); if (lookupMap == null) { lookupMap = new HashMap<String, Set<String>>(); orgMainMaps.put(new MultiKey(taxonId, clsName), lookupMap); } reverseMap = orgIdMainMaps.get(new MultiKey(taxonId, clsName)); if (reverseMap == null) { reverseMap = new LinkedHashMap<String, Set<String>>(); orgIdMainMaps.put(new MultiKey(taxonId, clsName), reverseMap); } } else { // these ids are synonyms lookupMap = orgSynMaps.get(new MultiKey(taxonId, clsName)); if (lookupMap == null) { lookupMap = new LinkedHashMap<String, Set<String>>(); orgSynMaps.put(new MultiKey(taxonId, clsName), lookupMap); } reverseMap = orgIdSynMaps.get(new MultiKey(taxonId, clsName)); if (reverseMap == null) { reverseMap = new LinkedHashMap<String, Set<String>>(); orgIdSynMaps.put(new MultiKey(taxonId, clsName), reverseMap); } } // map from primaryId back to main/synonym ids addToMapList(reverseMap, primaryIdentifier, ids); for (String id : ids) { addToMapList(lookupMap, id, Collections.singleton(primaryIdentifier)); } }
From source file:org.intermine.bio.dataconversion.OrthodbConverter.java
private String getGene(String geneId, String taxonId) throws ObjectStoreException { String identifierType = config.get(taxonId); {/* ww w . ja v a 2 s.c o m*/ /** * !!! Ugly Code Ahead * OrthoDB use secondaryIdentifier for worm gene, in wormbase-identifiers, gene * WBGene00006756 (ZC416.8, unc-17) and WBGene00000481 (ZC416.8, cha-1) have the same * secondaryIdentifier ZC416.8, but OrthoDB points to cha-1 in term of the protein id * ZC416.8b. To fix the issue, set symbol as another key to filter the duplication. * Same for Y105E8A.7 and B0564.1 * * For a better fix, load uniprot data, set key to secondaryIdentifier, protein and * organism. But MasterMine does not load protein data. */ if ("ZC416.8".equals(geneId)) { geneId = "cha-1"; identifierType = "symbol"; } if ("Y105E8A.7".equals(geneId)) { geneId = "lev-10"; identifierType = "symbol"; } if ("B0564.1".equals(geneId)) { geneId = "exos-4.1"; identifierType = "symbol"; } } // Resolver always returns primaryIdentifier, this behaviour could adjust in id resolver. String resolvedGenePid = resolveGene(taxonId, geneId); if (resolvedGenePid == null) { return null; } // Id resolver always resolve ids to pids. String refId = identifiersToGenes.get(new MultiKey(taxonId, resolvedGenePid)); if (refId == null) { Item gene = createItem("Gene"); gene.setAttribute(DEFAULT_IDENTIFIER_TYPE, resolvedGenePid); if (!StringUtils.isEmpty(identifierType)) { if (!identifierType.equals(DEFAULT_IDENTIFIER_TYPE)) { if ("crossReferences".equals(identifierType)) { gene.addToCollection(identifierType, createCrossReference(gene.getIdentifier(), geneId, DATA_SOURCE_NAME, true)); } else { gene.setAttribute(identifierType, geneId); } } } gene.setReference("organism", getOrganism(taxonId)); refId = gene.getIdentifier(); identifiersToGenes.put(new MultiKey(taxonId, resolvedGenePid), refId); store(gene); } return refId; }
From source file:org.intermine.bio.dataconversion.PantherConverter.java
private String getGene(String geneId, String taxonId) throws ObjectStoreException { String identifierType = config.get(taxonId); if (StringUtils.isEmpty(identifierType)) { identifierType = DEFAULT_IDENTIFIER_TYPE; }//w ww . ja va 2 s . c o m geneId = parseIdentifier(geneId); String resolvedGenePid = resolveGene(taxonId, geneId); if (resolvedGenePid == null) { return null; } String refId = identifiersToGenes.get(new MultiKey(taxonId, resolvedGenePid)); if (refId == null) { Item gene = createItem("Gene"); gene.setAttribute(DEFAULT_IDENTIFIER_TYPE, resolvedGenePid); if (geneIdPolymorphism.containsKey(taxonId)) { Map<String, String> patternMap = geneIdPolymorphism.get(taxonId); for (String key : patternMap.keySet()) { if (geneId.startsWith(key)) { identifierType = patternMap.get(key); if (!identifierType.equals(DEFAULT_IDENTIFIER_TYPE)) { if ("crossReferences".equals(identifierType)) { gene.addToCollection(identifierType, createCrossReference(gene.getIdentifier(), geneId, DATA_SOURCE_NAME, true)); } else { gene.setAttribute(identifierType, geneId); } } } } } else { if (!identifierType.equals(DEFAULT_IDENTIFIER_TYPE)) { if ("crossReferences".equals(identifierType)) { gene.addToCollection(identifierType, createCrossReference(gene.getIdentifier(), geneId, DATA_SOURCE_NAME, true)); } else { gene.setAttribute(identifierType, geneId); } } } gene.setReference("organism", getOrganism(taxonId)); refId = gene.getIdentifier(); identifiersToGenes.put(new MultiKey(taxonId, resolvedGenePid), refId); store(gene); } return refId; }
From source file:org.intermine.bio.dataconversion.SgdConverter.java
private Item getInteractionItem(String refId, String gene2RefId) throws ObjectStoreException { MultiKey key = new MultiKey(refId, gene2RefId); Item interaction = interactionsnew.get(key); if (interaction == null) { interaction = createItem("Interaction"); interaction.setReference("participant1", refId); //gene1 interaction.setReference("participant2", gene2RefId); //gene2 }/*from ww w . ja v a 2 s . co m*/ return interaction; }
From source file:org.intermine.bio.util.OrganismRepository.java
/** * Return an OrganismRepository created from a properties file in the class path. * @return the OrganismRepository/*from ww w. ja v a 2s .co m*/ */ @SuppressWarnings("unchecked") public static OrganismRepository getOrganismRepository() { if (or == null) { Properties props = new Properties(); try { InputStream propsResource = OrganismRepository.class.getClassLoader() .getResourceAsStream(PROP_FILE); if (propsResource == null) { throw new RuntimeException("can't find " + PROP_FILE + " in class path"); } props.load(propsResource); } catch (IOException e) { throw new RuntimeException("Problem loading properties '" + PROP_FILE + "'", e); } or = new OrganismRepository(); Enumeration<String> propNames = (Enumeration<String>) props.propertyNames(); Pattern pattern = Pattern.compile(REGULAR_EXPRESSION); while (propNames.hasMoreElements()) { String name = propNames.nextElement(); if (name.startsWith(PREFIX)) { Matcher matcher = pattern.matcher(name); if (matcher.matches()) { String taxonIdString = matcher.group(1); int taxonId = Integer.valueOf(taxonIdString).intValue(); String fieldName = matcher.group(2); OrganismData od = or.getOrganismDataByTaxonInternal(taxonId); final String attributeValue = props.getProperty(name); if (fieldName.equals(ABBREVIATION)) { od.setAbbreviation(attributeValue); or.abbreviationMap.put(attributeValue.toLowerCase(), od); } else if (fieldName.equals(STRAINS)) { String[] strains = attributeValue.split(" "); for (String strain : strains) { try { or.strains.put(Integer.valueOf(strain), od); or.organismsWithStrains.put(taxonIdString, strain); } catch (NumberFormatException e) { throw new NumberFormatException("taxon ID must be a number"); } } } else if (fieldName.equals(ENSEMBL)) { od.setEnsemblPrefix(attributeValue); } else if (fieldName.equals(UNIPROT)) { od.setUniprot(attributeValue); uniprotToTaxon.put(attributeValue, od); } else { if (fieldName.equals(SPECIES)) { od.setSpecies(attributeValue); } else { if (fieldName.equals(GENUS)) { od.setGenus(attributeValue); } else { throw new RuntimeException("internal error didn't match: " + fieldName); } } } } else { throw new RuntimeException("unable to parse organism property key: " + name); } } else { throw new RuntimeException("properties in " + PROP_FILE + " must start with " + PREFIX + "."); } } for (OrganismData od : or.taxonMap.values()) { or.genusSpeciesMap.put(new MultiKey(od.getGenus(), od.getSpecies()), od); // we have some organisms from uniprot that don't have a short name if (od.getShortName() != null) { or.shortNameMap.put(od.getShortName(), od); } } } return or; }
From source file:org.intermine.bio.util.OrganismRepository.java
/** * Look up OrganismData objects by genus and species - both must match. Returns null if there * is no OrganismData in this OrganismRepository that matches. * @param genus the genus//from w ww . java2 s .c o m * @param species the species * @return the OrganismData */ public OrganismData getOrganismDataByGenusSpecies(String genus, String species) { MultiKey key = new MultiKey(genus, species); return genusSpeciesMap.get(key); }