Changeset 782


Ignore:
Timestamp:
Jun 12, 2012, 8:53:46 PM (4 years ago)
Author:
hailiang.mei@…
Message:

added unittest for umls-sp mapping.

Location:
trunk/code/conceptwiki
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/code/conceptwiki/common/common-api/src/main/java/nl/nbic/conceptwiki/common/api/Concept.java

    r781 r782  
    9494    /**
    9595     * Check whether there is any difference between this concept and a target POJO concept.
    96      * It is almost the same as ConceptImpl.equals but skipping the uuid comparison. 
     96     * It is almost the same as ConceptImpl.equals but skipping the uuid comparison.
     97     * @param target the POJO concept to be compared with. 
    9798     * @return {@code boolean} true if equals, false otherwise.
    9899     */
  • trunk/code/conceptwiki/common/common-api/src/main/java/nl/nbic/conceptwiki/common/impl/ConceptImpl.java

    r781 r782  
    251251
    252252    @Override
    253     public boolean equalsPOJO(Concept target) {
     253    public boolean equalsPOJO(final Concept target) {
    254254       
    255255        return Objects.equal(labels, target.getLabels())
  • trunk/code/conceptwiki/imports/imports-common/src/main/java/nl/nbic/conceptwiki/imports/common/AbstractConceptImporter.java

    r781 r782  
    131131                // calculate diff
    132132                final ConceptChangeset diff = conceptUtility.getDiff(target, concept);
    133                
     133                               
    134134                conceptService.updateConcept(target.getUuid(), diff, importBranch);
    135135            } else {
  • trunk/code/conceptwiki/imports/imports-swissprot/src/main/java/nl/nbic/conceptwiki/imports/swissprot/SwissProtImporter.java

    r781 r782  
    223223                for (Concept result: results) {
    224224                    if (result.getTags().contains(tag)) {
    225                       return result;
     225                        return result;
    226226                    }
    227227                }
  • trunk/code/conceptwiki/imports/imports-swissprot/src/main/java/nl/nbic/conceptwiki/imports/swissprot/SwissProtReader.java

    r781 r782  
    329329     */
    330330    private Iterator<Concept> getBootstrapTagsInternal() throws XMLStreamException, JAXBException, IOException {
    331         final Set<Concept> bootstrapTags = Sets.newHashSet();
     331       
     332        // Some bootstrap concepts should be made as tags.
     333        final Set<Concept> bootstrapTags = Sets.newHashSet(swissProtSource, proteinSemanticType, geneSemanticType, species);
    332334        final Map<String, Concept> bootstrapGenericProteinTags = Maps.newHashMap();
    333         final Map<String, Concept> bootstrapGenericGeneTags = Maps.newHashMap();
    334        
    335         Concept genericProteinConcept;
    336         Concept genericGeneConcept;
    337        
    338         // Some bootstrap concepts should be made as tags.
    339         bootstrapTags.add(swissProtSource);       
    340         bootstrapTags.add(proteinSemanticType);
    341         bootstrapTags.add(geneSemanticType);
    342         bootstrapTags.add(species);
     335        final Map<String, Concept> bootstrapGenericGeneTags = Maps.newHashMap();               
    343336       
    344337        final XMLInputFactory xif = XMLInputFactory.newInstance();           
     
    354347           
    355348            // store generic protein tag if new
    356             genericProteinConcept = getGenericProteinTagFromEntry(entry);
    357             final String proteinRecommendedName = conceptUtility.getPreferredLabel(genericProteinConcept, LANG_EN).getText();
     349            final Concept genericProteinConcept = getGenericProteinTagFromEntry(entry);
     350            final String proteinAccession = entry.getAccession().get(0);
    358351                               
    359             if (!bootstrapGenericProteinTags.containsKey(proteinRecommendedName)) {
    360                 bootstrapGenericProteinTags.put(proteinRecommendedName, genericProteinConcept);
     352            if (!bootstrapGenericProteinTags.containsKey(proteinAccession)) {
     353                bootstrapGenericProteinTags.put(proteinAccession, genericProteinConcept);
    361354            }
    362355           
    363356            // store generic gene tag if available and new
    364             genericGeneConcept = getGenericGeneTagFromEntry(entry);
     357            final Concept genericGeneConcept = getGenericGeneTagFromEntry(entry);
    365358            if (genericGeneConcept != null) {
    366                 final String genePrimaryName = conceptUtility.getPreferredLabel(genericGeneConcept, LANG_EN).getText();
    367                
    368                 if (!bootstrapGenericGeneTags.containsKey(genePrimaryName)) {
    369                     bootstrapGenericGeneTags.put(genePrimaryName, genericGeneConcept);
     359                final String geneAccession = entry.getAccession().get(0);
     360               
     361                if (!bootstrapGenericGeneTags.containsKey(geneAccession)) {
     362                    bootstrapGenericGeneTags.put(geneAccession, genericGeneConcept);
    370363                }               
    371364            }
     
    385378        return bootstrapTags.iterator();
    386379    }
    387    
     380       
    388381    /**
    389382     * Get all concepts.
  • trunk/code/conceptwiki/imports/imports-swissprot/src/test/java/nl/nbic/conceptwiki/imports/swissprot/SwissProtImporterUnitTest.java

    r780 r782  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    45
    56import java.io.IOException;
    67import java.util.List;
     8import java.util.Set;
    79
    810import javax.inject.Inject;
    911
    1012import nl.nbic.conceptwiki.common.api.Concept;
     13import nl.nbic.conceptwiki.common.api.Label;
    1114import nl.nbic.conceptwiki.common.api.Language;
     15import nl.nbic.conceptwiki.common.api.Notation;
    1216import nl.nbic.conceptwiki.common.api.Triple;
     17import nl.nbic.conceptwiki.common.api.Label.LabelType;
     18import nl.nbic.conceptwiki.common.impl.ConceptImpl;
     19import nl.nbic.conceptwiki.common.impl.LabelImpl;
    1320import nl.nbic.conceptwiki.common.impl.LanguageImpl;
     21import nl.nbic.conceptwiki.common.impl.NotationImpl;
    1422import nl.nbic.conceptwiki.common.impl.QueryScopeImpl;
    1523import nl.nbic.conceptwiki.common.util.ConceptUtility;
     
    2533import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    2634import org.springframework.transaction.annotation.Transactional;
     35
     36import com.google.common.collect.Sets;
    2737
    2838/**
     
    5060     */
    5161    private static final int SEARCH_LIMIT = 10;
     62    /**
     63     * Mapped SwissProt Accession.
     64     */
     65    private static final String MAPPED_SP_ACCESSION = "Q91ZQ5";
     66    /**
     67     * Mapped UMLS CID.
     68     */
     69    private static final String MAPPED_UMLS_CID = "C1571376";
    5270    /**
    5371     * Injected data source object.
     
    83101    @Before
    84102    public void setUp() throws IOException {
    85         System.out.println("SwissProtImporterUnitTest.setUp()");
     103        // Initialize UMLS.
     104        initUMLS();
     105       
    86106        // Initialize importer.
    87107        spImporter.init();
     
    95115        assertEquals(2, getNumberOfConceptsByNotation("P0C9E9"));
    96116        assertEquals(2, getNumberOfConceptsByNotation("O43149"));
    97         assertEquals(2, getNumberOfConceptsByNotation("Q91ZQ5"));
     117        assertEquals(2, getNumberOfConceptsByNotation(MAPPED_SP_ACCESSION));
    98118    }
    99119   
     
    129149    }
    130150   
     151    private void initUMLS() {
     152       
     153        final ConceptService conceptService = spImporter.getConceptService();
     154       
     155        //Create UMLS source.
     156        final Label umlsSourceLabel = new LabelImpl(LabelType.PREFERRED, "UMLS", LANG_EN);
     157        final Concept umlsSource = conceptService.createConcept(
     158                new ConceptImpl.Builder().labels(Sets.newHashSet(umlsSourceLabel)).build(),
     159                UMLS_BRANCH);
     160       
     161        //Create a UMLS concept that is mapped by one SP concept
     162        final Set<Notation> notations = Sets.newHashSet();
     163        notations.add(new NotationImpl(MAPPED_UMLS_CID).with(Sets.newHashSet(umlsSource)));       
     164        final Label umlsLabel = new LabelImpl(LabelType.PREFERRED, "Retinoid isomerohydrolase (Mus musculus) @UMLS", LANG_EN);
     165        final Concept umlsConcept = conceptService.createConcept(
     166                new ConceptImpl.Builder().labels(Sets.newHashSet(umlsLabel)).notations(notations).build(),
     167                UMLS_BRANCH);
     168    }
     169   
     170    @Test
     171    public void testImportWithMappedUMLSConcept() {
     172        final Set swissprotAccessions = Sets.newHashSet(MAPPED_SP_ACCESSION, "E9QNS6", "Q8VHP2");
     173        final ConceptService conceptService = spImporter.getConceptService();
     174        final List<Concept> resultConcepts = conceptService.getConceptsByNotation(MAPPED_UMLS_CID, QueryScopeImpl.LITE_SCOPE, SEARCH_LIMIT);
     175       
     176        assertEquals(1, resultConcepts.size());
     177       
     178        final Concept resultConcept = resultConcepts.get(0);
     179        for (Notation notation: resultConcept.getNotations()) {
     180            assertTrue(swissprotAccessions.contains(notation.getCode()));
     181        }
     182    }
     183   
    131184    /**
    132185     * return the number of triples with defined subject concept.
Note: See TracChangeset for help on using the changeset viewer.