Changeset 22646


Ignore:
Timestamp:
02/09/10 10:53:54 (17 months ago)
Author:
julie
Message:

eclipse warnings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bio/sources/uniprot/main/src/org/intermine/bio/dataconversion/UniprotConverter.java

    r22539 r22646  
    123123 
    124124    // process the sprot file, then the trembl file 
    125     private void processFiles(File[] files) 
    126         throws SAXException { 
     125    private void processFiles(File[] files) { 
    127126        for (int i = 0; i <= 1; i++) { 
    128127            File file = files[i]; 
     
    319318                String domain = entry.getAttribute(); 
    320319                if (domain.startsWith("IPR")) { 
    321                     try { 
    322                         entry.addDomainRefId(getInterpro(domain, getAttrValue(attrs, "value"))); 
    323                     } catch (ObjectStoreException e) { 
    324                         throw new SAXException(e); 
    325                     } 
     320                    entry.addDomainRefId(getInterpro(domain, getAttrValue(attrs, "value"))); 
    326321                } 
    327322            } else if (qName.equals("dbReference") && stack.peek().equals("citation") 
     
    472467 
    473468 
    474         private Set<UniprotEntry> processEntry(UniprotEntry entry) 
     469        private Set<UniprotEntry> processEntry(UniprotEntry uniprotEntry) 
    475470            throws SAXException, ObjectStoreException { 
    476471            entryCount++; 
     
    480475            Set<UniprotEntry> isoforms = new HashSet<UniprotEntry>(); 
    481476            // have we already seen a protein for this organism with the same sequence? 
    482             if (!entry.isIsoform() && seenSequence(entry.getTaxonId(), entry.getMd5checksum())) { 
     477            if (!uniprotEntry.isIsoform() && seenSequence(uniprotEntry.getTaxonId(), 
     478                    uniprotEntry.getMd5checksum())) { 
    483479                // if we have seen this sequence before for this organism just add the 
    484480                // primaryAccession of this protein as a synonym for the one already stored. 
    485481                Map<String, String> orgSequences = sequences.get(taxonId); 
    486                 if (orgSequences != null && orgSequences.containsKey(entry.getMd5checksum())) { 
    487                     Item synonym = createSynonym(orgSequences.get(entry.getMd5checksum()), 
    488                             entry.getPrimaryAccession(), false); 
     482                if (orgSequences != null 
     483                        && orgSequences.containsKey(uniprotEntry.getMd5checksum())) { 
     484                    Item synonym = createSynonym(orgSequences.get(uniprotEntry.getMd5checksum()), 
     485                            uniprotEntry.getPrimaryAccession(), false); 
    489486                    synonymsAndXrefs.add(synonym); 
    490487                } 
     
    493490 
    494491            // TODO there are uniparc entries so check for swissprot-trembl datasets 
    495             if (entry.hasDatasetRefId() && entry.hasPrimaryAccession()) { 
    496  
    497                 setDataSet(entry.getDatasetRefId()); 
    498  
    499                 for (String isoformAccession: entry.getIsoforms()) { 
    500                     isoforms.add(entry.createIsoformEntry(isoformAccession)); 
     492            if (uniprotEntry.hasDatasetRefId() && uniprotEntry.hasPrimaryAccession()) { 
     493 
     494                setDataSet(uniprotEntry.getDatasetRefId()); 
     495 
     496                for (String isoformAccession: uniprotEntry.getIsoforms()) { 
     497                    isoforms.add(uniprotEntry.createIsoformEntry(isoformAccession)); 
    501498                } 
    502499 
     
    504501 
    505502                /* primaryAccession, primaryIdentifier, name, etc */ 
    506                 processIdentifiers(protein, entry); 
    507  
    508                 String isCanonical = (entry.isIsoform() ? "false" : "true"); 
     503                processIdentifiers(protein, uniprotEntry); 
     504 
     505                String isCanonical = (uniprotEntry.isIsoform() ? "false" : "true"); 
    509506                protein.setAttribute("isUniprotCanonical", isCanonical); 
    510507 
     
    513510 
    514511                /* sequence */ 
    515                 if (!entry.isIsoform()) { 
    516                     processSequence(protein, entry); 
     512                if (!uniprotEntry.isIsoform()) { 
     513                    processSequence(protein, uniprotEntry); 
    517514                } 
    518515 
    519516                /* interpro */ 
    520                 if (createInterpro && !entry.getDomains().isEmpty()) { 
    521                     protein.setCollection("proteinDomains", entry.getDomains()); 
    522                 } 
    523  
    524                 protein.setReference("organism", getOrganism(entry.getTaxonId())); 
     517                if (createInterpro && !uniprotEntry.getDomains().isEmpty()) { 
     518                    protein.setCollection("proteinDomains", uniprotEntry.getDomains()); 
     519                } 
     520 
     521                protein.setReference("organism", getOrganism(uniprotEntry.getTaxonId())); 
    525522 
    526523                /* publications */ 
    527                 if (!entry.getPubs().isEmpty()) { 
    528                     protein.setCollection("publications", entry.getPubs()); 
     524                if (!uniprotEntry.getPubs().isEmpty()) { 
     525                    protein.setCollection("publications", uniprotEntry.getPubs()); 
    529526                } 
    530527 
    531528                /* comments */ 
    532                 if (!entry.getComments().isEmpty()) { 
    533                     protein.setCollection("comments", entry.getComments()); 
     529                if (!uniprotEntry.getComments().isEmpty()) { 
     530                    protein.setCollection("comments", uniprotEntry.getComments()); 
    534531                } 
    535532 
    536533                /* keywords */ 
    537                 if (!entry.getKeywords().isEmpty()) { 
    538                     protein.setCollection("keywords", entry.getKeywords()); 
     534                if (!uniprotEntry.getKeywords().isEmpty()) { 
     535                    protein.setCollection("keywords", uniprotEntry.getKeywords()); 
    539536                } 
    540537 
    541538                /* features */ 
    542                 processFeatures(protein, entry); 
     539                processFeatures(protein, uniprotEntry); 
    543540 
    544541                /* components */ 
    545                 if (!entry.getComponents().isEmpty()) { 
    546                     processComponents(protein, entry); 
     542                if (!uniprotEntry.getComponents().isEmpty()) { 
     543                    processComponents(protein, uniprotEntry); 
    547544                } 
    548545 
    549546                // record that we have seen this sequence for this organism 
    550                 addSeenSequence(entry.getTaxonId(), entry.getMd5checksum(), 
     547                addSeenSequence(uniprotEntry.getTaxonId(), uniprotEntry.getMd5checksum(), 
    551548                        protein.getIdentifier()); 
    552549 
    553550                try { 
    554551                    /* dbrefs (go terms, refseq) */ 
    555                     processDbrefs(protein, entry); 
     552                    processDbrefs(protein, uniprotEntry); 
    556553 
    557554                    /* genes */ 
    558                     processGene(protein, entry); 
     555                    processGene(protein, uniprotEntry); 
    559556 
    560557                    store(protein); 
    561558 
    562559                    // create synonyms for accessions and store xrefs and synonyms we've collected 
    563                     processSynonyms(protein.getIdentifier(), entry); 
     560                    processSynonyms(protein.getIdentifier(), uniprotEntry); 
    564561 
    565562                } catch (ObjectStoreException e) { 
     
    571568        } 
    572569 
    573  
    574         private void processSequence(Item protein, UniprotEntry entry) { 
     570        private void processSequence(Item protein, UniprotEntry uniprotEntry) { 
    575571            Item item = createItem("Sequence"); 
    576             item.setAttribute("residues", entry.getSequence()); 
    577             item.setAttribute("length", entry.getLength()); 
     572            item.setAttribute("residues", uniprotEntry.getSequence()); 
     573            item.setAttribute("length", uniprotEntry.getLength()); 
    578574            try { 
    579575                store(item); 
     
    581577                throw new RuntimeException(e); 
    582578            } 
    583             protein.setAttribute("length", entry.getLength()); 
     579            protein.setAttribute("length", uniprotEntry.getLength()); 
    584580            protein.setReference("sequence", item.getIdentifier()); 
    585             protein.setAttribute("molecularWeight", entry.getMolecularWeight()); 
    586             protein.setAttribute("md5checksum", entry.getMd5checksum()); 
    587         } 
    588  
    589         private void processIdentifiers(Item protein, UniprotEntry entry) { 
    590             protein.setAttribute("name", entry.getName()); 
    591             protein.setAttribute("isFragment", entry.isFragment()); 
    592             protein.setAttribute("uniprotAccession", entry.getUniprotAccession()); 
    593             String primaryAccession = entry.getPrimaryAccession(); 
     581            protein.setAttribute("molecularWeight", uniprotEntry.getMolecularWeight()); 
     582            protein.setAttribute("md5checksum", uniprotEntry.getMd5checksum()); 
     583        } 
     584 
     585        private void processIdentifiers(Item protein, UniprotEntry uniprotEntry) { 
     586            protein.setAttribute("name", uniprotEntry.getName()); 
     587            protein.setAttribute("isFragment", uniprotEntry.isFragment()); 
     588            protein.setAttribute("uniprotAccession", uniprotEntry.getUniprotAccession()); 
     589            String primaryAccession = uniprotEntry.getPrimaryAccession(); 
    594590            protein.setAttribute("primaryAccession", primaryAccession); 
    595591 
    596             String primaryIdentifier = entry.getPrimaryIdentifier(); 
     592            String primaryIdentifier = uniprotEntry.getPrimaryIdentifier(); 
    597593            protein.setAttribute("uniprotName", primaryIdentifier); 
    598594 
    599595            // primaryIdentifier must be unique, so append isoform suffix, eg -1 
    600             if (entry.isIsoform()) { 
     596            if (uniprotEntry.isIsoform()) { 
    601597                primaryIdentifier = getIsoformIdentifier(primaryAccession, primaryIdentifier); 
    602598            } 
     
    613609        } 
    614610 
    615         private void processComponents(Item protein, UniprotEntry entry) 
     611        private void processComponents(Item protein, UniprotEntry uniprotEntry) 
    616612            throws SAXException { 
    617             for (String componentName : entry.getComponents()) { 
     613            for (String componentName : uniprotEntry.getComponents()) { 
    618614                Item component = createItem("Component"); 
    619615                component.setAttribute("name", componentName); 
     
    627623        } 
    628624 
    629         private void processFeatures(Item protein, UniprotEntry entry) 
     625        private void processFeatures(Item protein, UniprotEntry uniprotEntry) 
    630626            throws SAXException { 
    631             for (Item feature : entry.getFeatures()) { 
     627            for (Item feature : uniprotEntry.getFeatures()) { 
    632628                feature.setReference("protein", protein); 
    633629                try { 
     
    639635        } 
    640636 
    641         private void processSynonyms(String proteinRefId, UniprotEntry entry) 
     637        private void processSynonyms(String proteinRefId, UniprotEntry uniprotEntry) 
    642638            throws SAXException, ObjectStoreException { 
    643639 
    644640            // accessions 
    645             for (String accession : entry.getAccessions()) { 
     641            for (String accession : uniprotEntry.getAccessions()) { 
    646642                createSynonym(proteinRefId, accession, true); 
    647643            } 
    648644 
    649645            // primaryIdentifier if isoform 
    650             if (entry.isIsoform()) { 
     646            if (uniprotEntry.isIsoform()) { 
    651647                String isoformIdentifier = 
    652                     getIsoformIdentifier(entry.getPrimaryAccession(), entry.getPrimaryIdentifier()); 
     648                    getIsoformIdentifier(uniprotEntry.getPrimaryAccession(), 
     649                            uniprotEntry.getPrimaryIdentifier()); 
    653650                createSynonym(proteinRefId, isoformIdentifier, true); 
    654651            } 
    655652 
    656653            // name <recommendedName> or <alternateName> 
    657             for (String name : entry.getProteinNames()) { 
     654            for (String name : uniprotEntry.getProteinNames()) { 
    658655                createSynonym(proteinRefId, name, true); 
    659656            } 
    660657 
    661658            // isoforms with extra identifiers 
    662             List<String> isoformSynonyms = entry.getIsoformSynonyms(); 
     659            List<String> isoformSynonyms = uniprotEntry.getIsoformSynonyms(); 
    663660            if (!isoformSynonyms.isEmpty()) { 
    664661                for (String identifier : isoformSynonyms) { 
     
    676673        } 
    677674 
    678         private void processDbrefs(Item protein, UniprotEntry entry) 
     675        private void processDbrefs(Item protein, UniprotEntry uniprotEntry) 
    679676            throws SAXException, ObjectStoreException { 
    680             Map<String, List<String>> dbrefs = entry.getDbrefs(); 
     677            Map<String, List<String>> dbrefs = uniprotEntry.getDbrefs(); 
    681678 
    682679            for (Map.Entry<String, List<String>> dbref : dbrefs.entrySet()) { 
     
    692689                    setCrossReference(protein.getIdentifier(), identifier, key, false); 
    693690                    if (creatego && key.equals("GO")) { 
    694                         entry.addGOTerm(getGoTerm(identifier)); 
     691                        uniprotEntry.addGOTerm(getGoTerm(identifier)); 
    695692                    } 
    696693                } 
     
    710707        } 
    711708 
    712         private void processGoAnnotation(UniprotEntry entry, Item gene) 
     709        private void processGoAnnotation(UniprotEntry uniprotEntry, Item gene) 
    713710            throws SAXException { 
    714             for (String goTermRefId : entry.getGOTerms()) { 
     711            for (String goTermRefId : uniprotEntry.getGOTerms()) { 
    715712                Item goAnnotation = createItem("GOAnnotation"); 
    716713                goAnnotation.setReference("subject", gene); 
     
    727724        // gets the unique identifier and list of identifiers to set 
    728725        // loops through each gene entry, assigns refId to protein 
    729         private void processGene(Item protein, UniprotEntry entry) 
     726        private void processGene(Item protein, UniprotEntry uniprotEntry) 
    730727            throws SAXException, ObjectStoreException { 
    731             String taxonId = entry.getTaxonId(); 
     728            String taxId = uniprotEntry.getTaxonId(); 
    732729 
    733730            // which gene.identifier field has to be unique 
    734             String uniqueIdentifierField = CONFIG.getUniqueIdentifier(taxonId); 
     731            String uniqueIdentifierField = CONFIG.getUniqueIdentifier(taxId); 
    735732            if (uniqueIdentifierField == null) { 
    736733                uniqueIdentifierField = CONFIG.getUniqueIdentifier("default"); 
     
    738735 
    739736            // for this organism, set the following gene fields 
    740             Set<String> geneFields = CONFIG.getGeneIdentifierFields(taxonId); 
     737            Set<String> geneFields = CONFIG.getGeneIdentifierFields(taxId); 
    741738            if (geneFields == null) { 
    742739                geneFields = CONFIG.getGeneIdentifierFields("default"); 
     
    744741 
    745742            // just one gene, don't have to worry about gene designations and dbrefs 
    746             if (!entry.hasMultipleGenes()) { 
    747                 String geneRefId = createGene(entry, taxonId, geneFields, uniqueIdentifierField); 
     743            if (!uniprotEntry.hasMultipleGenes()) { 
     744                String geneRefId = createGene(uniprotEntry, taxId, geneFields, 
     745                        uniqueIdentifierField); 
    748746                if (geneRefId != null) { 
    749747                    protein.addToCollection("genes", geneRefId); 
     
    754752            // loop through each gene entry to be processed 
    755753            // cloning the gene removes dbrefs without gene designations 
    756             List<UniprotEntry> clonedEntries = entry.cloneGenes(); 
     754            List<UniprotEntry> clonedEntries = uniprotEntry.cloneGenes(); 
    757755            Iterator<UniprotEntry> iter = clonedEntries.iterator(); 
    758756            while (iter.hasNext()) { 
    759757                // create a dummy entry and add identifiers for specific gene 
    760                 String geneRefId = createGene(iter.next(), taxonId, geneFields, 
     758                String geneRefId = createGene(iter.next(), taxId, geneFields, 
    761759                        uniqueIdentifierField); 
    762760                if (StringUtils.isNotEmpty(geneRefId)) { 
     
    769767        // sets the identifier fields specified in the config file 
    770768        // creates synonym 
    771         private String createGene(UniprotEntry entry, String taxonId, Set<String> geneFields, 
     769        private String createGene(UniprotEntry uniprotEntry, String taxId, Set<String> geneFields, 
    772770                String uniqueIdentifierFieldType) 
    773771            throws SAXException, ObjectStoreException { 
     
    775773            List<String> geneSynonyms = new ArrayList<String>(); 
    776774 
    777             String uniqueIdentifierValue = getGeneIdentifier(entry, taxonId, 
     775            String uniqueIdentifierValue = getGeneIdentifier(uniprotEntry, taxId, 
    778776                    uniqueIdentifierFieldType, geneSynonyms, true); 
    779777            if (uniqueIdentifierValue == null) { 
     
    792790                        continue; 
    793791                    } 
    794                     String identifier = getGeneIdentifier(entry, taxonId, geneField, geneSynonyms, 
    795                             false); 
     792                    String identifier = getGeneIdentifier(uniprotEntry, taxId, geneField, 
     793                            geneSynonyms, false); 
    796794 
    797795                    if (identifier == null) { 
     
    804802                     * identifier will always be a duplicate in this case. 
    805803                     */ 
    806                     if (!entry.isIsoform() && geneIdentifiers.contains(identifier)) { 
     804                    if (!uniprotEntry.isIsoform() && geneIdentifiers.contains(identifier)) { 
    807805                        // TODO this should create a synonym 
    808806                        LOG.error("not assigning duplicate identifier:  " + identifier); 
     
    817815 
    818816                if (creatego) { 
    819                     processGoAnnotation(entry, gene); 
     817                    processGoAnnotation(uniprotEntry, gene); 
    820818                } 
    821819 
    822820                // store gene 
    823821                try { 
    824                     gene.setReference("organism", getOrganism(taxonId)); 
     822                    gene.setReference("organism", getOrganism(taxId)); 
    825823                    store(gene); 
    826824                } catch (ObjectStoreException e) { 
     
    840838        // gets the identifier for a gene from the dbref/names collected from the XML 
    841839        // which identifier is chosen depends on the configuration in the uniprot config file 
    842         private String getGeneIdentifier(UniprotEntry entry, String taxonId, String identifierType, 
    843                                         List<String> geneSynonyms, boolean isUniqueIdentifier) { 
     840        private String getGeneIdentifier(UniprotEntry uniprotEntry, String taxId, 
     841                String identifierType, List<String> geneSynonyms, boolean isUniqueIdentifier) { 
    844842 
    845843            String identifierValue = null; 
    846844            // how to get the identifier, eg. dbref OR name 
    847             String method = CONFIG.getIdentifierMethod(taxonId, identifierType); 
     845            String method = CONFIG.getIdentifierMethod(taxId, identifierType); 
    848846            // what value to use with method, eg. "FlyBase" or "ORF" 
    849             String value = CONFIG.getIdentifierValue(taxonId, identifierType); 
     847            String value = CONFIG.getIdentifierValue(taxId, identifierType); 
    850848 
    851849            if (method == null || value == null) { 
     
    855853                if (method == null || value == null) { 
    856854                    throw new RuntimeException("error processing line in config file for organism " 
    857                                                + taxonId); 
     855                                               + taxId); 
    858856                } 
    859857            } 
    860858 
    861859            if (method.equals("name")) { 
    862                 if (entry.getGeneNames() == null || entry.getGeneNames().isEmpty()) { 
    863                     LOG.error("No gene names for " + taxonId + ". protein accession:" 
    864                               + entry.getPrimaryAccession()); 
     860                if (uniprotEntry.getGeneNames() == null || uniprotEntry.getGeneNames().isEmpty()) { 
     861                    LOG.error("No gene names for " + taxId + ". protein accession:" 
     862                              + uniprotEntry.getPrimaryAccession()); 
    865863                    return null; 
    866864                } 
    867                 identifierValue = entry.getGeneNames().get(value); 
     865                identifierValue = uniprotEntry.getGeneNames().get(value); 
    868866            } else if (method.equals("dbref")) { 
    869867                if (value.equals("Ensembl")) { 
    870868                    // See #2122 
    871                     identifierValue = entry.getGeneDesignation("Ensembl"); 
     869                    identifierValue = uniprotEntry.getGeneDesignation("Ensembl"); 
    872870                } else { 
    873                     Map<String, List<String>> dbrefs = entry.getDbrefs(); 
     871                    Map<String, List<String>> dbrefs = uniprotEntry.getDbrefs(); 
    874872                    String msg = "no " + value + " identifier found for gene attached to protein: " 
    875                                     + entry.getPrimaryAccession(); 
     873                                    + uniprotEntry.getPrimaryAccession(); 
    876874                    if (dbrefs == null || dbrefs.isEmpty()) { 
    877875                        LOG.error(msg); 
     
    884882                    } 
    885883                    // TODO handle multiple identifiers somehow 
    886                     identifierValue = entry.getDbrefs().get(value).get(0); 
     884                    identifierValue = uniprotEntry.getDbrefs().get(value).get(0); 
    887885                } 
    888886            } else { 
    889                 LOG.error("error processing line in config file for organism " + taxonId); 
     887                LOG.error("error processing line in config file for organism " + taxId); 
    890888                return null; 
    891889            } 
    892890            geneSynonyms.add(identifierValue); 
    893             if (isUniqueIdentifier && taxonId.equals("7227")) { 
    894                 identifierValue = resolveGene(taxonId, identifierValue); 
     891            if (isUniqueIdentifier && taxId.equals("7227")) { 
     892                identifierValue = resolveGene(taxId, identifierValue); 
    895893 
    896894                // try again! 
    897                 if (identifierValue == null && entry.getGeneNames() != null 
    898                                 && !entry.getGeneNames().isEmpty()) { 
    899                     Iterator<String> iter = entry.getGeneNames().values().iterator(); 
     895                if (identifierValue == null && uniprotEntry.getGeneNames() != null 
     896                                && !uniprotEntry.getGeneNames().isEmpty()) { 
     897                    Iterator<String> iter = uniprotEntry.getGeneNames().values().iterator(); 
    900898                    while (iter.hasNext() && identifierValue == null) { 
    901                         identifierValue = resolveGene(taxonId, iter.next()); 
     899                        identifierValue = resolveGene(taxId, iter.next()); 
    902900                    } 
    903901                } 
     
    906904        } 
    907905 
    908         private String resolveGene(String taxonId, String identifier) { 
     906        private String resolveGene(String taxId, String identifier) { 
    909907            flyResolver = resolverFactory.getIdResolver(false); 
    910908            if (flyResolver == null) { 
     
    912910                return identifier; 
    913911            } 
    914             int resCount = flyResolver.countResolutions(taxonId, identifier); 
     912            int resCount = flyResolver.countResolutions(taxId, identifier); 
    915913            if (resCount != 1) { 
    916914                LOG.info("RESOLVER: failed to resolve gene to one identifier, ignoring gene: " 
    917915                         + identifier + " count: " + resCount + " FBgn: " 
    918                          + flyResolver.resolveId(taxonId, identifier)); 
     916                         + flyResolver.resolveId(taxId, identifier)); 
    919917                return null; 
    920918            } 
    921             return flyResolver.resolveId(taxonId, identifier).iterator().next(); 
    922         } 
    923     } 
    924  
    925     private void addSeenSequence(String taxonId, String md5checksum, String proteinIdentifier) 
    926         throws SAXException { 
     919            return flyResolver.resolveId(taxId, identifier).iterator().next(); 
     920        } 
     921    } 
     922 
     923    private void addSeenSequence(String taxonId, String md5checksum, String proteinIdentifier) { 
    927924        Map<String, String> orgSequences = sequences.get(taxonId); 
    928925        if (orgSequences == null) { 
     
    935932    } 
    936933 
    937     private boolean seenSequence(String taxonId, String md5checksum) 
    938         throws SAXException { 
     934    private boolean seenSequence(String taxonId, String md5checksum) { 
    939935        Map<String, String> orgSequences = sequences.get(taxonId); 
    940936        if (orgSequences == null) { 
     
    983979 
    984980    private String getInterpro(String identifier, String shortName) 
    985         throws SAXException, ObjectStoreException { 
     981        throws SAXException { 
    986982        String refId = domains.get(identifier); 
    987983        if (refId == null) { 
Note: See TracChangeset for help on using the changeset viewer.