Example usage for org.apache.commons.collections.keyvalue MultiKey MultiKey

List of usage examples for org.apache.commons.collections.keyvalue MultiKey MultiKey

Introduction

In this page you can find the example usage for org.apache.commons.collections.keyvalue MultiKey MultiKey.

Prototype

public MultiKey(Object key1, Object key2, Object key3, Object key4) 

Source Link

Document

Constructor taking four keys.

Usage

From source file:com.workplacesystems.utilsj.collections.HashMap4Template.java

/**
 * Method to get existing [key1,key2,key3,key4] value or create new one if it's
 * absent. Needs implementation of create(key1,key2,key3,key4) in order to work
 *///www  .ja v a2  s  . c  o  m
public V getOrCreate(K1 key1, K2 key2, K3 key3, K4 key4) {
    // already got it?
    MultiKey multi_key = new MultiKey(key1, key2, key3, key4);
    if (containsKey(multi_key))
        return get(multi_key);

    // if not, create and add it
    V result = create(key1, key2, key3, key4);
    put(multi_key, result);
    return result;
}

From source file:com.workplacesystems.utilsj.collections.HashMap4Template.java

public void put(K1 key1, K2 key2, K3 key3, K4 key4, V value) {
    put(new MultiKey(key1, key2, key3, key4), value);
}

From source file:com.workplacesystems.utilsj.collections.HashMap4Template.java

public V get(K1 key1, K2 key2, K3 key3, K4 key4) {
    return get(new MultiKey(key1, key2, key3, key4));
}

From source file:org.intermine.api.profile.TagManager.java

private MultiKey makeKey(String tagName, String objectIdentifier, String type, String userName) {
    return new MultiKey(tagName, objectIdentifier, type, userName);
}

From source file:org.intermine.bio.dataconversion.FlyBaseProcessor.java

/**
 * {@inheritDoc}//  w w  w .j a  va2s  .c  o m
 */
@Override
protected Map<MultiKey, List<ConfigAction>> getConfig(int taxonId) {
    MultiKeyMap map = config.get(new Integer(taxonId));
    if (map == null) {
        map = new MultiKeyMap();
        config.put(new Integer(taxonId), map);

        // synomym configuration example: for features of class "Gene", if the type name of
        // the synonym is "fullname" and "is_current" is true, set the "name" attribute of
        // the new Gene to be this synonym and then make a Synonym object
        map.put(new MultiKey("synonym", "Gene", "fullname", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("name")));
        map.put(new MultiKey("synonym", "Gene", "fullname", Boolean.FALSE),
                Arrays.asList(CREATE_SYNONYM_ACTION));
        map.put(new MultiKey("synonym", "Gene", "symbol", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("symbol")));
        map.put(new MultiKey("synonym", "Gene", "symbol", Boolean.FALSE), Arrays.asList(CREATE_SYNONYM_ACTION));

        // dbxref table configuration example: for features of class "Gene", where the
        // db.name is "FlyBase Annotation IDs" and "is_current" is true, set the
        // "secondaryIdentifier" attribute of the new Gene to be this dbxref and then make a
        // Synonym object
        map.put(new MultiKey("dbxref", "Gene", FLYBASE_DB_NAME + " Annotation IDs", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("secondaryIdentifier")));
        map.put(new MultiKey("dbxref", "Gene", FLYBASE_DB_NAME + " Annotation IDs", Boolean.FALSE),
                Arrays.asList(CREATE_SYNONYM_ACTION));
        // null for the "is_current" means either TRUE or FALSE is OK.

        map.put(new MultiKey("dbxref", "Gene", FLYBASE_DB_NAME, null), Arrays.asList(CREATE_SYNONYM_ACTION));

        map.put(new MultiKey("dbxref", "MRNA", FLYBASE_DB_NAME + " Annotation IDs", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("secondaryIdentifier")));
        map.put(new MultiKey("dbxref", "TransposableElementInsertionSite", "drosdel", null),
                Arrays.asList(new SetFieldConfigAction("symbol")));

        map.put(new MultiKey("synonym", "ChromosomeStructureVariation", "fullname", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("name")));
        map.put(new MultiKey("synonym", "ChromosomalDeletion", "fullname", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("name")));
        map.put(new MultiKey("synonym", "ChromosomalDuplication", "fullname", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("name")));
        map.put(new MultiKey("synonym", "ChromosomalInversion", "fullname", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("name")));
        map.put(new MultiKey("synonym", "ChromosomalTranslocation", "fullname", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("name")));
        map.put(new MultiKey("synonym", "ChromosomalTransposition", "fullname", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("name")));

        map.put(new MultiKey("synonym", "MRNA", "symbol", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("symbol")));
        map.put(new MultiKey("synonym", "MRNA", "symbol", Boolean.FALSE), Arrays.asList(CREATE_SYNONYM_ACTION));
        map.put(new MultiKey("dbxref", "MRNA", FLYBASE_DB_NAME + " Annotation IDs", null),
                Arrays.asList(CREATE_SYNONYM_ACTION));
        map.put(new MultiKey("dbxref", "MRNA", FLYBASE_DB_NAME, null), Arrays.asList(CREATE_SYNONYM_ACTION));

        // set the Allele.gene when there is an alleleof relationship between Allele and Gene
        map.put(new MultiKey("relationship", "Allele", "alleleof", "Gene"),
                Arrays.asList(new SetFieldConfigAction("gene")));

        // Set the protein reference in the MRNA - "rev_relationship" means that the
        // relationship table actually has Protein, producedby, MRNA.  We configure like
        // this so we can set a reference in MRNA rather than protein
        map.put(new MultiKey("rev_relationship", "MRNA", "producedby", "Protein"),
                Arrays.asList(new SetFieldConfigAction("protein")));

        map.put(new MultiKey("relationship", "CDNAClone", "derived_assoc_cdna_clone", "Gene"),
                Arrays.asList(new SetFieldConfigAction("gene")));

        map.put(new MultiKey("relationship", "Gene", "producedby", "Protein"),
                Arrays.asList(new SetFieldConfigAction("proteins")));

        // featureprop configuration example: for features of class "Gene", if the type name
        // of the prop is "cyto_range", set the "cytoLocation" attribute of the
        // new Gene to be this property
        map.put(new MultiKey("prop", "Gene", "cyto_range"),
                Arrays.asList(new SetFieldConfigAction("cytoLocation")));
        map.put(new MultiKey("prop", "Gene", "symbol"), Arrays.asList(CREATE_SYNONYM_ACTION));
        map.put(new MultiKey("prop", "TransposableElementInsertionSite", "curated_cytological_location"),
                Arrays.asList(new SetFieldConfigAction("cytoLocation")));
        ConfigAction alleleClassConfigAction = new AlleleClassSetFieldAction("alleleClass");
        map.put(new MultiKey("prop", "Allele", "promoted_allele_class"),
                Arrays.asList(alleleClassConfigAction));
        // library config example: for features of class "CDNAClone", if the type name
        // of the library is "stage", set the "stage" attribute of the
        // new CDNAClone to be this property
        map.put(new MultiKey("library", "CDNAClone", "stage"),
                Arrays.asList(new SetFieldConfigAction("stage")));
        // anatomy term config example:  for features of class "CDNAClone" if there is an
        // anatomy term, set a reference in CDNAClone.tissueSource
        // See #2173
        //            map.put(new MultiKey("anatomyterm", "CDNAClone", null),
        //                    Arrays.asList(new SetFieldConfigAction("tissueSource")));

        // feature_cvterm example for Transposition: we create a featureTerms collection in the
        // Transposition objects containing SequenceOntologyTerm objects.  For the current
        // feature we create one SequenceOntologyTerm object for each associated "SO" cvterm.
        // We set the "name" field of the SequenceOntologyTerm to be the name from the cvterm
        // table.
        // TODO fixme
        //            List<String> chromosomeStructureVariationClassNames =
        //                Arrays.asList("ChromosomeStructureVariation", "ChromosomalDeletion",
        //                        "ChromosomalDuplication", "ChromosomalInversion",
        //                        "ChromosomalTranslocation", "ChromosomalTransposition");
        //            for (String className: chromosomeStructureVariationClassNames) {
        //                map.put(new MultiKey("cvterm", className, "SO"),
        //                        Arrays.asList(new CreateCollectionAction("SOTerm", "abberationSOTerms",
        //                                "name", true)));
        //            }
        // feature configuration example: for features of class "Exon", from "FlyBase",
        // set the Gene.symbol to be the "name" field from the chado feature
        map.put(new MultiKey("feature", "Exon", FLYBASE_DB_NAME, "name"),
                Arrays.asList(new SetFieldConfigAction("symbol")));
        map.put(new MultiKey("feature", "Allele", FLYBASE_DB_NAME, "name"),
                Arrays.asList(new SetFieldConfigAction("symbol")));

        // DO_NOTHING_ACTION means skip the name from this feature
        map.put(new MultiKey("feature", "Chromosome", FLYBASE_DB_NAME, "name"),
                Arrays.asList(DO_NOTHING_ACTION));

        map.put(new MultiKey("feature", "ChromosomeBand", FLYBASE_DB_NAME, "name"),
                Arrays.asList(DO_NOTHING_ACTION));

        map.put(new MultiKey("feature", "TransposableElementInsertionSite", FLYBASE_DB_NAME, "name"),
                Arrays.asList(new SetFieldConfigAction("symbol", PB_INSERTION_PATTERN),
                        new SetFieldConfigAction("secondaryIdentifier")));

        map.put(new MultiKey("feature", "Gene", FLYBASE_DB_NAME, "uniquename"),
                Arrays.asList(new SetFieldConfigAction("primaryIdentifier")));
        map.put(new MultiKey("feature", "Gene", FLYBASE_DB_NAME, "name"), Arrays.asList(DO_NOTHING_ACTION));

        map.put(new MultiKey("feature", "ChromosomeStructureVariation", FLYBASE_DB_NAME, "name"),
                Arrays.asList(new SetFieldConfigAction("secondaryIdentifier")));

        // just make a Synonym because the secondaryIdentifier and the symbol are set from the
        // dbxref and synonym tables
        map.put(new MultiKey("feature", "MRNA", FLYBASE_DB_NAME, "name"),
                Arrays.asList(new CreateSynonymAction()));

        map.put(new MultiKey("feature", "PointMutation", FLYBASE_DB_NAME, "uniquename"),
                Arrays.asList(new SetFieldConfigAction("name"), new SetFieldConfigAction("primaryIdentifier")));
        // name isn't set in flybase:
        map.put(new MultiKey("feature", "PointMutation", FLYBASE_DB_NAME, "name"),
                Arrays.asList(DO_NOTHING_ACTION));

        map.put(new MultiKey("dbxref", "Protein", FLYBASE_DB_NAME + " Annotation IDs", Boolean.TRUE),
                Arrays.asList(CREATE_SYNONYM_ACTION));
        map.put(new MultiKey("feature", "Protein", FLYBASE_DB_NAME, "name"),
                Arrays.asList(CREATE_SYNONYM_ACTION));
        map.put(new MultiKey("feature", "Protein", FLYBASE_DB_NAME, "uniquename"),
                Arrays.asList(new SetFieldConfigAction("secondaryIdentifier")));
        map.put(new MultiKey("dbxref", "Protein", "GB_protein", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("genbankIdentifier"), CREATE_SYNONYM_ACTION));

        // transposable_element and natural_transposable_element
        map.put(new MultiKey("feature", "TransposableElement", FLYBASE_DB_NAME, "name"), Arrays
                .asList(new SetFieldConfigAction("secondaryIdentifier"), new SetFieldConfigAction("symbol")));
        map.put(new MultiKey("feature", "NaturalTransposableElement", FLYBASE_DB_NAME, "name"), Arrays
                .asList(new SetFieldConfigAction("secondaryIdentifier"), new SetFieldConfigAction("symbol")));
        map.put(new MultiKey("relationship", "TransposableElement", "producedby", "NaturalTransposableElement"),
                Arrays.asList(new SetFieldConfigAction("insertedElement")));
        map.put(new MultiKey("synonym", "NaturalTransposableElement", "fullname", Boolean.TRUE),
                Arrays.asList(new SetFieldConfigAction("name")));
    }
    return map;
}

From source file:org.intermine.bio.dataconversion.ModEncodeFeatureProcessor.java

/**
 * {@inheritDoc}/*from   w ww .  j a v  a  2s.c o m*/
 *
 * see FlyBaseProcessor for many more examples of configuration
 */
@Override
protected Map<MultiKey, List<ConfigAction>> getConfig(int taxonId) {
    MultiKeyMap map = config.get(new Integer(taxonId));
    if (map == null) {
        map = new MultiKeyMap();
        config.put(new Integer(taxonId), map);
        //feature configuration example: for features of class "Gene", from "modENCODE",
        //set the Gene.symbol to be the "name" field from the chado feature
        // map.put(new MultiKey("feature", "Gene", MODENCODE_SOURCE_NAME, "name"),
        // Arrays.asList(new SetFieldConfigAction("symbol")));

        // TODO: check possible conflicts with our sql matching
        // map.put(new MultiKey("relationship", "ESTMatch", "evidence_for_feature", "Intron"),
        //        Arrays.asList(new SetFieldConfigAction("intron")));
        map.put(new MultiKey("relationship", "ThreePrimeUTR", "adjacent_to", "CDS"),
                Arrays.asList(new SetFieldConfigAction("CDS")));
        map.put(new MultiKey("relationship", "PolyASite", "derives_from", "ThreePrimeRACEClone"),
                Arrays.asList(new SetFieldConfigAction("threePrimeRACEClone")));
        map.put(new MultiKey("relationship", "ThreePrimeRST", "derives_from", "ThreePrimeRACEClone"),
                Arrays.asList(new SetFieldConfigAction("threePrimeRACEClone")));
        // evidence_for_feature
        map.put(new MultiKey("relationship", "OverlappingESTSet", "evidence_for_feature", "TranscriptRegion"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "ExperimentalFeature", "evidence_for_feature", "Transcript"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "ExperimentalFeature", "evidence_for_feature", "Exon"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "ExperimentalFeature", "evidence_for_feature", "Intron"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "ExperimentalFeature", "evidence_for_feature", "ExonRegion"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "Intron", "evidence_for_feature", "PolypeptideRegion"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        // partial_evidence_for_feature
        map.put(new MultiKey("relationship", "OverlappingESTSet", "partial_evidence_for_feature", "MRNA"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "TranscriptRegion", "partial_evidence_for_feature", "MRNA"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        // complete_evidence_for_feature
        map.put(new MultiKey("relationship", "ThreePrimeUST", "complete_evidence_for_feature", "ThreePrimeUTR"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "OverlappingESTSet", "complete_evidence_for_feature", "Intron"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "OverlappingESTSet", "complete_evidence_for_feature", "PolyASite"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "OverlappingESTSet", "complete_evidence_for_feature",
                "SL1AcceptorSite"), Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "OverlappingESTSet", "complete_evidence_for_feature",
                "SL2AcceptorSite"), Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "OverlappingESTSet", "complete_evidence_for_feature",
                "TranscriptionEndSite"), Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "OverlappingESTSet", "complete_evidence_for_feature", "TSS"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        // full_evidence_for_feature
        //          map.put(new MultiKey("relationship", "OverlappingESTSet",
        //                  "full_evidence_for_feature", "Gene"),
        //                  Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "OverlappingESTSet", "full_evidence_for_feature", "MRNA"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        map.put(new MultiKey("relationship", "TranscriptRegion", "full_evidence_for_feature", "MRNA"),
                Arrays.asList(new SetFieldConfigAction("supportedFeatures")));
        // additional properties
        map.put(new MultiKey("prop", "CDS", "status"), Arrays.asList(new SetFieldConfigAction("status")));
        map.put(new MultiKey("prop", "CDS", "wormpep"), Arrays.asList(new SetFieldConfigAction("wormpep")));
        map.put(new MultiKey("prop", "MRNA", "cds"), Arrays.asList(new SetFieldConfigAction("CDS")));
        map.put(new MultiKey("prop", "MRNA", "wormpep"), Arrays.asList(new SetFieldConfigAction("wormpep")));
        map.put(new MultiKey("prop", "PolyASite", "external_evidence"),
                Arrays.asList(new SetFieldConfigAction("externalEvidence")));
        map.put(new MultiKey("prop", "ThreePrimeRST", "genbank_acc"),
                Arrays.asList(new SetFieldConfigAction("GenBankAcc")));
        map.put(new MultiKey("prop", "ThreePrimeRST", "ncbi_dbest"),
                Arrays.asList(new SetFieldConfigAction("NCBIdbEST")));
        map.put(new MultiKey("prop", "ThreePrimeUTR", "external_evidence"),
                Arrays.asList(new SetFieldConfigAction("externalEvidence")));
        map.put(new MultiKey("prop", "BindingSite", "qvalue"),
                Arrays.asList(new SetFieldConfigAction("qvalue")));
        map.put(new MultiKey("prop", "Exon", "acceptor"), Arrays.asList(new SetFieldConfigAction("acceptor")));
        map.put(new MultiKey("prop", "Exon", "connected_to_wormbase_transcript"),
                Arrays.asList(new SetFieldConfigAction("connectedToWormbaseTranscript")));
        map.put(new MultiKey("prop", "Exon", "donor"), Arrays.asList(new SetFieldConfigAction("donor")));
        map.put(new MultiKey("prop", "Exon", "overlapping_wormbase_transcript"),
                Arrays.asList(new SetFieldConfigAction("overlappingWormbaseTranscript")));
        map.put(new MultiKey("prop", "Exon", "polyA"), Arrays.asList(new SetFieldConfigAction("polyA")));
        map.put(new MultiKey("prop", "Exon", "tes"), Arrays.asList(new SetFieldConfigAction("tes")));
        map.put(new MultiKey("prop", "Exon", "tsl"), Arrays.asList(new SetFieldConfigAction("tsl")));
        map.put(new MultiKey("prop", "Exon", "tss"), Arrays.asList(new SetFieldConfigAction("tss")));
        map.put(new MultiKey("prop", "OverlappingESTSet", "fdr"),
                Arrays.asList(new SetFieldConfigAction("fdr")));
        map.put(new MultiKey("prop", "OverlappingESTSet", "fp"), Arrays.asList(new SetFieldConfigAction("fp")));
        map.put(new MultiKey("prop", "OverlappingESTSet", "overlap"),
                Arrays.asList(new SetFieldConfigAction("overlap")));
        map.put(new MultiKey("prop", "OverlappingESTSet", "reads"),
                Arrays.asList(new SetFieldConfigAction("reads")));
        map.put(new MultiKey("prop", "OverlappingESTSet", "strands_confirmed"),
                Arrays.asList(new SetFieldConfigAction("strandsConfirmed")));
        map.put(new MultiKey("prop", "OverlappingESTSet", "trimT"),
                Arrays.asList(new SetFieldConfigAction("trimT")));
        map.put(new MultiKey("prop", "Transcript", "transcribed"),
                Arrays.asList(new SetFieldConfigAction("transcribed")));
        map.put(new MultiKey("prop", "TranscriptRegion", "marginal_fpr"),
                Arrays.asList(new SetFieldConfigAction("marginalFpr")));
        map.put(new MultiKey("prop", "TranscriptRegion", "marginal_sensitivity"),
                Arrays.asList(new SetFieldConfigAction("marginalSensitivity")));
        map.put(new MultiKey("prop", "TranscriptRegion", "mean_intensity"),
                Arrays.asList(new SetFieldConfigAction("meanIntensity")));
        map.put(new MultiKey("prop", "TranscriptRegion", "rank_score"),
                Arrays.asList(new SetFieldConfigAction("rankScore")));
        map.put(new MultiKey("prop", "SequenceFeature", "prediction_status"),
                Arrays.asList(new SetFieldConfigAction("predictionStatus")));
        map.put(new MultiKey("prop", "SequenceFeature", "note"),
                Arrays.asList(new SetFieldConfigAction("note")));
    }
    return map;
}

From source file:org.intermine.bio.dataconversion.SequenceProcessor.java

/**
 * Create and store a new InterMineObject given data from a row of the feature table in a
 * Chado database.//ww  w  .ja va  2 s. co m
 * @param featureId the chado id from the feature table
 * @param uniqueName the uniquename from Chado
 * @param name the name from Chado
 * @param seqlen the sequence length from Chado
 * @param residues the residues from Chado
 * @param md5checksum the MD5 checksum of the residues
 * @param chadoType the type of the feature from the feature + cvterm tables
 * @param organismId the chado organism id
 * @throws ObjectStoreException if there is a problem while storing
 */
private boolean processAndStoreFeature(Integer featureId, String uniqueName, String name, int seqlen,
        String residues, String md5checksum, String chadoType, Integer organismId) throws ObjectStoreException {

    if (featureMap.containsKey(featureId)) {
        return false;
    }

    FeatureData fdat = makeFeatureData(featureId.intValue(), chadoType, uniqueName, name, md5checksum, seqlen,
            organismId.intValue());

    if (fdat == null) {
        return false;
    }

    String fixedUniqueName = fixIdentifier(fdat, uniqueName);

    if (seqlen > 0) {
        setAttributeIfNotSet(fdat, "length", String.valueOf(seqlen));
    }
    ChadoDBConverter chadoDBConverter = getChadoDBConverter();

    String dataSourceName = chadoDBConverter.getDataSourceName();
    MultiKey nameKey = new MultiKey("feature", fdat.getInterMineType(), dataSourceName, "name");
    OrganismData orgData = fdat.getOrganismData();
    List<ConfigAction> nameActionList = getConfig(orgData.getTaxonId()).get(nameKey);

    // check interMineType not chadoType - FlyBase subclass converts some Genes to Alleles
    if (fdat.getInterMineType().endsWith("Gene")) {
        //          setGeneSource(fdat.getIntermineObjectId(), dataSourceName);
        setGeneSource(fdat, dataSourceName);
        // special case for modENCODE
        if ("modENCODE".equalsIgnoreCase(dataSourceName)) {
            fixedUniqueName = fixIdentifier(fdat, fdat.getUniqueName());
        }
    }

    Set<String> fieldValuesSet = new HashSet<String>();
    String fixedName = fixIdentifier(fdat, name);

    // using the configuration, set a field to be the feature name
    if (!StringUtils.isBlank(fixedName)) {
        if (nameActionList == null || nameActionList.size() == 0) {
            fieldValuesSet.add(fixedName);
            setAttributeIfNotSet(fdat, SECONDARY_IDENTIFIER_STRING, fixedName);
        } else {
            for (ConfigAction action : nameActionList) {
                if (action instanceof SetFieldConfigAction) {
                    SetFieldConfigAction attrAction = (SetFieldConfigAction) action;
                    if (attrAction.isValidValue(fixedName)) {
                        String newFieldValue = attrAction.processValue(fixedName);
                        setAttributeIfNotSet(fdat, attrAction.getFieldName(), newFieldValue);
                        fieldValuesSet.add(newFieldValue);
                    }
                }
            }
        }
    }

    MultiKey uniqueNameKey = new MultiKey("feature", fdat.getInterMineType(), dataSourceName, "uniquename");
    List<ConfigAction> uniqueNameActionList = getConfig(fdat.getOrganismData().getTaxonId()).get(uniqueNameKey);
    if (uniqueNameActionList == null || uniqueNameActionList.size() == 0) {
        // default: set primaryIdentifier to be the uniquename
        setAttributeIfNotSet(fdat, "primaryIdentifier", fixedUniqueName);
        fieldValuesSet.add(fixedUniqueName);
    } else {
        // using the configuration, set a field to be the feature name
        for (ConfigAction action : uniqueNameActionList) {
            if (action instanceof SetFieldConfigAction) {
                SetFieldConfigAction attrAction = (SetFieldConfigAction) action;
                if (attrAction.isValidValue(fixedUniqueName)) {
                    String newFieldValue = attrAction.processValue(fixedUniqueName);
                    setAttributeIfNotSet(fdat, attrAction.getFieldName(), newFieldValue);
                    fieldValuesSet.add(newFieldValue);
                }
            }
        }
    }

    // set the BioEntity sequence if there is one
    if (fdat.checkField(SEQUENCE_STRING) && residues != null && residues.length() > 0) {
        if (!fdat.getFlag(SEQUENCE_STRING)) {
            Item sequence = getChadoDBConverter().createItem("Sequence");
            sequence.setAttribute("residues", residues);
            sequence.setAttribute("length", String.valueOf(seqlen));
            Reference chrReference = new Reference();
            chrReference.setName(SEQUENCE_STRING);
            chrReference.setRefId(sequence.getIdentifier());
            getChadoDBConverter().store(chrReference, fdat.getIntermineObjectId());
            getChadoDBConverter().store(sequence);
            fdat.setFlag(SEQUENCE_STRING, true);
        }
    }

    // create a synonym for name, if configured
    if (!StringUtils.isBlank(name)) {
        if (nameActionList != null) {
            for (ConfigAction action : nameActionList) {
                if (action instanceof CreateSynonymAction) {
                    CreateSynonymAction createSynonymAction = (CreateSynonymAction) action;
                    if (createSynonymAction.isValidValue(fixedName)) {
                        String processedName = createSynonymAction.processValue(fixedName);
                        if (!fdat.getExistingSynonyms().contains(processedName)) {
                            Item nameSynonym = createSynonym(fdat, processedName);
                            if (nameSynonym != null) {
                                getChadoDBConverter().store(nameSynonym);
                            }
                        }
                    }
                }
            }
        }
    }

    addToFeatureMap(featureId, fdat);

    return true;
}

From source file:org.intermine.bio.dataconversion.SequenceProcessor.java

/**
 * Create collections and references for the Item given by chadoSubjectId.
 * @param collectionWarnings//w  w w.  ja  v  a2  s.  co  m
 */
private boolean processCollectionData(Integer chadoSubjectId,
        Map<String, Map<String, List<FeatureData>>> relTypeMap, int collectionWarnings, boolean subjectIsFirst)
        throws ObjectStoreException {
    FeatureData subjectData = featureMap.get(chadoSubjectId);
    if (subjectData == null) {
        if (collectionWarnings < 20) {
            LOG.warn("unknown feature " + chadoSubjectId + " passed to processCollectionData - " + "ignoring");
        }
        return false;
    }

    // map from collection name to list of item ids
    Map<String, List<String>> collectionsToStore = new HashMap<String, List<String>>();

    String subjectInterMineType = subjectData.getInterMineType();
    ClassDescriptor cd = getModel().getClassDescriptorByName(subjectInterMineType);
    Integer intermineObjectId = subjectData.getIntermineObjectId();
    for (Map.Entry<String, Map<String, List<FeatureData>>> entry : relTypeMap.entrySet()) {
        String relationType = entry.getKey();
        Map<String, List<FeatureData>> objectClassFeatureDataMap = entry.getValue();

        Set<Entry<String, List<FeatureData>>> mapEntries = objectClassFeatureDataMap.entrySet();
        for (Map.Entry<String, List<FeatureData>> featureDataMap : mapEntries) {
            String objectClass = featureDataMap.getKey();
            List<FeatureData> featureDataCollection = featureDataMap.getValue();
            List<FieldDescriptor> fds = null;

            FeatureData subjectFeatureData = featureMap.get(chadoSubjectId);
            // key example: ("relationship", "Protein", "producedby", "MRNA")
            String relType;
            if (subjectIsFirst) {
                relType = "relationship";
            } else {
                relType = "rev_relationship";
            }
            MultiKey key = new MultiKey(relType, subjectFeatureData.getInterMineType(), relationType,
                    objectClass);
            List<ConfigAction> actionList = getConfig(subjectData.organismData.getTaxonId()).get(key);

            if (actionList != null) {
                if (actionList.size() == 0
                        || actionList.size() == 1 && actionList.get(0) instanceof DoNothingAction) {
                    // do nothing
                    continue;
                }
                fds = new ArrayList<FieldDescriptor>();
                for (ConfigAction action : actionList) {
                    if (action instanceof SetFieldConfigAction) {
                        SetFieldConfigAction setAction = (SetFieldConfigAction) action;
                        String fieldName = setAction.getFieldName();
                        FieldDescriptor fd = cd.getFieldDescriptorByName(fieldName);
                        if (fd == null) {
                            throw new RuntimeException("can't find field " + fieldName + " in class " + cd
                                    + " configured for " + key);
                        }
                        fds.add(fd);

                    }
                }
                if (fds.size() == 0) {
                    throw new RuntimeException("no actions found for " + key);
                }
            } else {
                if (PARTOF_RELATIONS.contains(relationType)) {
                    // special case for part_of relations - try to find a reference or
                    // collection that has a name that looks right for these objects (of class
                    // objectClass).  eg.  If the subject is a Transcript and the objectClass
                    // is Exon then find collections called "exons", "geneParts" (GenePart is
                    // a superclass of Exon)
                    fds = getReferenceForRelationship(objectClass, cd);
                } else {
                    continue;
                }
            }

            if (fds.size() == 0) {
                if (!loggedMissingCols.contains(subjectInterMineType + relationType)) {
                    LOG.error("can't find collection for type " + objectClass + " with relationship "
                            + relationType + " in " + subjectInterMineType + " (was processing feature "
                            + chadoSubjectId + ")");
                    loggedMissingCols.add(subjectInterMineType + relationType);
                }
                continue;
            }

            for (FieldDescriptor fd : fds) {
                if (fd.isReference()) {
                    if (objectClassFeatureDataMap.size() > 1) {
                        throw new RuntimeException("found more than one object for reference " + fd
                                + " in class " + subjectInterMineType + " current subject identifier: "
                                + subjectData.getUniqueName());
                    }
                    if (objectClassFeatureDataMap.size() == 1) {
                        Reference reference = new Reference();
                        reference.setName(fd.getName());
                        FeatureData referencedFeatureData = featureDataCollection.get(0);
                        reference.setRefId(referencedFeatureData.getItemIdentifier());
                        getChadoDBConverter().store(reference, intermineObjectId);

                        // special case for 1-1 relations - we need to set the reverse
                        // reference
                        ReferenceDescriptor rd = (ReferenceDescriptor) fd;
                        ReferenceDescriptor reverseRD = rd.getReverseReferenceDescriptor();
                        if (reverseRD != null && !reverseRD.isCollection()) {
                            Reference revReference = new Reference();
                            revReference.setName(reverseRD.getName());
                            revReference.setRefId(subjectData.getItemIdentifier());
                            Integer refObjectId = referencedFeatureData.getIntermineObjectId();
                            getChadoDBConverter().store(revReference, refObjectId);
                        }
                    }

                } else {
                    List<String> itemIds;
                    if (collectionsToStore.containsKey(fd.getName())) {
                        itemIds = collectionsToStore.get(fd.getName());
                    } else {
                        itemIds = new ArrayList<String>();
                        collectionsToStore.put(fd.getName(), itemIds);
                    }
                    for (FeatureData featureData : featureDataCollection) {
                        itemIds.add(featureData.getItemIdentifier());
                    }
                }
            }
        }
    }

    for (Map.Entry<String, List<String>> entry : collectionsToStore.entrySet()) {
        ReferenceList referenceList = new ReferenceList();
        String collectionName = entry.getKey();
        referenceList.setName(collectionName);
        List<String> idList = entry.getValue();
        referenceList.setRefIds(idList);
        getChadoDBConverter().store(referenceList, intermineObjectId);

        // if there is a field called <classname>Count that matches the name of the collection
        // we just stored, set it
        String countName;
        if (collectionName.endsWith("s")) {
            countName = collectionName.substring(0, collectionName.length() - 1);
        } else {
            countName = collectionName;
        }
        countName += "Count";
        if (cd.getAttributeDescriptorByName(countName, true) != null) {
            setAttribute(intermineObjectId, countName, String.valueOf(idList.size()));
        }
    }

    return true;
}

From source file:org.intermine.bio.dataconversion.SequenceProcessor.java

@SuppressWarnings("boxing")
private void processDbxrefTable(Connection connection) throws SQLException, ObjectStoreException {

    ResultSet res = getDbxrefResultSet(connection);
    Set<String> existingAttributes = new HashSet<String>();
    Integer currentFeatureId = null;
    int count = 0;

    while (res.next()) {
        Integer featureId = new Integer(res.getInt("feature_id"));
        String accession = res.getString("accession");
        String dbName = res.getString("db_name");
        Boolean isCurrent = res.getBoolean("is_current");

        if (currentFeatureId != null && currentFeatureId != featureId) {
            existingAttributes = new HashSet<String>();
        }//from   w ww. j  a  v  a  2  s  . c o m

        if (featureMap.containsKey(featureId)) {
            FeatureData fdat = featureMap.get(featureId);
            MultiKey key = new MultiKey("dbxref", fdat.getInterMineType(), dbName, isCurrent);

            if (accession == null) {
                throw new RuntimeException("found null accession in dbxref table for database " + dbName + ".");
            }
            accession = fixIdentifier(fdat, accession);

            int taxonId = fdat.organismData.getTaxonId();
            Map<MultiKey, List<ConfigAction>> orgConfig = getConfig(taxonId);
            List<ConfigAction> actionList = orgConfig.get(key);

            if (actionList == null) {
                // try ignoring isCurrent
                MultiKey key2 = new MultiKey("dbxref", fdat.getInterMineType(), dbName, null);
                actionList = orgConfig.get(key2);
            }

            if (actionList == null) {
                // no actions configured for this synonym
                continue;
            }
            Set<String> fieldsSet = new HashSet<String>();
            for (ConfigAction action : actionList) {
                if (action instanceof SetFieldConfigAction) {
                    SetFieldConfigAction setAction = (SetFieldConfigAction) action;
                    if (!existingAttributes.contains(setAction.getFieldName())) {
                        if (setAction.isValidValue(accession)) {
                            String newFieldValue = setAction.processValue(accession);
                            setAttribute(fdat.getIntermineObjectId(), setAction.getFieldName(), newFieldValue);
                            existingAttributes.add(setAction.getFieldName());
                            fieldsSet.add(newFieldValue);
                            if ("primaryIdentifier".equals(setAction.getFieldName())) {
                                fdat.setFlag(FeatureData.IDENTIFIER_SET, true);
                            }
                        }
                    }
                }
            }

            for (ConfigAction action : actionList) {
                if (action instanceof CreateSynonymAction) {
                    CreateSynonymAction createSynonymAction = (CreateSynonymAction) action;
                    if (!createSynonymAction.isValidValue(accession)) {
                        continue;
                    }
                    String newFieldValue = createSynonymAction.processValue(accession);
                    if (fdat.getExistingSynonyms().contains(newFieldValue)) {
                        continue;
                    }
                    Item synonym = createSynonym(fdat, newFieldValue);
                    if (synonym != null) {
                        getChadoDBConverter().store(synonym);
                        count++;
                    }
                }
            }
        }

        currentFeatureId = featureId;
    }

    LOG.info("created " + count + " synonyms from the dbxref table");
    res.close();
}

From source file:org.intermine.bio.dataconversion.SequenceProcessor.java

@SuppressWarnings("boxing")
private void processSynonymTable(Connection connection) throws SQLException, ObjectStoreException {
    ResultSet res = getSynonymResultSet(connection);
    Set<String> existingAttributes = new HashSet<String>();
    Integer currentFeatureId = null;
    int count = 0;
    while (res.next()) {
        Integer featureId = new Integer(res.getInt("feature_id"));
        String identifier = res.getString("synonym_name");
        String synonymTypeName = res.getString("type_name");

        // change type so synonyms will merge correctly
        if ("primaryAccession".equals(synonymTypeName)) {
            synonymTypeName = "accession";
        } else if ("primaryIdentifier".equals(synonymTypeName)) {
            synonymTypeName = "identifier";
        }//from  ww  w. j  a v  a 2s .  c o m

        Boolean isCurrent = res.getBoolean("is_current");

        // it is a not null in db
        if (identifier == null) {
            throw new RuntimeException("found null synonym name in synonym table.");
        }
        identifier = fixIdentifier(featureMap.get(featureId), identifier);

        if (currentFeatureId != null && currentFeatureId != featureId) {
            existingAttributes = new HashSet<String>();
        }

        if (featureMap.containsKey(featureId)) {
            FeatureData fdat = featureMap.get(featureId);
            identifier = fixIdentifier(fdat, identifier);
            MultiKey key = new MultiKey("synonym", fdat.getInterMineType(), synonymTypeName, isCurrent);
            int taxonId = fdat.organismData.getTaxonId();
            Map<MultiKey, List<ConfigAction>> orgConfig = getConfig(taxonId);
            List<ConfigAction> actionList = orgConfig.get(key);

            if (actionList == null) {
                // try ignoring isCurrent
                MultiKey key2 = new MultiKey("synonym", fdat.getInterMineType(), synonymTypeName, null);
                actionList = orgConfig.get(key2);
            }
            if (actionList == null) {
                // no actions configured for this synonym
                continue;
            }
            for (ConfigAction action : actionList) {
                if (action instanceof SetFieldConfigAction) {
                    SetFieldConfigAction setAction = (SetFieldConfigAction) action;
                    if (!existingAttributes.contains(setAction.getFieldName())
                            && setAction.isValidValue(identifier)) {
                        String newFieldValue = setAction.processValue(identifier);
                        setAttribute(fdat.getIntermineObjectId(), setAction.getFieldName(), newFieldValue);
                        existingAttributes.add(setAction.getFieldName());
                        if ("primaryIdentifier".equals(setAction.getFieldName())) {
                            fdat.setFlag(FeatureData.IDENTIFIER_SET, true);
                        }
                    }
                }
            }

            for (ConfigAction action : actionList) {
                if (action instanceof CreateSynonymAction) {
                    CreateSynonymAction createSynonymAction = (CreateSynonymAction) action;
                    if (!createSynonymAction.isValidValue(identifier)) {
                        continue;
                    }
                    String newFieldValue = createSynonymAction.processValue(identifier);
                    if (fdat.getExistingSynonyms().contains(newFieldValue)) {
                        continue;
                    }
                    Item synonym = createSynonym(fdat, newFieldValue);
                    if (synonym != null) {
                        getChadoDBConverter().store(synonym);
                        count++;
                    }
                }
            }
        }
        currentFeatureId = featureId;
    }

    LOG.info("created " + count + " synonyms from the synonym table");
    res.close();
}