Example usage for org.apache.commons.collections.map MultiKeyMap containsKey

List of usage examples for org.apache.commons.collections.map MultiKeyMap containsKey

Introduction

In this page you can find the example usage for org.apache.commons.collections.map MultiKeyMap containsKey.

Prototype

public boolean containsKey(Object key1, Object key2) 

Source Link

Document

Checks whether the map contains the specified multi-key.

Usage

From source file:com.amalto.core.server.StorageAdminImpl.java

public String[] getAll() {
    Set<String> allStorageNames = new HashSet<>();
    for (Map.Entry<String, MultiKeyMap> currentStorage : storages.entrySet()) {
        MultiKeyMap value = currentStorage.getValue();
        if (value.containsKey(StringUtils.EMPTY, StorageType.MASTER)) {
            allStorageNames.add(currentStorage.getKey());
        }/* w  w w  . j av  a2  s.  c  o  m*/
        if (value.containsKey(StringUtils.EMPTY, StorageType.STAGING)) {
            allStorageNames.add(currentStorage.getKey());
        }
    }
    return allStorageNames.toArray(new String[allStorageNames.size()]);
}

From source file:org.cbio.portal.pipelines.foundation.CnaDataReader.java

/**
 * Generate map of gene to CNA data /*from w  w w  . ja  va2 s.c o  m*/
 * @param fmiCaseMap
 * @return 
 */
private List<String> generateCnaRowData(Map<String, CaseType> fmiCaseTypeMap) {
    Set<String> geneList = new HashSet<>();
    MultiKeyMap cnaMap = new MultiKeyMap();

    int noCnaCount = 0; // keep track of how many cases don't have copy number data
    for (CaseType ct : fmiCaseTypeMap.values()) {
        List<CopyNumberAlterationType> cnaTypeList = ct.getVariantReport().getCopyNumberAlterations()
                .getCopyNumberAlteration();
        if (cnaTypeList != null) {
            for (CopyNumberAlterationType cnaType : cnaTypeList) {
                cnaMap.put(cnaType.getGene(), ct.getCase(), FoundationUtils.resolveCnaType(cnaType));
                geneList.add(cnaType.getGene());
            }
        } else {
            noCnaCount++;
        }
    }
    if (noCnaCount > 0) {
        LOG.info("Number of cases without CNA data: " + noCnaCount);
    }

    // format row data for CNA file                
    List<String> cnaRowData = new ArrayList();
    for (String gene : geneList) {
        List<String> geneCnaData = new ArrayList();
        geneCnaData.add(gene);
        for (String caseId : fmiCaseTypeMap.keySet()) {
            if (cnaMap.containsKey(gene, caseId)) {
                geneCnaData.add((String) cnaMap.get(gene, caseId));
            } else {
                geneCnaData.add("0");
            }

        }
        cnaRowData.add(StringUtils.join(geneCnaData, "\t"));
    }

    return cnaRowData;
}

From source file:org.mskcc.cbio.portal.scripts.ImportClinicalData.java

private boolean addDatum(String[] fields, List<ClinicalAttribute> columnAttrs, MultiKeyMap attributeMap)
        throws Exception {
    int sampleIdIndex = findSampleIdColumn(columnAttrs);
    String stableSampleId = (sampleIdIndex >= 0) ? fields[sampleIdIndex] : "";
    stableSampleId = StableIdUtil.getSampleId(stableSampleId);
    int patientIdIndex = findPatientIdColumn(columnAttrs);
    String stablePatientId = (patientIdIndex >= 0) ? fields[patientIdIndex] : "";
    stablePatientId = StableIdUtil.getPatientId(stablePatientId);
    int internalSampleId = -1;
    int internalPatientId = -1;

    //check if sample is not already added:
    Sample sample = DaoSample.getSampleByCancerStudyAndSampleId(cancerStudy.getInternalId(), stableSampleId,
            false);/*from w w w.ja v a2  s . c  o  m*/
    if (sample != null) {
        //this should be a WARNING in case of TCGA studies (see https://github.com/cBioPortal/cbioportal/issues/839#issuecomment-203452415)
        //and an ERROR in other studies. I.e. a sample should occur only once in clinical file!
        if (stableSampleId.startsWith("TCGA-")) {
            ProgressMonitor.logWarning("Sample " + stableSampleId
                    + " found to be duplicated in your file. Only data of the first sample will be processed.");
            return false;
        }
        //give error or warning if sample is already in DB and this is NOT expected (i.e. not supplemental data):
        if (!this.isSupplementalData()) {
            throw new RuntimeException(
                    "Error: Sample " + stableSampleId + " found to be duplicated in your file.");
        } else {
            internalSampleId = sample.getInternalId();
        }
    } else {
        Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudy.getInternalId(),
                stablePatientId);
        if (patient != null) {
            //patient exists, get internal id:
            internalPatientId = patient.getInternalId();
        } else {
            //add patient:
            internalPatientId = (patientIdIndex >= 0) ? addPatientToDatabase(fields[patientIdIndex]) : -1;
        }
        // sample is new, so attempt to add to DB
        internalSampleId = (stableSampleId.length() > 0)
                ? addSampleToDatabase(stableSampleId, fields, columnAttrs)
                : -1;

    }

    //validate and count:
    if (internalSampleId != -1) {
        //some minimal validation/fail safe for now: only continue if patientId is same as patient id in 
        //existing sample (can occur in case of this.isSupplementalData or in case of parsing bug in addSampleToDatabase):
        internalPatientId = DaoPatient
                .getPatientByCancerStudyAndPatientId(cancerStudy.getInternalId(), stablePatientId)
                .getInternalId();
        if (internalPatientId != DaoSample.getSampleById(internalSampleId).getInternalPatientId()) {
            throw new RuntimeException("Error: Sample " + stableSampleId
                    + " was previously linked to another patient, and not to " + stablePatientId);
        }
        numSamplesProcessed++;
    }

    // this will happen when clinical file contains sample id, but not patient id
    //TODO - this part, and the dummy patient added in addSampleToDatabase, can be removed as the field PATIENT_ID is now
    //always required (as validated at start of importData() ). Probably kept here for "old" studies, but Ben's tests did not find anything...
    // --> alternative would be to be less strict in validation at importData() and allow for missing PATIENT_ID when type is MIXED... 
    if (internalPatientId == -1 && internalSampleId != -1) {
        sample = DaoSample.getSampleById(internalSampleId);
        internalPatientId = sample.getInternalPatientId();
    }

    for (int lc = 0; lc < fields.length; lc++) {
        //if lc is sampleIdIndex or patientIdIndex, skip as well since these are the relational fields:
        if (lc == sampleIdIndex || lc == patientIdIndex) {
            continue;
        }
        //if the value matches one of the missing values, skip this attribute:
        if (MissingAttributeValues.has(fields[lc])) {
            numEmptyClinicalAttributesSkipped++;
            continue;
        }
        boolean isPatientAttribute = columnAttrs.get(lc).isPatientAttribute();
        if (isPatientAttribute && internalPatientId != -1) {
            // The attributeMap keeps track what  patient/attribute to value pairs are being added to the DB. If there are duplicates,
            // (which can happen in a MIXED_ATTRIBUTES type clinical file), we need to make sure that the value for the same
            // attributes are consistent. This prevents duplicate entries in the temp file that the MySqlBulkLoader uses.
            if (!attributeMap.containsKey(internalPatientId, columnAttrs.get(lc).getAttrId())) {
                addDatum(internalPatientId, columnAttrs.get(lc).getAttrId(), fields[lc],
                        ClinicalAttribute.PATIENT_ATTRIBUTE);
                attributeMap.put(internalPatientId, columnAttrs.get(lc).getAttrId(), fields[lc]);
            } else if (!relaxed) {
                throw new RuntimeException("Error: Duplicated patient in file");
            } else if (!attributeMap.get(internalPatientId, columnAttrs.get(lc).getAttrId())
                    .equals(fields[lc])) {
                ProgressMonitor.logWarning("Error: Duplicated patient " + stablePatientId
                        + " with different values for patient attribute " + columnAttrs.get(lc).getAttrId()
                        + "\n\tValues: " + attributeMap.get(internalPatientId, columnAttrs.get(lc).getAttrId())
                        + " " + fields[lc]);
            }
        } else if (internalSampleId != -1) {
            if (!attributeMap.containsKey(internalSampleId, columnAttrs.get(lc).getAttrId())) {
                addDatum(internalSampleId, columnAttrs.get(lc).getAttrId(), fields[lc],
                        ClinicalAttribute.SAMPLE_ATTRIBUTE);
                attributeMap.put(internalSampleId, columnAttrs.get(lc).getAttrId(), fields[lc]);
            } else if (!relaxed) {
                throw new RuntimeException("Error: Duplicated sample in file");
            } else if (!attributeMap.get(internalSampleId, columnAttrs.get(lc).getAttrId())
                    .equals(fields[lc])) {
                ProgressMonitor.logWarning("Error: Duplicated sample " + stableSampleId
                        + " with different values for sample attribute " + columnAttrs.get(lc).getAttrId()
                        + "\n\tValues: " + attributeMap.get(internalSampleId, columnAttrs.get(lc).getAttrId())
                        + " " + fields[lc]);
            }
        }
    }
    return true;
}