Changeset 785


Ignore:
Timestamp:
Jun 14, 2012, 12:15:08 PM (4 years ago)
Author:
hailiang.mei@…
Message:

bug fixing for deleting concepts during SP update.

Location:
trunk/code/conceptwiki
Files:
8 edited

Legend:

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

    r756 r785  
    3636    @Valid
    3737    ConceptChangeset getDiff(@NotNull Concept sourceConcept, @NotNull Concept targetConcept);
     38   
     39    /**
     40     * Check if a changeset is empty.
     41     * @param changeset to check.
     42     * @return true if empty, otherwise false.
     43     */
     44    boolean changeSetIsEmpty(ConceptChangeset changeset);
    3845}
  • trunk/code/conceptwiki/common/common-util/src/main/java/nl/nbic/conceptwiki/common/util/impl/ConceptUtilityImpl.java

    r756 r785  
    5656        return changeset;
    5757    }
     58
     59    @Override
     60    public boolean changeSetIsEmpty(ConceptChangeset changeset) {
     61        int changes = 0;
     62       
     63        if (changeset.getAdd() != null) {
     64            changes += changeset.getAdd().getLabels().size();
     65            changes += changeset.getAdd().getNotations().size();
     66            changes += changeset.getAdd().getNotes().size();
     67            changes += changeset.getAdd().getTags().size();
     68            changes += changeset.getAdd().getUrls().size();
     69        }
     70       
     71        if (changeset.getRemove() != null) {
     72            changes += changeset.getRemove().getLabels().size();
     73            changes += changeset.getRemove().getNotations().size();
     74            changes += changeset.getRemove().getNotes().size();
     75            changes += changeset.getRemove().getTags().size();
     76            changes += changeset.getRemove().getUrls().size();
     77        }
     78               
     79        if (changes == 0) {
     80            return true;
     81        }
     82        return false;
     83    }
    5884}
  • trunk/code/conceptwiki/imports/imports-common/src/main/java/nl/nbic/conceptwiki/imports/common/AbstractConceptImporter.java

    r784 r785  
    137137                // calculate diff
    138138                final ConceptChangeset diff = conceptUtility.getDiff(target, resolveCrossDataSourceTags(concept));
    139 //               
    140 //                System.out.println("AbstractConceptImporter.processConcepts()");
    141 //               
    142 //                System.out.println("Added labels");
    143 //                for (Label label: diff.getAdd().getLabels()) {
    144 //                    System.out.println(label.getText());
    145 //                }
    146 //               
    147 //                System.out.println("Removed labels");
    148 //                for (Label label: diff.getRemove().getLabels()) {
    149 //                    System.out.println(label.getText());
    150 //                }
    151                                
    152                 conceptService.updateConcept(target.getUuid(), diff, importBranch);
     139               
     140                if (!conceptUtility.changeSetIsEmpty(diff)) {
     141                    conceptService.updateConcept(target.getUuid(), diff, importBranch);
     142                }       
    153143               
    154144            } else {
     
    272262        int counter = 0;
    273263        Transaction tx = startTransaction();
     264       
     265        comment = "Concept deleted at data source.";
    274266
    275267        while (deletedConcepts.hasNext()) {
    276             final Concept current = getConcept(deletedConcepts.next());
    277             conceptService.deleteConcept(current.getUuid(), comment, importBranch);
    278 
    279             tx = updateTransaction(tx, counter, CHUNK_SIZE);
     268            final Concept current = getConcept(resolveReferences(deletedConcepts.next()));
     269                       
     270            if (current != null) {
     271                conceptService.deleteConcept(current.getUuid(), comment, importBranch);
     272                tx = updateTransaction(tx, counter, CHUNK_SIZE);
     273            }
     274           
    280275            counter++;
    281276        }
  • trunk/code/conceptwiki/imports/imports-swissprot/src/main/java/nl/nbic/conceptwiki/imports/swissprot/SwissProtImporter.java

    r784 r785  
    154154       
    155155        if (mappedUMLSID != null) {
    156             // get the mapped UMLS concept in SwissProt branch.           
    157             final Concept umlsConcept = conceptService.getConceptsByNotation(mappedUMLSID, QueryScopeImpl.FULL_SCOPE, 1, UMLS_BRANCH).get(0);
    158             result = conceptService.getConcept(umlsConcept.getUuid(), SWISSPROT_BRANCH);
    159            
    160             if (result == null) {
    161                 logger.error("Mapped UMLS concept " + mappedUMLSID + " does not exist in ConceptWiki.");
    162             }
     156            // get the mapped UMLS concept in SwissProt branch.           
     157           
     158            final List<Concept> umlsConcepts = conceptService.getConceptsByNotation(mappedUMLSID, QueryScopeImpl.FULL_SCOPE, 1, UMLS_BRANCH);
     159           
     160            if (umlsConcepts.size() == 1) {
     161                result = conceptService.getConcept(umlsConcepts.get(0).getUuid(), SWISSPROT_BRANCH);
     162            } else {
     163                logger.error("Mapped UMLS concept " + mappedUMLSID + " does not exist in ConceptWiki or has more than 1 hits.");
     164            }           
     165           
    163166        } else {
    164167            // get the resolved SwissProt concept.
     
    190193    protected Concept getConcept(final Concept concept) {
    191194       
    192         Concept resultConcept = null;
    193                
    194195        if (isGeneOrGenome(concept)) {
    195             resultConcept = getConceptWithATag(concept, geneSemanticType);
    196         }
    197        
    198         if (resultConcept != null) {
    199             return resultConcept;
     196            return getConceptWithATag(concept, geneSemanticType);
    200197        }
    201198       
    202199        if (isProteinOrAminoAcid(concept)) {
    203             resultConcept = getConceptWithATag(concept, proteinSemanticType);
    204         }
    205                
    206         if (resultConcept != null) {
    207             return resultConcept;
     200            return getConceptWithATag(concept, proteinSemanticType);
    208201        }
    209202       
     
    230223        for (Notation notation : concept.getNotations()) {
    231224            if (notation.getSources().contains(swissProtSource)) {
     225               
    232226                final List<Concept> results =
    233227                        conceptService.getConceptsByNotation(notation.getCode(), QueryScopeImpl.FULL_SCOPE, SEARCH_LIMIT, SWISSPROT_BRANCH);
  • trunk/code/conceptwiki/imports/imports-swissprot/src/main/java/nl/nbic/conceptwiki/imports/swissprot/SwissProtReader.java

    r782 r785  
    266266            notations.add(new NotationImpl(line.trim()).with(Sets.newHashSet(swissProtSource)));
    267267       
    268             final Concept deletedConcept = new ConceptImpl.Builder().notations(notations).build();
     268            final Concept deletedProteinConcept =
     269                    new ConceptImpl.Builder().notations(notations).tags(Sets.newHashSet(proteinSemanticType)).build();           
     270            deletedConcepts.add(deletedProteinConcept);
    269271           
    270             deletedConcepts.add(deletedConcept);
     272            final Concept deletedGeneConcept =
     273                    new ConceptImpl.Builder().notations(notations).tags(Sets.newHashSet(geneSemanticType)).build();           
     274            deletedConcepts.add(deletedGeneConcept);
     275           
    271276            if (counter % CHUNK_SIZE == 0) {
    272277                logger.info(Integer.toString(counter));
  • trunk/code/conceptwiki/imports/imports-swissprot/src/test/java/nl/nbic/conceptwiki/imports/swissprot/SwissProtImporterUnitTest.java

    r784 r785  
    2424import nl.nbic.conceptwiki.common.util.ConceptUtility;
    2525import nl.nbic.conceptwiki.service.api.ConceptService;
     26import nl.nbic.conceptwiki.service.api.TagService;
    2627import nl.nbic.conceptwiki.service.api.TripleService;
    2728import nl.nbic.conceptwiki.storage.api.ConceptStorageService;
     
    6667    private static final String MAPPED_SP_ACCESSION = "Q91ZQ5";
    6768    /**
    68      * Mapped UMLS Generic CID for "retinoid isomerohydrolase".
     69     * To be deleted SwissProt Accession.
     70     */
     71    private static final String DELETED_SP_ACCESSION_A = "P35228";
     72    /**
     73     * To be deleted SwissProt Accession.
     74     */
     75    private static final String DELETED_SP_ACCESSION_B = "P16860";
     76    /**
     77     * Mapped UMLS generic CID for "retinoid isomerohydrolase".
    6978     */
    7079    private static final String MAPPED_UMLS_GENERIC_CID = "C0073113";
    7180    /**
    72      * Mapped UMLS Generic Text for "retinoid isomerohydrolase".
     81     * Mapped UMLS generic text for "retinoid isomerohydrolase".
    7382     */
    7483    private static final String MAPPED_UMLS_GENERIC_TEXT = "Retinoid isomerohydrolase @UMLS";
    7584    /**
     85     * Protein semantic type label text.
     86     */
     87    private static final String PROTEIN_SEMANTIC_TYPE_TEXT = "Amino Acid, Peptide, or Protein";
     88    /**
    7689     * Mapped UMLS CID.
    7790     */
     
    97110    @Inject
    98111    private TripleService tripleService;
     112    /**
     113     * ConceptWiki service used to manipulate the tags.
     114     */
     115    @Inject
     116    private TagService tagService;
    99117    /**
    100118     * SwissProt reader.
     
    113131        initUMLS();
    114132       
     133        // Initialize SwissProt.
     134        initSP();
     135       
    115136        // Initialize importer.
    116137        spImporter.init();
     
    168189                UMLS_BRANCH);
    169190       
    170         //Create a UMLS concept that is mapped by one SP concept
     191        //Create a mapped UMLS sepecific protein
    171192        Set<Notation> notations = Sets.newHashSet();
    172193        notations.add(new NotationImpl(MAPPED_UMLS_SPECIFIC_CID).with(Sets.newHashSet(umlsSource)));       
     
    176197                UMLS_BRANCH);
    177198       
     199        //Create a mapped UMLS generic protein
    178200        notations = Sets.newHashSet();
    179201        notations.add(new NotationImpl(MAPPED_UMLS_GENERIC_CID).with(Sets.newHashSet(umlsSource)));       
     
    182204                new ConceptImpl.Builder().labels(Sets.newHashSet(umlsLabel)).notations(notations).build(),
    183205                UMLS_BRANCH);
    184     }
    185    
    186 //    private void initUMLS() {
    187 //       
    188 //        final ConceptService conceptService = spImporter.getConceptService();
    189 //       
    190 //        //Create UMLS source.
    191 //        final Label umlsSourceLabel = new LabelImpl(LabelType.PREFERRED, "UMLS", LANG_EN);
    192 //        final Concept umlsSource = conceptService.createConcept(
    193 //                new ConceptImpl.Builder().labels(Sets.newHashSet(umlsSourceLabel)).build(),
    194 //                UMLS_BRANCH);
    195 //       
    196 //        //Create a UMLS concept that is mapped by one SP concept
    197 //        Set<Notation> notations = Sets.newHashSet();
    198 //        notations.add(new NotationImpl(MAPPED_UMLS_SPECIFIC_CID).with(Sets.newHashSet(umlsSource)));       
    199 //        Label umlsLabel = new LabelImpl(LabelType.PREFERRED, "Retinoid isomerohydrolase (Mus musculus) @UMLS", LANG_EN);
    200 //        Concept umlsConcept = conceptService.createConcept(
    201 //                new ConceptImpl.Builder().labels(Sets.newHashSet(umlsLabel)).notations(notations).build(),
    202 //                UMLS_BRANCH);
    203 //       
    204 //        final Set<Label> labelsA = Sets.newHashSet(
    205 //                (Label) new LabelImpl(LabelType.PREFERRED, "Unique Label for branch A", LANG_EN));
    206 //        final Set<Notation> notationsA = Sets.newHashSet((Notation) new NotationImpl("Q12345"));
    207 //        final ConceptChangeset changeset = new ConceptChangesetImpl().withAdd(
    208 //                new ConceptChangesetImpl.ActionImpl().withLabels(labelsA).withNotations(notationsA));
    209 //        conceptService.updateConcept(umlsConcept.getUuid(), changeset, SWISSPROT_BRANCH);
    210 //       
    211 //        List<Concept> results = conceptService.getConceptsByNotation("Q12345", QueryScopeImpl.FULL_SCOPE, 10, SWISSPROT_BRANCH);
    212 //       
    213 //        System.out.println("SwissProtImporterUnitTest.initUMLS()");
    214 //       
    215 //    }
    216    
     206               
     207    }
     208   
     209    private void initSP() {
     210       
     211        final ConceptService conceptService = spImporter.getConceptService();
     212       
     213        //Create SP source.
     214        final Label swissProtSourceLabel = new LabelImpl(LabelType.PREFERRED, "SwissProt", LANG_EN);
     215        final Concept swissProtSource = conceptService.createConcept(
     216                new ConceptImpl.Builder().labels(Sets.newHashSet(swissProtSourceLabel)).build(),
     217                SWISSPROT_BRANCH);
     218       
     219        final Label proteinSemanticTypeLabel = new LabelImpl(LabelType.PREFERRED, PROTEIN_SEMANTIC_TYPE_TEXT, LANG_EN);
     220        final Concept proteinSemanticType = conceptService.createConcept(
     221                new ConceptImpl.Builder().labels(Sets.newHashSet(proteinSemanticTypeLabel)).build(),
     222                SWISSPROT_BRANCH);               
     223        tagService.createTag(proteinSemanticType);
     224       
     225        final Set<Concept> tags = Sets.newHashSet(proteinSemanticType);
     226       
     227        //Create a to be deleted SP protein
     228        Set<Notation> notations = Sets.newHashSet();
     229        notations.add(new NotationImpl(DELETED_SP_ACCESSION_A).with(Sets.newHashSet(swissProtSource)));       
     230        Label spLabel = new LabelImpl(LabelType.PREFERRED, "Nitric oxide synthase, inducible @SP", LANG_EN);
     231        conceptService.createConcept(
     232                new ConceptImpl.Builder().labels(Sets.newHashSet(spLabel)).notations(notations).tags(tags).build(),
     233                SWISSPROT_BRANCH);
     234       
     235        //Create a to be deleted SP protein
     236        notations = Sets.newHashSet();
     237        notations.add(new NotationImpl(DELETED_SP_ACCESSION_B).with(Sets.newHashSet(swissProtSource)));       
     238        spLabel = new LabelImpl(LabelType.PREFERRED, "Natriuretic peptides B @SP", LANG_EN);
     239        conceptService.createConcept(
     240                new ConceptImpl.Builder().labels(Sets.newHashSet(spLabel)).notations(notations).tags(tags).build(),
     241                SWISSPROT_BRANCH);
     242    }
     243       
    217244    @Test
    218245    public void testImportWithMappedUMLSConcept() {
    219246        final HashSet<String> allNotations = Sets.newHashSet(MAPPED_UMLS_SPECIFIC_CID, MAPPED_SP_ACCESSION, "E9QNS6", "Q8VHP2");
    220         final HashSet<String> allTagLabelTexts = Sets.newHashSet(MAPPED_UMLS_GENERIC_TEXT, "Amino Acid, Peptide, or Protein");
     247        final HashSet<String> allTagLabelTexts = Sets.newHashSet(MAPPED_UMLS_GENERIC_TEXT, PROTEIN_SEMANTIC_TYPE_TEXT);
    221248        final ConceptService conceptService = spImporter.getConceptService();
    222249        final List<Concept> resultConcepts = conceptService.getConceptsByNotation(MAPPED_UMLS_SPECIFIC_CID, QueryScopeImpl.FULL_SCOPE, SEARCH_LIMIT);
     
    239266    }
    240267   
     268    @Test
     269    public void testDeletedConcept() {
     270        final ConceptService conceptService = spImporter.getConceptService();
     271        List<Concept> resultConcepts = conceptService.getConceptsByNotation(
     272                DELETED_SP_ACCESSION_A, QueryScopeImpl.LITE_SCOPE, SEARCH_LIMIT, SWISSPROT_BRANCH);       
     273        assertEquals(0, resultConcepts.size());
     274       
     275        resultConcepts = conceptService.getConceptsByNotation(
     276                DELETED_SP_ACCESSION_B, QueryScopeImpl.LITE_SCOPE, SEARCH_LIMIT, SWISSPROT_BRANCH);       
     277        assertEquals(0, resultConcepts.size());
     278    }
     279   
    241280    /**
    242281     * return the number of triples with defined subject concept.
  • trunk/code/conceptwiki/imports/imports-swissprot/src/test/resources/SP_Deleted_Entries_2012_05_16_small_2.txt

    r778 r785  
     1P16860
     2P35228
  • trunk/code/conceptwiki/storage/storage-neo4j/src/main/java/nl/nbic/conceptwiki/storage/neo4j/impl/ConceptStorageServiceImpl.java

    r783 r785  
    99
    1010import javax.inject.Inject;
    11 
    12 import com.google.common.base.Predicate;
    13 import com.google.common.collect.ImmutableList;
    14 import com.google.common.collect.ImmutableMap;
    15 import com.google.common.collect.ImmutableSet;
    16 import com.google.common.collect.Iterables;
    17 import com.google.common.collect.Lists;
    18 import com.google.common.collect.Sets;
    1911
    2012import nl.nbic.conceptwiki.common.api.Concept;
     
    6355import org.springframework.transaction.annotation.Transactional;
    6456
     57import com.google.common.base.Predicate;
     58import com.google.common.collect.ImmutableList;
     59import com.google.common.collect.ImmutableMap;
     60import com.google.common.collect.ImmutableSet;
     61import com.google.common.collect.Iterables;
     62import com.google.common.collect.Lists;
     63import com.google.common.collect.Sets;
     64
    6565/**
    6666 * Neo4j implementation of the {@link ConceptStorageService} interface. Implements the {@link Neo4jConceptStorageService} interface
     
    311311        for (Node node : nodes) {
    312312            final Relationship relationship = node.getSingleRelationship(RelationType.HAS_NOTATION, Direction.INCOMING);
     313           
     314            if (relationship == null) {
     315                continue;
     316            }
     317                       
    313318            if (branchId == 0 || relationship.getProperty(NodePropertyKeys.KEY_BRANCH).equals(branchId)) {
    314319                // TODO assert assumption that all nodes that have an outgoing relationship to a notation are concepts
Note: See TracChangeset for help on using the changeset viewer.