⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maciereader.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return entries;    }        private void createNiceMACiETitle(ChemModel chemModel) {        chemModel.setProperty(CDKConstants.TITLE,            "MACIE " + currentEntry.getProperty(EnzymeName) + "= " +            "PDB: " + currentEntry.getProperty(PDBCode) + ", " +            "EC: " + currentEntry.getProperty(ECNumber)        );    }        private String[] readDtypeDatumTuple(String triggerLine) throws IOException {        String dTypeLine = triggerLine;        String datumLine = input.readLine();        String type = dTypeLine.substring(7);        String datum = datumLine.substring(7);        logger.debug("Tuple TYPE: ", type);        String line = datum;        if (datum.endsWith("$MFMT")) {            // deal with MDL mol content            StringBuffer fullDatum = new StringBuffer();            do {                line = input.readLine();                fullDatum.append(line);            } while (!(line.equals("M  END")));            datum = fullDatum.toString();        } else if (datum.endsWith("+") && (datum.length() >= 74)) {            // deal with multiline fields            StringBuffer fullDatum = new StringBuffer();            fullDatum.append(datum.substring(0,datum.length()-1));            do {                line = input.readLine();                if (line.length() > 0)                     fullDatum.append(line.substring(0,line.length()-1));            } while (line.endsWith("+"));            datum = fullDatum.toString();        }        logger.debug("     DATUM: ", datum);        String[] tuple = new String[2];        tuple[0] = type;        tuple[1] = datum;        return tuple;    }        private void processTopLevelField(String field, String datum)       throws IOException, CDKException {        logger.debug("Processing top level field");        if (field.equals("UNIQUE IDENTIFIER")) {            currentEntry.setID("MACIE-" + datum);        } else if (field.equals("EC NUMBER")) {            currentEntry.setProperty(ECNumber, datum);        } else if (field.equals("PDB CODE")) {            currentEntry.setProperty(PDBCode, datum);        } else if (field.equals("ENZYME NAME")) {            currentEntry.setProperty(EnzymeName, datum);        } else {            logger.warn("Unrecognized ROOT field ", field,                         " around line " + input.getLineNumber());        }    }        private void processSubLevelField(String field, String fieldNumber,                                      String subfield, String datum)       throws IOException, CDKException {        logger.debug("Processing sub level field");        if (field.equals("OVERALL REACTION")) {            if (subfield.equals("REACTION_ID")) {                if (readSecondaryFiles.isSet() && readThisEntry) {                    // parse referenced file                    String filename = readSecondaryDir.getSetting() + datum + ".rxn";                    File file = new File(filename);                    if (file.exists()) {                        logger.info("Reading overall reaction from: ", filename);                        FileReader reader = new FileReader(file);                        IChemObjectReader rxnReader = new ReaderFactory().createReader(reader);                        currentReaction = (Reaction)rxnReader.read(new Reaction());                        currentReaction.setID(datum);                        currentReaction.setProperty(CDKConstants.TITLE, "Overall Reaction");                        // don't add it now, wait until annotation is parsed                    } else {                        String error = "Cannot find secondary file: " + filename;                        logger.error(error);                        throw new CDKException(error);                    }                } else {                    logger.warn("Not reading overall reaction for this entry");                }            } else if (subfield.equals("OVERALL REACTION ANNOTATION")) {                parseReactionAnnotation(datum, currentReaction);                currentReactionStepSet.addReaction(currentReaction);            }        } else if (field.equals("REACTION STAGES")) {            if (subfield.equals("REACTION STAGES")) {                // new reaction step                // cannot create one, because CDK io does not                // allow that (yet)                reactionStepAnnotation = null;                reactionStepComments = null;            } else if (subfield.equals("ANNOTATION")) {                reactionStepAnnotation = datum;            } else if (subfield.equals("COMMENTS")) {                reactionStepComments = datum;            } else if (subfield.equals("STEP_ID")) {                // read secondary RXN files?                if (readSecondaryFiles.isSet() && readThisEntry) {                    // parse referenced file                    String filename = readSecondaryDir.getSetting() + datum + ".rxn";                    File file = new File(filename);                    if (file.exists()) {                        logger.info("Reading reaction step from: ", filename);                        FileReader reader = new FileReader(file);                        IChemObjectReader rxnReader = new ReaderFactory().createReader(reader);                        currentReaction = (Reaction)rxnReader.read(new Reaction());                        currentReaction.setID(datum);                        currentReaction.setProperty(CDKConstants.TITLE, "Step " + fieldNumber);                    } else {                        logger.error("Cannot find secondary file: ", filename);                    }                    // convert PseudoAtom's in EnzymeResidueLocator's if appropriate                    markEnzymeResidueLocatorAtoms(currentReaction);                    // now parse annotation                    if (reactionStepAnnotation != null) {                        parseReactionAnnotation(reactionStepAnnotation, currentReaction);                    }                    // and set comments                    if (reactionStepComments != null) {                        currentReaction.setProperty(CDKConstants.COMMENT, reactionStepComments);                    }                    // now, I'm ready to add reaction                    currentReactionStepSet.addReaction(currentReaction);                } else {                    logger.warn("Not reading reactions of this entry.");                }            }        } else if (field.equals("SUBSTRATES")) {            logger.warn("Ignoring top level definition of substrates");        } else if (field.equals("PRODUCTS")) {            logger.warn("Ignoring top level definition of products");        } else if (field.equals("REFERENCES")) {             if (subfield.equals("MEDLINE_ID")) {                 currentEntry.setProperty(MedlineID, datum);             }        } else {            logger.error("Unrecognized sub level field ", field,                         " around line " + input.getLineNumber());        }    }        private void markEnzymeResidueLocatorAtoms(Reaction currentReaction) {    	Iterator containers = ReactionManipulator.getAllAtomContainers(currentReaction).iterator();    	while (containers.hasNext()) {    		IAtomContainer ac = (IAtomContainer) containers.next();    		for (int i=0; i<ac.getAtomCount(); i++) {    			IAtom atom = ac.getAtom(i);    			if (atom instanceof EnzymeResidueLocator) {    				// skip atom    			} else if (atom instanceof PseudoAtom) {    				PseudoAtom pseudo = (PseudoAtom)atom;    				logger.debug("pseudo atom label: ", pseudo.getLabel());    				logger.debug("pseudo class: ", pseudo.getClass().getName());    				Matcher residueLocatorMatcher = residueLocator.matcher(pseudo.getLabel());    				if (residueLocatorMatcher.matches()) {    					logger.debug("Found residueLocator: ", pseudo.getLabel());    					// replace atom with enzymeResidueLocator    					IAtomContainer container = ReactionManipulator.getRelevantAtomContainer(    							currentReaction, pseudo    					);    					logger.debug("Replacing the pseudo atom with a ezymeResidueLocator atom");    					AtomContainerManipulator.replaceAtomByAtom(container,     							pseudo, new EnzymeResidueLocator(pseudo));    				}    			}    		}    	}    }        private void parseReactionAnnotation(String annotation, Reaction reaction) {        logger.debug("Parsing annotation...");        Matcher annotationTupleMatcher =            annotationTuple.matcher(annotation);        while (annotationTupleMatcher.matches()) {            String field = annotationTupleMatcher.group(1);            String value = annotationTupleMatcher.group(2);            processAnnotation(field, value, reaction);            // eat next part of annotation            String remainder = annotationTupleMatcher.group(3);            annotationTupleMatcher =                annotationTuple.matcher(remainder);        }    }    private void processAnnotation(String field, String value, Reaction reaction) {        logger.debug("Annote: ", field, "=", value);        if (field.equals("RxnAtts") || field.equals("RxnType")) {            // reaction attributes            /*String dictionary = "macie";            if (value.equals("Acid") || value.equals("Base")) {                dictionary = "chemical";            }*/            addDictRefedAnnotation(reaction, "Attributes", value);        } else if (field.equals("ResiduesPresent") ||                   field.equals("GroupTransferred") ||                   field.equals("BondFormed") ||                   field.equals("ReactiveCentres") ||                   field.equals("BondCleaved") ||                   field.equals("BondFormed") ||                   field.equals("Products") ||                   field.equals("ResiduesPresent")) {            reaction.setProperty(new DictRef("macie:" + field, value), value);        } else if (field.equals("Reversible")) {            if (value.equalsIgnoreCase("yes")) {                reaction.setDirection(Reaction.BIDIRECTIONAL);                addDictRefedAnnotation(reaction, "ReactionType", "ReversibleReaction");            }        } else if (field.equals("OverallReactionType")) {            StringTokenizer tokenizer = new StringTokenizer(value, ",");            int i = 0;            while (tokenizer.hasMoreTokens()) {                String token = tokenizer.nextToken();                i++;                reaction.setProperty(                    DictionaryDatabase.DICTREFPROPERTYNAME + ":field:overallReactionType:" + i,                     "macie:" + token.toLowerCase()                );            }        } else {            Matcher residueLocatorMatcher =                residueLocator.matcher(field);            if (residueLocatorMatcher.matches()) {                logger.debug("Found residueLocator: ", field);            	boolean found = false;                Iterator containers = ReactionManipulator.getAllAtomContainers(reaction).iterator();                while (containers.hasNext()) {                	IAtomContainer ac = (IAtomContainer) containers.next();                	logger.debug("Searching for given residueLocator through #atom: ", ac.getAtomCount());                	logger.debug("Taken from reaction ", reaction.getID());                	for (int i=0; (i<ac.getAtomCount() && !found); i++) {                		if (ac.getAtom(i) instanceof PseudoAtom) {                			// that is what we are looking for                			PseudoAtom atom = (PseudoAtom)ac.getAtom(i);                			if (atom.getLabel().equals(field)) {                				// we have a hit, now mark Atom with dict refs                				addDictRefedAnnotation(atom, "ResidueRole", value);                				found = true;                			}                		}                	}                }                if (!found) {                    logger.error("MACiE annotation mentions a residue that does not exist: " + field);                }            } else {                logger.error("Did not parse annotation: ", field);            }        }    }        private void addDictRefedAnnotation(IChemObject object, String type, String values) {        StringTokenizer tokenizer = new StringTokenizer(values, ",");        while (tokenizer.hasMoreTokens()) {            String token = tokenizer.nextToken();            object.setProperty(new DictRef("macie:" + type, token), token);            logger.debug("Added dict ref ", token, " to ", object.getClass().getName());        }    }        public void close() throws IOException {        input.close();    }    private void initIOSettings() {        selectedEntry = new IntegerIOSetting("SelectedEntry", IOSetting.LOW,          "Which entry should I read?",          "1");        readSecondaryFiles = new BooleanIOSetting("ReadSecondaryFiles", IOSetting.LOW,          "Should I read the secondary files (if available)?",          "true");        readSecondaryDir = new StringIOSetting("ReadSecondaryDir", IOSetting.LOW,          "Where can the secondary files be found?",          System.getProperty("user.home") + System.getProperty("file.separator"));    }        private void customizeJob() {        fireIOSettingQuestion(selectedEntry);        fireIOSettingQuestion(readSecondaryFiles);        fireIOSettingQuestion(readSecondaryDir);    }    public IOSetting[] getIOSettings() {        IOSetting[] settings = new IOSetting[3];        settings[0] = selectedEntry;        settings[1] = readSecondaryFiles;        settings[2] = readSecondaryDir;        return settings;    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -