/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.mskcc.cbio.oncokb.importer;

import org.mskcc.cbio.oncokb.model.Alteration;
import org.mskcc.cbio.oncokb.model.Evidence;
import org.mskcc.cbio.oncokb.model.Gene;
import org.mskcc.cbio.oncokb.model.LevelOfEvidence;
import org.mskcc.cbio.oncokb.util.AlterationUtils;
import org.mskcc.cbio.oncokb.util.ApplicationContextSingleton;
import org.mskcc.cbio.oncokb.util.LevelUtils;

import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author zhangh2 
 */

public class AlterationLevel {
    private AlterationLevel() {
        throw new AssertionError();
    }

    public static void main(String[] args) throws IOException {
        List<Gene> genes = ApplicationContextSingleton.getGeneBo().findAll();

        System.out.println("Gene\tAlteration\tLevel");
        for (Gene gene : genes) {
            List<Alteration> alterations = ApplicationContextSingleton.getAlterationBo().findAlterationsByGene(Collections.singleton(gene));
            Set<Alteration> alterationsWithoutVUS = AlterationUtils.excludeVUS(new HashSet<>(alterations));
            for (Alteration alteration : alterationsWithoutVUS) {
                List<Alteration> relevantAlts = ApplicationContextSingleton.getAlterationBo().findRelevantAlterations(alteration, alterations);
                List<Evidence> relevantEvidences = ApplicationContextSingleton.getEvidenceBo().findEvidencesByAlteration(relevantAlts);
                LevelOfEvidence levelOfEvidence = LevelUtils.getHighestLevelFromEvidence(new HashSet<>(relevantEvidences));
                String level = "NA";

                if (levelOfEvidence != null && levelOfEvidence.getLevel() != null) {
                    level = levelOfEvidence.getLevel().toUpperCase();
                }
                System.out.println(gene.getHugoSymbol() + "\t" + alteration.getAlteration() + "\t" + level);
            }
        }
    }
}

@@ -149,128 +149,40 @@
 org.
-mskcc.cbio.oncokb.model.Alteration;%0Aimport org.mskcc.cbio.oncokb.model.Evidence;%0Aimport org.mskcc.cbio.oncokb.model.Gene
+apache.commons.lang3.StringUtils
 ;%0Aim
@@ -214,31 +214,17 @@
 b.model.
-LevelOfEvidence
+*
 ;%0Aimport
@@ -335,182 +335,55 @@
 on;%0A
-import org.mskcc.cbio.oncokb.util.LevelUtils;%0A%0Aimport java.io.IOException;%0Aimport java.util.Collections;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set
+%0Aimport java.io.IOException;%0Aimport java.util.*
 ;%0A%0A/
@@ -403,17 +403,16 @@
  zhangh2
- 
 %0A */%0A%0Apu
@@ -1338,24 +1338,26 @@
 evantAlts);%0A
+//
             
@@ -1464,24 +1464,233 @@
 vidences));%0A
+%0A                for (Evidence evidence : relevantEvidences) %7B%0A                    LevelOfEvidence level = evidence.getLevelOfEvidence();%0A                    TumorType tumorType = evidence.getTumorType();%0A    
             
@@ -1709,18 +1709,23 @@
 evel
+Str
  = %22
-NA
 %22;%0A%0A
+    
     
@@ -1745,26 +1745,16 @@
 f (level
-OfEvidence
  != null
@@ -1758,34 +1758,24 @@
 ull && level
-OfEvidence
 .getLevel() 
@@ -1809,21 +1809,28 @@
     
+    
 level
+Str
  = level
 OfEv
@@ -1829,171 +1829,1595 @@
 evel
-OfEvidence.getLevel().toUpperCase();%0A                %7D%0A                System.out.println(gene.getHugoSymbol() + %22%5Ct%22 + alteration.getAlteration() + %22%5Ct%22 + level);
+.getLevel().toUpperCase();%0A                    %7D%0A%0A                    if (tumorType != null) %7B%0A                        String tumorTypeStr = tumorType.getName();%0A                        Set%3CTreatment%3E treatments = evidence.getTreatments();%0A                        List%3CString%3E treatmentNames = new ArrayList%3C%3E();%0A%0A                        for (Treatment treatment : treatments) %7B%0A                            Set%3CDrug%3E drugs = treatment.getDrugs();%0A                            List%3CString%3E drugNames = new ArrayList%3C%3E();%0A%0A                            for (Drug drug : drugs) %7B%0A                                if (drug.getDrugName() != null) %7B%0A                                    drugNames.add(drug.getDrugName());%0A                                %7D%0A                            %7D%0A                            String drugStr = StringUtils.join(drugNames, %22 + %22);%0A%0A                            treatmentNames.add(drugStr);%0A                        %7D%0A%0A                        String treatmentStr = StringUtils.join(treatmentNames, %22, %22);%0A                        %0A                        if (treatmentStr != null && !treatmentStr.equals(%22%22)) %7B%0A                            System.out.println(gene.getHugoSymbol() + %22%5Ct%22 + alteration.getAlteration() + %22%5Ct%22 + tumorTypeStr + %22%5Ct%22 + levelStr + %22%5Ct%22 + treatmentStr);%0A                        %7D%0A                    %7D%0A                %7D%0A%0A//                String level = %22NA%22;%0A//%0A//                if (levelOfEvidence != null && levelOfEvidence.getLevel() != null) %7B%0A//                    level = levelOfEvidence.getLevel().toUpperCase();%0A//                %7D
 %0A   

Update alteration level