Search in sources :

Example 1 with PsProjectFeature

use of com.compomics.util.io.export.features.peptideshaker.PsProjectFeature in project peptide-shaker by compomics.

the class PsProjectSection method writeSection.

/**
 * Writes the desired section.
 *
 * @param experiment the experiment name
 * @param projectDetails the details of this project
 * @param waitingHandler the waiting handler
 *
 * @throws IOException exception thrown whenever an error occurred while
 * writing the file
 */
public void writeSection(String experiment, ProjectDetails projectDetails, WaitingHandler waitingHandler) throws IOException {
    if (waitingHandler != null) {
        waitingHandler.setSecondaryProgressCounterIndeterminate(true);
    }
    if (header) {
        if (indexes) {
            writer.writeHeaderText("");
            writer.addSeparator();
        }
        writer.writeHeaderText("Parameter");
        writer.addSeparator();
        writer.writeHeaderText("Value");
        writer.newLine();
    }
    int line = 1;
    for (PsProjectFeature projectFeature : projectFeatures) {
        if (indexes) {
            writer.write(Integer.toString(line));
            writer.addSeparator();
        }
        writer.write(projectFeature.getTitle());
        writer.addSeparator();
        switch(projectFeature) {
            case date:
                writer.write(projectDetails.getCreationDate() + "");
                break;
            case experiment:
                writer.write(experiment);
                break;
            case peptide_shaker:
                writer.write(projectDetails.getPeptideShakerVersion());
                break;
            case identification_algorithms:
                ArrayList<Integer> advocatesIds = projectDetails.getIdentificationAlgorithms();
                Collections.sort(advocatesIds);
                for (int i = 0; i < advocatesIds.size(); i++) {
                    if (i > 0) {
                        if (i == advocatesIds.size() - 1) {
                            writer.write(" and ");
                        } else {
                            writer.write(", ");
                        }
                    }
                    Integer advocateId = advocatesIds.get(i);
                    Advocate advocate = Advocate.getAdvocate(advocateId);
                    writer.write(advocate.getName());
                }
                break;
            case algorithms_versions:
                advocatesIds = projectDetails.getIdentificationAlgorithms();
                HashMap<String, ArrayList<String>> versions = projectDetails.getAlgorithmNameToVersionsMap();
                Collections.sort(advocatesIds);
                for (int i = 0; i < advocatesIds.size(); i++) {
                    if (i > 0) {
                        if (i == advocatesIds.size() - 1) {
                            writer.write(" and ");
                        } else {
                            writer.write(", ");
                        }
                    }
                    Integer advocateId = advocatesIds.get(i);
                    Advocate advocate = Advocate.getAdvocate(advocateId);
                    String advocateName = advocate.getName();
                    writer.write(advocateName + " (");
                    ArrayList<String> algorithmVersions = versions.get(advocateName);
                    if (algorithmVersions == null || algorithmVersions.isEmpty()) {
                        writer.write("unknown version)");
                    } else {
                        if (algorithmVersions.size() == 1) {
                            writer.write("version " + algorithmVersions.get(0) + ")");
                        } else {
                            writer.write("versions ");
                            for (int j = 0; j < algorithmVersions.size(); j++) {
                                if (j > 0) {
                                    if (j == algorithmVersions.size() - 1) {
                                        writer.write(" and ");
                                    } else {
                                        writer.write(", ");
                                    }
                                }
                                writer.write(algorithmVersions.get(j));
                            }
                            writer.write(")");
                        }
                    }
                }
                break;
            default:
                writer.write("Not implemented");
        }
        writer.newLine();
        line++;
    }
}
Also used : ArrayList(java.util.ArrayList) Advocate(com.compomics.util.experiment.identification.Advocate) PsProjectFeature(com.compomics.util.io.export.features.peptideshaker.PsProjectFeature)

Aggregations

Advocate (com.compomics.util.experiment.identification.Advocate)1 PsProjectFeature (com.compomics.util.io.export.features.peptideshaker.PsProjectFeature)1 ArrayList (java.util.ArrayList)1