Example usage for org.jdom2 Document getRootElement

List of usage examples for org.jdom2 Document getRootElement

Introduction

In this page you can find the example usage for org.jdom2 Document getRootElement.

Prototype

public Element getRootElement() 

Source Link

Document

This will return the root Element for this Document

Usage

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.experiments.CopyNumberVariationExperiment.java

License:Open Source License

public void generateXMLConfigurationFile(File output) throws IOException {
    Document configurationFile = new Document();
    Element configData = new Element(CONFIG_DATA);
    configurationFile.setRootElement(configData);
    configData.setAttribute(ExperimentUtils.BRANCH, ExperimentUtils.BRANCH_CNV);

    Element genRef = new Element(GENREF);
    genRef.addContent(this.getGenRefPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(genRef);

    Element dbSnpAnnot = new Element(DBSNPANNOT);
    dbSnpAnnot.addContent(this.getDbSnpAnnotPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(dbSnpAnnot);

    Element indelAnnot = new Element(INDELANNOT);
    indelAnnot.addContent(this.getIndelAnnotPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(indelAnnot);

    Element intervals = new Element(INTERVALS);
    intervals.addContent(this.getIntervalsPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(intervals);

    if (this.getKnownIndels().size() > 0) {
        for (KnownIndels kI : this.getKnownIndels()) {
            Element knownIndels = new Element(KNOWNINDELS);
            knownIndels.addContent(kI.getFile().getFile().getAbsolutePath());
            configurationFile.getRootElement().addContent(knownIndels);
        }//from  ww  w.  j  a v a 2s.co m
    }

    Element plattform = new Element(PLATTFORM);
    plattform.addContent(this.getPlattform().getDisplayName());
    configurationFile.getRootElement().addContent(plattform);

    if (!this.getCheckCasava().equals(checkCasava_DV)) {
        Element checkCasava = new Element(CHECKCASAVA);
        checkCasava.addContent(this.getCheckCasava().toString());
        configurationFile.getRootElement().addContent(checkCasava);
    }

    Element dirOutBase = new Element(DIROUTBASE);
    dirOutBase.addContent(this.getDirOutBase().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(dirOutBase);

    Element projectId = new Element(PROJECTID);
    projectId.addContent(this.getProjectId());
    configurationFile.getRootElement().addContent(projectId);

    if (!this.getUserName().equals(userName_DV)) {
        Element userName = new Element(USERNAME);
        userName.addContent(this.getUserName());
        configurationFile.getRootElement().addContent(userName);
    }

    Element dataInDirpreProcess = new Element(INDIRPREPROCESS);
    dataInDirpreProcess.addContent(this.getDataInDirpreProcess().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(dataInDirpreProcess);

    for (Sample s : this.getSamples()) {
        Element sample = new Element(SAMPLE);

        Element sampleName = new Element(SAMPLE_NAME);
        sampleName.addContent(s.getSampleName());
        sample.addContent(sampleName);

        Element sampleFiles = new Element(SAMPLE_FILES);
        sampleFiles.addContent(s.getSampleFiles());
        sample.addContent(sampleFiles);

        Element sampleSuffix = new Element(SAMPLE_SUFFIX);
        sampleSuffix.addContent(s.getSampleSuffix());
        sample.addContent(sampleSuffix);

        Element sampleType = new Element(SAMPLE_TYPE);
        sampleType.addContent(s.getSampleType().getDisplayName());
        sample.addContent(sampleType);

        configurationFile.getRootElement().addContent(sample);
    }

    if (!this.getFastqc().equals(fastqc_DV)) {
        Element fastqc = new Element(FASTQC);
        fastqc.addContent(this.getFastqc().toString());
        configurationFile.getRootElement().addContent(fastqc);
    }

    if (!this.getExtraContra().equals(extraContra_DV)) {
        Element extraContra = new Element(EXTRACONTRA);
        extraContra.addContent(this.getExtraContra().toString());
        configurationFile.getRootElement().addContent(extraContra);
    }

    if (this.getBaseline() != baseline_DV) {
        Element baseline = new Element(BASELINE);
        baseline.addContent(this.getBaseline().getFile().getAbsolutePath());
        configurationFile.getRootElement().addContent(baseline);
    }

    if (!this.getmDFlag().equals(mDFlag_DV)) {
        Element mDFlag = new Element(MDFLAG);
        mDFlag.addContent(this.getmDFlag().toString());
        configurationFile.getRootElement().addContent(mDFlag);
    }

    if (!this.getQueueSGEProject().equals(queueSGEProject_DV)) {
        Element queueSGEProject = new Element(QUEUESGEPROJECT);
        queueSGEProject.addContent(this.getQueueSGEProject().toString());
        configurationFile.getRootElement().addContent(queueSGEProject);
    }

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(configurationFile, new FileWriter(output));
}

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.experiments.CopyNumberVariationExperiment.java

License:Open Source License

public void loadDataFromFile(File editFile) throws InvalidRubioSeqParameterException {
    SAXBuilder saxBuilder = new SAXBuilder();
    try {/*from   w  w  w.  j  a v a  2s. c o m*/
        Document document = saxBuilder.build(editFile);
        Element configData = document.getRootElement();

        Element genRef = configData.getChild(GENREF);
        if (validElement(genRef)) {
            this.setGenRefPath(Utils.getRUbioSeqFile(genRef.getValue()));
        }

        Element dbSnpAnnot = configData.getChild(DBSNPANNOT);
        if (validElement(dbSnpAnnot)) {
            this.setDbSnpAnnotPath(Utils.getRUbioSeqFile(dbSnpAnnot.getValue()));
        }

        Element indelAnnot = configData.getChild(INDELANNOT);
        if (validElement(indelAnnot)) {
            this.setIndelAnnotPath(Utils.getRUbioSeqFile(indelAnnot.getValue()));
        }

        Element intervals = configData.getChild(INTERVALS);
        if (validElement(intervals)) {
            this.setIntervalsPath(Utils.getRUbioSeqFile(intervals.getValue()));
        }

        for (Element knownIndels : configData.getChildren(KNOWNINDELS)) {
            if (validElement(knownIndels)) {
                KnownIndels kI = new KnownIndels();
                kI.setFile(Utils.getRUbioSeqFile(knownIndels.getValue()));
                this.knownIndels.add(kI);
            }
        }

        Element plattform = configData.getChild(PLATTFORM);
        if (validElement(plattform)) {
            String plattformValue = plattform.getValue().toLowerCase();
            if (plattformValue.equals("illumina")) {
                this.setPlattform(PlattformTech.ILLUMINA);
            } else if (plattformValue.equals("ion")) {
                this.setPlattform(PlattformTech.ION);
            } else if (plattformValue.equals("solid")) {
                this.setPlattform(PlattformTech.SOLID);
            }
        }

        Element checkCasava = configData.getChild(CHECKCASAVA);
        if (validElement(checkCasava)) {
            this.setCheckCasava(Integer.valueOf(checkCasava.getValue()));
        }

        Element dirOutBase = configData.getChild(DIROUTBASE);
        if (validElement(dirOutBase)) {
            this.setDirOutBase(Utils.getRUbioSeqFile(dirOutBase.getValue()));
        }

        Element projectId = configData.getChild(PROJECTID);
        if (validElement(projectId)) {
            this.setProjectId(projectId.getValue());
        }

        Element userName = configData.getChild(USERNAME);
        if (validElement(userName)) {
            this.setUserName(userName.getValue());
        }

        Element dataInDirpreProcess = configData.getChild(INDIRPREPROCESS);
        if (validElement(dataInDirpreProcess)) {
            this.setDataInDirpreProcess(Utils.getRUbioSeqFile(dataInDirpreProcess.getValue()));
        }

        for (Element sampleElement : configData.getChildren(SAMPLE)) {
            Sample newSample = new Sample();

            Element sampleName = sampleElement.getChild(SAMPLE_NAME);
            if (validElement(sampleName)) {
                newSample.setSampleName(sampleName.getValue());
            }

            Element sampleFiles = sampleElement.getChild(SAMPLE_FILES);
            if (validElement(sampleFiles)) {
                newSample.setSampleFiles(sampleFiles.getValue());
            }

            Element sampleSuffix = sampleElement.getChild(SAMPLE_SUFFIX);
            if (validElement(sampleSuffix)) {
                newSample.setSampleSuffix(sampleSuffix.getValue());
            }

            Element sampleType = sampleElement.getChild(SAMPLE_TYPE);
            if (validElement(sampleType)) {
                newSample.setSampleType(
                        sampleType.getValue().equals("1") ? SampleType.SingleEnd : SampleType.PairedEnd);
            }

            this.getSamples().add(newSample);
        }

        Element fastqc = configData.getChild(FASTQC);
        if (validElement(fastqc)) {
            this.setFastqc(Integer.valueOf(fastqc.getValue()));
        }

        Element extraContra = configData.getChild(EXTRACONTRA);
        if (validElement(extraContra)) {
            this.setExtraContra(extraContra.getValue());
        }

        Element baseline = configData.getChild(BASELINE);
        if (validElement(baseline)) {
            this.setBaseline(Utils.getRUbioSeqFile(baseline.getValue()));
        }

        Element mDFlag = configData.getChild(MDFLAG);
        if (validElement(mDFlag)) {
            this.setmDFlag(Integer.valueOf(mDFlag.getValue()));
        }

        Element queueSGEProject = configData.getChild(QUEUESGEPROJECT);
        if (validElement(queueSGEProject)) {
            this.setQueueSGEProject(queueSGEProject.getValue());
        }

    } catch (JDOMException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        throw new InvalidRubioSeqParameterException(InvalidRubioSeqParameterException.DEFAULT_MESSAGE);
    }
}

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.experiments.ExperimentUtils.java

License:Open Source License

public static ExperimentType getExperimentType(File inputFile) throws InvalidRubioSeqParameterException {
    if (inputFile.isDirectory() || !inputFile.canRead() || !inputFile.getName().endsWith(".xml")) {
        return null;
    }//w  w w  .j a  v  a 2  s  . c  o m
    SAXBuilder saxBuilder = new SAXBuilder();
    try {
        Document document = saxBuilder.build(inputFile);
        Element configData = document.getRootElement();
        String branch = configData.getAttributeValue(ExperimentUtils.BRANCH);
        if (branch == null) {
            throw new InvalidRubioSeqParameterException(ExperimentUtils.BRANCH_MISSING_MESSAGE);
        } else {
            if (branch.equals(BRANCH_METHYLATION)) {
                return ExperimentType.Methylation;
            } else if (branch.equals(BRANCH_SNV)) {
                return ExperimentType.SNV;
            } else if (branch.equals(BRANCH_CNV)) {
                return ExperimentType.CNV;
            } else if (branch.equals(BRANCH_CHIPSEQ)) {
                return ExperimentType.CHIPSeq;
            }
        }
    } catch (JDOMException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.experiments.MethylationExperiment.java

License:Open Source License

public void generateXMLConfigurationFile(File output) throws IOException {
    Document configurationFile = new Document();
    Element configData = new Element(CONFIG_DATA);
    configurationFile.setRootElement(configData);
    configData.setAttribute(ExperimentUtils.BRANCH, ExperimentUtils.BRANCH_METHYLATION);

    Element referencePath = new Element(REFERENCEPATH);
    referencePath.addContent(this.getReferencePath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(referencePath);

    Element readsPath = new Element(READSPATH);
    readsPath.addContent(this.getReadsPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(readsPath);

    Element projectCompletePath = new Element(PROJECT_COMPLETE_PATH);
    projectCompletePath.addContent(this.getProjectCompletePath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(projectCompletePath);

    Element plattform = new Element(PLATTFORM);
    plattform.addContent(this.getPlattform().getDisplayName());
    configurationFile.getRootElement().addContent(plattform);

    Element methylType = new Element(METHYLTYPE);
    methylType.addContent(this.getMethylType().toString());
    configurationFile.getRootElement().addContent(methylType);

    for (MethylationSample ms : this.getSamples()) {
        Element sample1 = new Element(SAMPLE1);
        sample1.addContent(ms.getSample1().getFile().getName());
        configurationFile.getRootElement().addContent(sample1);
    }// ww  w  .j a  va  2s. c  o  m

    for (MethylationSample ms : this.getSamples()) {
        if (ms.getSample2() != null) {
            Element sample2 = new Element(SAMPLE2);
            sample2.addContent(ms.getSample2().getFile().getName());
            configurationFile.getRootElement().addContent(sample2);
        }
    }

    if (!this.getSeedLength().equals(seedLength_DV)) {
        Element seedLength = new Element(SEED_LENGTH);
        seedLength.addContent(this.getSeedLength().toString());
        configurationFile.getRootElement().addContent(seedLength);
    }

    if (!this.getNumMis().equals(numMis_DV)) {
        Element numMiss = new Element(NUM_MIS);
        numMiss.addContent(this.getNumMis().toString());
        configurationFile.getRootElement().addContent(numMiss);
    }

    if (this.getIntervalsPath() != intervalsPath_DV) {
        Element intervalsPath = new Element(INTERVALS);
        intervalsPath.addContent(this.getIntervalsPath().getFile().getAbsolutePath());
        configurationFile.getRootElement().addContent(intervalsPath);
    }

    if (!this.getContextType().equals(contextType_DV)) {
        Element contextType = new Element(CONTEXT);
        contextType.addContent(this.getContextType().toString());
        configurationFile.getRootElement().addContent(contextType);
    }

    if (!this.getTrimTagLength().equals(trimTagLength_DV)) {
        Element trimTagLength = new Element(TRIMTAGLENGTH);
        trimTagLength.addContent(this.getTrimTagLength());
        configurationFile.getRootElement().addContent(trimTagLength);
    }

    if (!this.getMinQual().equals(minQual_DV)) {
        Element minQual = new Element(MINQUAL);
        minQual.addContent(this.getMinQual().toString());
        configurationFile.getRootElement().addContent(minQual);
    }

    if (!this.getFastqc().equals(fastqc_DV)) {
        Element fastqc = new Element(FASTQC);
        fastqc.addContent(this.getFastqc().toString());
        configurationFile.getRootElement().addContent(fastqc);
    }

    if (!this.getDepthFilter().equals(depthFilter_DV)) {
        Element depthFilter = new Element(DEPTHFILTER);
        depthFilter.addContent(this.getDepthFilter().toString());
        configurationFile.getRootElement().addContent(depthFilter);
    }

    if (!this.getQueueSGEProject().equals(queueSGEProject_DV)) {
        Element queueProject = new Element(QUEUESGEPROJECT);
        queueProject.addContent(this.getQueueSGEProject().toString());
        configurationFile.getRootElement().addContent(queueProject);
    }

    if (!this.getMultiExec().equals(multiExec_DV)) {
        Element multiExec = new Element(MULTIEXEC);
        multiExec.addContent(this.getMultiExec().toString());
        configurationFile.getRootElement().addContent(multiExec);
    }

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(configurationFile, new FileWriter(output));
}

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.experiments.MethylationExperiment.java

License:Open Source License

public static String getWorkingDirectory(File inputFile) {
    SAXBuilder saxBuilder = new SAXBuilder();
    try {/*w w  w  .  j a v  a  2 s .  c  o m*/
        Document document = saxBuilder.build(inputFile);
        Element configData = document.getRootElement();

        Element projectCompletePath = configData.getChild(PROJECT_COMPLETE_PATH);

        return projectCompletePath.getValue();

    } catch (JDOMException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.experiments.MethylationExperiment.java

License:Open Source License

public void loadDataFromFile(File editFile) throws InvalidRubioSeqParameterException {
    SAXBuilder saxBuilder = new SAXBuilder();
    try {/*from  ww w. ja  va2s . c  o m*/
        Document document = saxBuilder.build(editFile);
        Element configData = document.getRootElement();

        Element referencePath = configData.getChild(REFERENCEPATH);
        if (validElement(referencePath)) {
            this.setReferencePath(Utils.getRUbioSeqFile(referencePath.getValue()));
        }

        Element intervals = configData.getChild(INTERVALS);
        if (validElement(intervals)) {
            this.setIntervalsPath(Utils.getRUbioSeqFile(intervals.getValue()));
        }

        Element plattform = configData.getChild(PLATTFORM);
        if (validElement(plattform)) {
            String plattformValue = plattform.getValue().toLowerCase();
            if (plattformValue.equals("illumina")) {
                this.setPlattform(PlattformTech.ILLUMINA);
            } else if (plattformValue.equals("fastq")) {
                this.setPlattform(PlattformTech.FASTQ);
            }
        }

        Element projectCompletePath = configData.getChild(PROJECT_COMPLETE_PATH);
        if (validElement(projectCompletePath)) {
            this.setProjectCompletePath(Utils.getRUbioSeqFile(projectCompletePath.getValue(), false));
        }

        Element readsPath = configData.getChild(READSPATH);
        if (validElement(readsPath)) {
            this.setReadsPath(Utils.getRUbioSeqFile(readsPath.getValue()));
        }

        Iterator<Element> sample1It = configData.getChildren(SAMPLE1).iterator();
        Iterator<Element> sample2It = configData.getChildren(SAMPLE2).iterator();
        this.samples = new LinkedList<MethylationSample>();

        while (sample1It.hasNext()) {

            MethylationSample newMS = new MethylationSample();

            Element sample1 = sample1It.next();
            if (validElement(sample1)) {
                newMS.setSample1(Utils.getRUbioSeqFile(
                        Utils.getDirectoryNameWithFinalSlash(this.getReadsPath().getFile().getAbsolutePath())
                                + sample1.getValue()));
            }

            if (sample2It.hasNext()) {
                Element sample2 = sample2It.next();
                if (validElement(sample2)) {
                    newMS.setSample2(Utils.getRUbioSeqFile(Utils.getDirectoryNameWithFinalSlash(
                            this.getReadsPath().getFile().getAbsolutePath()) + sample2.getValue()));
                }
            }

            this.getSamples().add(newMS);
        }

        Element seedLength = configData.getChild(SEED_LENGTH);
        if (validElement(seedLength)) {
            this.setSeedLength(Integer.valueOf(seedLength.getValue()));
        }

        Element numMiss = configData.getChild(NUM_MIS);
        if (validElement(numMiss)) {
            this.setNumMis(Integer.valueOf(numMiss.getValue()));
        }

        Element minQual = configData.getChild(MINQUAL);
        if (validElement(minQual)) {
            this.setNumMis(Integer.valueOf(minQual.getValue()));
        }

        Element depthFilter = configData.getChild(DEPTHFILTER);
        if (validElement(depthFilter)) {
            this.setDepthFilter(Double.valueOf(depthFilter.getValue()));
        }

        Element methylType = configData.getChild(METHYLTYPE);
        if (validElement(methylType)) {
            String methylTypeValue = methylType.getValue().toUpperCase();
            if (methylTypeValue.equals("LISTER")) {
                this.setMethylType(MethylType.LISTER);
            } else if (methylTypeValue.equals("COKUS")) {
                this.setMethylType(MethylType.COKUS);
            }
        }

        Element contextType = configData.getChild(CONTEXT);
        if (validElement(contextType)) {
            String contextTypeValue = contextType.getValue();
            if (contextTypeValue.equals("ALL")) {
                this.setContextType(ContextType.ALL);
            } else if (contextTypeValue.equals("CpG")) {
                this.setContextType(ContextType.CPG);
            } else if (contextTypeValue.equals("CHG")) {
                this.setContextType(ContextType.CHG);
            } else if (contextTypeValue.equals("CHH")) {
                this.setContextType(ContextType.CHH);
            }
        }

        Element multiExec = configData.getChild(MULTIEXEC);
        if (validElement(multiExec)) {
            this.setMultiExec(Integer.valueOf(multiExec.getValue()));
        }

        Element trimTagLenght = configData.getChild(TRIMTAGLENGTH);
        if (validElement(trimTagLenght)) {
            this.setTrimTagLength(trimTagLenght.getValue());
        }

        Element fastqc = configData.getChild(FASTQC);
        if (validElement(fastqc)) {
            this.setFastqc(Integer.valueOf(fastqc.getValue()));
        }

        Element queueSGEProject = configData.getChild(QUEUESGEPROJECT);
        if (validElement(queueSGEProject)) {
            this.setQueueSGEProject(queueSGEProject.getValue());
        }

    } catch (JDOMException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        throw new InvalidRubioSeqParameterException(InvalidRubioSeqParameterException.DEFAULT_MESSAGE);
    }
}

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.experiments.SingleNucleotideVariantExperiment.java

License:Open Source License

public void generateXMLConfigurationFile(File output) throws IOException {
    Document configurationFile = new Document();
    Element configData = new Element(CONFIG_DATA);
    configurationFile.setRootElement(configData);
    configData.setAttribute(ExperimentUtils.BRANCH, ExperimentUtils.BRANCH_SNV);

    Element genRef = new Element(GENREF);
    genRef.addContent(this.getGenRefPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(genRef);

    Element dbSnpAnnot = new Element(DBSNPANNOT);
    dbSnpAnnot.addContent(this.getDbSnpAnnotPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(dbSnpAnnot);

    Element genomes1000Annot = new Element(GENOMES1000ANNOT);
    genomes1000Annot.addContent(this.getGenomes1000AnnotPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(genomes1000Annot);

    Element indelAnnot = new Element(INDELANNOT);
    indelAnnot.addContent(this.getIndelAnnotPath().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(indelAnnot);

    if (this.getIntervalsPath() != getIntervalsPath_DV()) {
        Element intervals = new Element(INTERVALS);
        intervals.addContent(this.getIntervalsPath().getFile().getAbsolutePath());
        configurationFile.getRootElement().addContent(intervals);
    }//from   w w  w .j  ava 2s. c  o m

    if (this.getKnownIndels().size() > 0) {
        for (KnownIndels kI : this.getKnownIndels()) {
            Element knownIndels = new Element(KNOWNINDELS);
            knownIndels.addContent(kI.getFile().getFile().getAbsolutePath());
            configurationFile.getRootElement().addContent(knownIndels);
        }
    }

    Element plattform = new Element(PLATTFORM);
    plattform.addContent(this.getPlattform().getDisplayName());
    configurationFile.getRootElement().addContent(plattform);

    if (!this.getCheckCasava().equals(checkCasava_DV)) {
        Element checkCasava = new Element(CHECKCASAVA);
        checkCasava.addContent(this.getCheckCasava().toString());
        configurationFile.getRootElement().addContent(checkCasava);
    }

    Element dirOutBase = new Element(DIROUTBASE);
    dirOutBase.addContent(this.getDirOutBase().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(dirOutBase);

    Element projectId = new Element(PROJECTID);
    projectId.addContent(this.getProjectId());
    configurationFile.getRootElement().addContent(projectId);

    if (!this.getUserName().equals(userName_DV)) {
        Element userName = new Element(USERNAME);
        userName.addContent(this.getUserName());
        configurationFile.getRootElement().addContent(userName);
    }

    Element dataInDirpreProcess = new Element(INDIRPREPROCESS);
    dataInDirpreProcess.addContent(this.getDataInDirpreProcess().getFile().getAbsolutePath());
    configurationFile.getRootElement().addContent(dataInDirpreProcess);

    for (Sample s : this.getSamples()) {
        Element sample = new Element(SAMPLE);

        Element sampleName = new Element(SAMPLE_NAME);
        sampleName.addContent(s.getSampleName());
        sample.addContent(sampleName);

        Element sampleFiles = new Element(SAMPLE_FILES);
        sampleFiles.addContent(s.getSampleFiles());
        sample.addContent(sampleFiles);

        Element sampleSuffix = new Element(SAMPLE_SUFFIX);
        sampleSuffix.addContent(s.getSampleSuffix());
        sample.addContent(sampleSuffix);

        Element sampleType = new Element(SAMPLE_TYPE);
        sampleType.addContent(s.getSampleType().getDisplayName());
        sample.addContent(sampleType);

        configurationFile.getRootElement().addContent(sample);
    }

    if (!this.getCallingType().equals(callingType_DV)) {
        Element callingType = new Element(CALLYING_TYPE);
        callingType.addContent(this.getCallingType().toString());
        configurationFile.getRootElement().addContent(callingType);
    }

    if (!this.getgATKoutputMode().equals(gATKoutputMode_DV)) {
        Element gATKoutputModeoutputMode = new Element(GATKOUTPUTMODE);
        gATKoutputModeoutputMode.addContent(this.getgATKoutputMode().toString());
        configurationFile.getRootElement().addContent(gATKoutputModeoutputMode);
    }

    if (!this.getRsFilter().equals(rsFilter_DV)) {
        Element rsFilter = new Element(RSFILTER);
        rsFilter.addContent(this.getRsFilter().toString());
        configurationFile.getRootElement().addContent(rsFilter);
    }

    if (!this.getrUbioSeqMode().equals(rUbioSeqMode_DV)) {
        Element rUbioSeq_Mode = new Element(RUBIOSEQMODE);
        rUbioSeq_Mode.addContent(this.getrUbioSeqMode().toString());
        configurationFile.getRootElement().addContent(rUbioSeq_Mode);
    }

    if (!this.getFastqc().equals(fastqc_DV)) {
        Element fastqc = new Element(FASTQC);
        fastqc.addContent(this.getFastqc().toString());
        configurationFile.getRootElement().addContent(fastqc);
    }

    if (!this.getvEPFlag().equals(vEPFlag_DV)) {
        Element vEPFlag = new Element(VEPFLAG);
        vEPFlag.addContent(this.getvEPFlag().toString());
        configurationFile.getRootElement().addContent(vEPFlag);
    }

    if (!this.gettCFlag().equals(tCFlag_DV)) {
        Element tCFlag = new Element(TCFLAG);
        tCFlag.addContent(this.gettCFlag().toString());
        configurationFile.getRootElement().addContent(tCFlag);
    }

    if (!this.getmDFlag().equals(mDFlag_DV)) {
        Element mDFlag = new Element(MDFLAG);
        mDFlag.addContent(this.getmDFlag().toString());
        configurationFile.getRootElement().addContent(mDFlag);
    }

    if (!this.getStandCallConf().equals(standCallConf_DV)) {
        Element standCallConf = new Element(STANDCALLCONF);
        standCallConf.addContent(this.getStandCallConf().toString());
        configurationFile.getRootElement().addContent(standCallConf);
    }

    if (!this.getStandEmitConf().equals(standEmitConf_DV)) {
        Element standEmitConf = new Element(STANDEMITCONF);
        standEmitConf.addContent(this.getStandEmitConf().toString());
        configurationFile.getRootElement().addContent(standEmitConf);
    }

    if (!this.getQueueSGEProject().equals(queueSGEProject_DV)) {
        Element queueSGEProject = new Element(QUEUESGEPROJECT);
        queueSGEProject.addContent(this.getQueueSGEProject().toString());
        configurationFile.getRootElement().addContent(queueSGEProject);
    }

    if (this.getChoiceVqrsHardFilters().equals(VQRSHardFiltersChoice.VQRS)
            && this.getvQSRblockMills() != VQSRblockMills_DV && this.getvQSRblockHapMAp() != VQSRblockHapMAp_DV
            && this.getvQSRblockThousandG() != VQSRblockThousandG_DV) {

        Element vQSR_block = new Element(VQSRBLOCK);

        Element mills = new Element(MILLS);
        mills.addContent(this.getvQSRblockMills().getFile().getAbsolutePath());
        vQSR_block.addContent(mills);

        Element hapmap = new Element(HAPMAP);
        hapmap.addContent(this.getvQSRblockHapMAp().getFile().getAbsolutePath());
        vQSR_block.addContent(hapmap);

        Element thousandg = new Element(THOUSANDG);
        thousandg.addContent(this.getvQSRblockThousandG().getFile().getAbsolutePath());
        vQSR_block.addContent(thousandg);

        configurationFile.getRootElement().addContent(vQSR_block);
    }

    if (this.getChoiceVqrsHardFilters().equals(VQRSHardFiltersChoice.HARDFILTERS)
            && (!this.getminQual().equals(minQual_DV) || !this.getdPmin().equals(DPmin_DV)
                    || this.getHardFilters().size() > 0)) {

        Element hardFiltersBlock = new Element(HFILTERS);

        if (!this.getdPmin().equals(DPmin_DV)) {
            Element dpMin = new Element(DPMIN);
            dpMin.addContent(this.getdPmin().toString());
            hardFiltersBlock.addContent(dpMin);
        }

        if (!this.getminQual().equals(minQual_DV)) {
            Element minQual = new Element(MINQUAL);
            minQual.addContent(this.getminQual().toString());
            hardFiltersBlock.addContent(minQual);
        }

        for (HardFilter hF : this.getHardFilters()) {
            Element name = hF.getType().equals(HardFilter.HFilterType.SNP) ? new Element(HFILTER_NAME_SNP)
                    : new Element(HFILTER_NAME_INDEL);
            name.addContent(hF.getName());
            Element rule = hF.getType().equals(HardFilter.HFilterType.SNP) ? new Element(HFILTER_RULE_SNP)
                    : new Element(HFILTER_RULE_INDEL);
            rule.addContent(hF.getRule());
            hardFiltersBlock.addContent(name);
            hardFiltersBlock.addContent(rule);
        }

        configurationFile.getRootElement().addContent(hardFiltersBlock);
    }

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    xmlOutput.output(configurationFile, new FileWriter(output));
}

From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.experiments.SingleNucleotideVariantExperiment.java

License:Open Source License

public void loadDataFromFile(File editFile) throws InvalidRubioSeqParameterException {
    SAXBuilder saxBuilder = new SAXBuilder();
    try {//from w w w  .  java  2  s .  c  om
        Document document = saxBuilder.build(editFile);
        Element configData = document.getRootElement();

        Element genRef = configData.getChild(GENREF);
        if (validElement(genRef)) {
            this.setGenRefPath(Utils.getRUbioSeqFile(genRef.getValue()));
        }

        Element dbSnpAnnot = configData.getChild(DBSNPANNOT);
        if (validElement(dbSnpAnnot)) {
            this.setDbSnpAnnotPath(Utils.getRUbioSeqFile(dbSnpAnnot.getValue()));
        }

        Element genomes1000Annot = configData.getChild(GENOMES1000ANNOT);
        if (validElement(genomes1000Annot)) {
            this.setGenomes1000AnnotPath(Utils.getRUbioSeqFile(genomes1000Annot.getValue()));
        }

        Element indelAnnot = configData.getChild(INDELANNOT);
        if (validElement(indelAnnot)) {
            this.setIndelAnnotPath(Utils.getRUbioSeqFile(indelAnnot.getValue()));
        }

        Element intervals = configData.getChild(INTERVALS);
        if (validElement(intervals)) {
            this.setIntervalsPath(Utils.getRUbioSeqFile(intervals.getValue()));
        }

        for (Element knownIndels : configData.getChildren(KNOWNINDELS)) {
            if (validElement(knownIndels)) {
                KnownIndels kI = new KnownIndels();
                kI.setFile(Utils.getRUbioSeqFile(knownIndels.getValue()));
                this.knownIndels.add(kI);
            }
        }

        Element plattform = configData.getChild(PLATTFORM);
        if (validElement(plattform)) {
            String plattformValue = plattform.getValue().toLowerCase();
            if (plattformValue.equals("illumina")) {
                this.setPlattform(PlattformTech.ILLUMINA);
            } else if (plattformValue.equals("ion")) {
                this.setPlattform(PlattformTech.ION);
            } else if (plattformValue.equals("solid")) {
                this.setPlattform(PlattformTech.SOLID);
            }
        }

        Element checkCasava = configData.getChild(CHECKCASAVA);
        if (validElement(checkCasava)) {
            this.setCheckCasava(Integer.valueOf(checkCasava.getValue()));
        }

        Element dirOutBase = configData.getChild(DIROUTBASE);
        if (validElement(dirOutBase)) {
            this.setDirOutBase(Utils.getRUbioSeqFile(dirOutBase.getValue()));
        }

        Element projectId = configData.getChild(PROJECTID);
        if (validElement(projectId)) {
            this.setProjectId(projectId.getValue());
        }

        Element userName = configData.getChild(USERNAME);
        if (validElement(userName)) {
            this.setUserName(userName.getValue());
        }

        Element dataInDirpreProcess = configData.getChild(INDIRPREPROCESS);
        if (validElement(dataInDirpreProcess)) {
            this.setDataInDirpreProcess(Utils.getRUbioSeqFile(dataInDirpreProcess.getValue()));
        }

        for (Element sampleElement : configData.getChildren(SAMPLE)) {
            Sample newSample = new Sample();

            Element sampleName = sampleElement.getChild(SAMPLE_NAME);
            if (validElement(sampleName)) {
                newSample.setSampleName(sampleName.getValue());
            }

            Element sampleFiles = sampleElement.getChild(SAMPLE_FILES);
            if (validElement(sampleFiles)) {
                newSample.setSampleFiles(sampleFiles.getValue());
            }

            Element sampleSuffix = sampleElement.getChild(SAMPLE_SUFFIX);
            if (validElement(sampleSuffix)) {
                newSample.setSampleSuffix(sampleSuffix.getValue());
            }

            Element sampleType = sampleElement.getChild(SAMPLE_TYPE);
            if (validElement(sampleType)) {
                newSample.setSampleType(
                        sampleType.getValue().equals("1") ? SampleType.SingleEnd : SampleType.PairedEnd);
            }

            this.getSamples().add(newSample);
        }

        Element callingType = configData.getChild(CALLYING_TYPE);
        if (validElement(callingType)) {
            String callingTypeValue = callingType.getValue().toUpperCase();
            if (callingTypeValue.equals("SNP")) {
                this.setCallingType(CallingType.SNP);
            } else if (callingTypeValue.equals("INDEL")) {
                this.setCallingType(CallingType.INDEL);
            } else if (callingTypeValue.equals("BOTH")) {
                this.setCallingType(CallingType.BOTH);
            }
        }

        Element gATKoutputModeoutputMode = configData.getChild(GATKOUTPUTMODE);
        if (validElement(gATKoutputModeoutputMode)) {
            String gatkOutputModeValue = gATKoutputModeoutputMode.getValue().toUpperCase();
            if (gatkOutputModeValue.equals("EMIT_VARIANTS_ONLY")) {
                this.setgATKoutputMode(GATKoutputMode.EMIT_VARIANTS_ONLY);
            } else if (gatkOutputModeValue.equals("EMIT_ALL_SITES")) {
                this.setgATKoutputMode(GATKoutputMode.EMIT_ALL_SITES);
            } else if (gatkOutputModeValue.equals("EMIT_ALL_CONFIDENT_SITES")) {
                this.setgATKoutputMode(GATKoutputMode.EMIT_ALL_CONFIDENT_SITES);
            }
        }

        Element rsFilter = configData.getChild(RSFILTER);
        if (validElement(rsFilter)) {
            this.setRsFilter(Integer.valueOf(rsFilter.getValue()));
        }

        Element rUbioSeq_Mode = configData.getChild(RUBIOSEQMODE);
        if (validElement(rUbioSeq_Mode)) {
            this.setrUbioSeqMode(Integer.valueOf(rUbioSeq_Mode.getValue()));
        }

        Element fastqc = configData.getChild(FASTQC);
        if (validElement(fastqc)) {
            this.setFastqc(Integer.valueOf(fastqc.getValue()));
        }

        Element vEPFlag = configData.getChild(VEPFLAG);
        if (validElement(vEPFlag)) {
            this.setvEPFlag(Integer.valueOf(vEPFlag.getValue()));
        }

        Element tCFlag = configData.getChild(TCFLAG);
        if (validElement(tCFlag)) {
            this.settCFlag(Integer.valueOf(tCFlag.getValue()));
        }

        Element mDFlag = configData.getChild(MDFLAG);
        if (validElement(mDFlag)) {
            this.setmDFlag(Integer.valueOf(mDFlag.getValue()));
        }

        Element standCallConf = configData.getChild(STANDCALLCONF);
        if (validElement(standCallConf)) {
            this.setStandCallConf(Double.valueOf(standCallConf.getValue()));
        }

        Element standEmitConf = configData.getChild(STANDEMITCONF);
        if (validElement(standEmitConf)) {
            this.setStandEmitConf(Double.valueOf(standEmitConf.getValue()));
        }

        Element queueSGEProject = configData.getChild(QUEUESGEPROJECT);
        if (validElement(queueSGEProject)) {
            this.setQueueSGEProject(queueSGEProject.getValue());
        }

        Element vqsrBlock = configData.getChild(VQSRBLOCK);
        if (vqsrBlock != null) {

            this.setChoiceVqrsHardFilters(VQRSHardFiltersChoice.VQRS);

            Element mills = vqsrBlock.getChild(MILLS);
            if (validElement(mills)) {
                this.setvQSRblockMills(Utils.getRUbioSeqFile(mills.getValue()));
            }

            Element hapmap = vqsrBlock.getChild(HAPMAP);
            if (validElement(hapmap)) {
                this.setvQSRblockHapMAp(Utils.getRUbioSeqFile(hapmap.getValue()));
            }

            Element thousandg = vqsrBlock.getChild(THOUSANDG);
            if (validElement(thousandg)) {
                this.setvQSRblockThousandG(Utils.getRUbioSeqFile(thousandg.getValue()));
            }

        }

        Element hardFiltersBlock = configData.getChild(HFILTERS);
        if (hardFiltersBlock != null) {

            this.setChoiceVqrsHardFilters(VQRSHardFiltersChoice.HARDFILTERS);

            Element dpMin = hardFiltersBlock.getChild(DPMIN);
            if (validElement(dpMin)) {
                this.setdPmin(Integer.valueOf(dpMin.getValue()));
            }

            Element minQual = hardFiltersBlock.getChild(MINQUAL);
            if (validElement(minQual)) {
                this.setminQual(Integer.valueOf(minQual.getValue()));
            }

            Iterator<Element> hFilterNameSNP = hardFiltersBlock.getChildren(HFILTER_NAME_SNP).iterator();
            Iterator<Element> hFilterRuleSNP = hardFiltersBlock.getChildren(HFILTER_RULE_SNP).iterator();
            while (hFilterNameSNP.hasNext() && hFilterRuleSNP.hasNext()) {
                Element hFilterNameSNPElement = hFilterNameSNP.next();
                Element hFilterRuleSNPElement = hFilterRuleSNP.next();
                HardFilter newHardFilter = new HardFilter();
                newHardFilter.setName(hFilterNameSNPElement.getValue());
                newHardFilter.setRule(hFilterRuleSNPElement.getValue());
                newHardFilter.setType(HFilterType.SNP);
                this.getHardFilters().add(newHardFilter);
            }

            Iterator<Element> hFilterNameINDEL = hardFiltersBlock.getChildren(HFILTER_NAME_INDEL).iterator();
            Iterator<Element> hFilterRuleINDEL = hardFiltersBlock.getChildren(HFILTER_RULE_INDEL).iterator();
            while (hFilterNameINDEL.hasNext() && hFilterRuleINDEL.hasNext()) {
                Element hFilterNameINDELElement = hFilterNameINDEL.next();
                Element hFilterRuleINDELElement = hFilterRuleINDEL.next();
                HardFilter newHardFilter = new HardFilter();
                newHardFilter.setName(hFilterNameINDELElement.getValue());
                newHardFilter.setRule(hFilterRuleINDELElement.getValue());
                newHardFilter.setType(HFilterType.INDEL);
                this.getHardFilters().add(newHardFilter);
            }

        }

    } catch (JDOMException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        throw new InvalidRubioSeqParameterException(InvalidRubioSeqParameterException.DEFAULT_MESSAGE);
    }
}

From source file:esiptestbed.mudrod.main.MudrodEngine.java

License:Apache License

/**
 * Load the configuration provided at <a href=
 * "https://github.com/mudrod/mudrod/blob/master/core/src/main/resources/config.xml">config.xml</a>.
 * //from w  w  w .j  av a 2 s .com
 * @return a populated {@link java.util.Properties} object.
 */
public Properties loadConfig() {
    SAXBuilder saxBuilder = new SAXBuilder();
    InputStream configStream = MudrodEngine.class.getClassLoader().getResourceAsStream("config.xml");

    Document document;
    try {
        document = saxBuilder.build(configStream);
        Element rootNode = document.getRootElement();
        List<Element> paraList = rootNode.getChildren("para");

        for (int i = 0; i < paraList.size(); i++) {
            Element paraNode = paraList.get(i);
            props.put(paraNode.getAttributeValue("name"), paraNode.getTextTrim());
        }
    } catch (JDOMException | IOException e) {
        LOG.error("Exception whilst retreiving or processing XML contained within 'config.xml'!", e);
    }
    return getConfig();

}

From source file:eu.himeros.cophi.ocr.proofreader.controller.pojo.HocrDocumentBuilder.java

License:Open Source License

/**
 * Builds the hocr document, extracting the header from the old hocr document.
 * @param the old hocrDocument/*from   w w  w  .  ja  va2  s  .  c  om*/
 * @return the new ohocrDocument
 */
public Document build(Document hocrDocument) {
    Element root = hocrDocument.getRootElement();
    xmlns = root.getNamespace();
    Element bodyEl = root.getChildren().get(1);
    Element ocrPageEl = bodyEl.getChildren().get(0).detach();
    String pageId = ocrPageEl.getAttributeValue("id");
    ocrPageEl = new Element("div", xmlns);
    ocrPageEl.setAttribute("class", "ocr_page");
    ocrPageEl.setAttribute("id", pageId);
    for (OcrLine ocrLine : ocrPage.getOcrLines()) {
        ocrPageEl.addContent(makeOcrLineEl(ocrLine));
        ocrPageEl.addContent(new Element("br", xmlns));
    }
    bodyEl.addContent(ocrPageEl);
    return hocrDocument;
}