Examples of PSParameter


Examples of eu.isas.peptideshaker.myparameters.PSParameter

        super(parent, true);
        initComponents();
        setUpGui();

        this.matchKey = peptideMatchKey;
        psParameter = (PSParameter) identification.getPeptideMatchParameter(peptideMatchKey, new PSParameter());
        this.exceptionHandler = exceptionHandler;
        this.identification = identification;
        this.identificationFeaturesGenerator = identificationFeaturesGenerator;
        this.searchParameters = searchParameters;
        this.annotationPreferences = annotationPreferences;
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSParameter

        super(parent, true);
        initComponents();
        setUpGui();

        this.matchKey = psmMatchKey;
        psParameter = (PSParameter) identification.getSpectrumMatchParameter(psmMatchKey, new PSParameter());
        this.exceptionHandler = exceptionHandler;
        this.identification = identification;
        this.identificationFeaturesGenerator = identificationFeaturesGenerator;
        this.searchParameters = searchParameters;
        this.annotationPreferences = annotationPreferences;
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSParameter

                            identification.loadProteinMatchParameters(proteinMatches, psParameter, null);

                            for (String proteinMatchKey : proteinMatches) {

                                identificationFeaturesGenerator.updateNConfidentPeptides(proteinMatchKey);
                                PSParameter proteinPSParameter = (PSParameter) identification.getProteinMatchParameter(proteinMatchKey, psParameter);
                                MatchValidationLevel proteinValidation = proteinPSParameter.getMatchValidationLevel();

                                if (proteinValidation.isValidated()) {

                                    MatchesValidator.updateProteinMatchValidationLevel(identification, identificationFeaturesGenerator, searchParameters, annotationPreferences, proteinMap, proteinMatchKey);
                                    proteinPSParameter = (PSParameter) identification.getProteinMatchParameter(proteinMatchKey, proteinPSParameter);
                                    MatchValidationLevel newValidation = proteinPSParameter.getMatchValidationLevel();

                                    if (newValidation == MatchValidationLevel.confident && proteinValidation == MatchValidationLevel.doubtful) {
                                        metrics.setnConfidentProteins(metrics.getnConfidentProteins() + 1);
                                    } else if (newValidation == MatchValidationLevel.doubtful && proteinValidation == MatchValidationLevel.confident) {
                                        metrics.setnConfidentProteins(metrics.getnConfidentProteins() - 1);
                                    }
                                }
                            }
                        }
                    }
                } else if (type == Type.PSM) {

                    PSMaps pSMaps = new PSMaps();
                    pSMaps = (PSMaps) identification.getUrParam(pSMaps);
                    PeptideSpecificMap peptideMap = pSMaps.getPeptideSpecificMap();
                    ProteinMap proteinMap = pSMaps.getProteinMap();
                    SpectrumMatch spectrumMatch = identification.getSpectrumMatch(matchKey);
                    if (spectrumMatch.getBestPeptideAssumption() != null) {
                        Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
                        String peptideKey = peptide.getMatchingKey(sequenceMatchingPreferences);
                        identificationFeaturesGenerator.updateNConfidentSpectraForPeptide(peptideKey);
                        PSParameter peptidePSParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter);

                        if (peptidePSParameter.getMatchValidationLevel().isValidated()) {

                            MatchesValidator.updatePeptideMatchValidationLevel(identification, identificationFeaturesGenerator, searchParameters, peptideMap, peptideKey);
                            identification.updateSpectrumMatchParameter(matchKey, psParameter);
                            PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);

                            for (String accession : peptideMatch.getTheoreticPeptide().getParentProteins(sequenceMatchingPreferences)) {

                                ArrayList<String> proteinMatches = identification.getProteinMap().get(accession);

                                if (proteinMatches != null) {

                                    identification.loadProteinMatchParameters(proteinMatches, psParameter, null);

                                    for (String proteinMatchKey : proteinMatches) {

                                        identificationFeaturesGenerator.updateNConfidentPeptides(proteinMatchKey);
                                        identificationFeaturesGenerator.updateNConfidentSpectra(proteinMatchKey);
                                        PSParameter proteinPSParameter = (PSParameter) identification.getProteinMatchParameter(proteinMatchKey, psParameter);
                                        MatchValidationLevel proteinValidation = proteinPSParameter.getMatchValidationLevel();

                                        if (proteinValidation.isValidated()) {

                                            MatchesValidator.updateProteinMatchValidationLevel(identification, identificationFeaturesGenerator,
                                                    searchParameters, annotationPreferences, proteinMap, proteinMatchKey);
                                            proteinPSParameter = (PSParameter) identification.getProteinMatchParameter(proteinMatchKey, proteinPSParameter);
                                            MatchValidationLevel newValidation = proteinPSParameter.getMatchValidationLevel();

                                            if (newValidation == MatchValidationLevel.confident && proteinValidation == MatchValidationLevel.doubtful) {
                                                metrics.setnConfidentProteins(metrics.getnConfidentProteins() + 1);
                                            } else if (newValidation == MatchValidationLevel.doubtful && proteinValidation == MatchValidationLevel.confident) {
                                                metrics.setnConfidentProteins(metrics.getnConfidentProteins() - 1);
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSParameter

                }
                psmMap.get(fileName).add(key);
            }
        }

        PSParameter psParameter = new PSParameter();
        SpectrumMatch spectrumMatch = null;
        int line = 1;

        int totalSize = 0;

        for (String spectrumFile : psmMap.keySet()) {
            totalSize += psmMap.get(spectrumFile).size();
        }

        // get the spectrum keys
        ArrayList<String> spectrumKeys = new ArrayList<String>();

        for (String spectrumFile : psmMap.keySet()) {
            for (String spectrumKey : psmMap.get(spectrumFile)) {
                if (!spectrumKeys.contains(spectrumKey)) {
                    spectrumKeys.add(spectrumKey);
                }
            }
        }

        if (waitingHandler != null) {
            waitingHandler.setWaitingText("Loading Spectra. Please Wait...");
            waitingHandler.resetSecondaryProgressCounter();
        }
        identification.loadSpectrumMatches(spectrumKeys, waitingHandler);

        if (waitingHandler != null) {
            waitingHandler.setWaitingText("Loading Spectrum Details. Please Wait...");
            waitingHandler.resetSecondaryProgressCounter();
        }
        identification.loadSpectrumMatchParameters(spectrumKeys, psParameter, waitingHandler);

        if (waitingHandler != null) {
            waitingHandler.setWaitingText("Exporting. Please Wait...");
            waitingHandler.resetSecondaryProgressCounter();
            waitingHandler.setMaxSecondaryProgressCounter(totalSize);
        }

        for (String spectrumFile : psmMap.keySet()) {

            for (String spectrumKey : psmMap.get(spectrumFile)) {

                if (waitingHandler != null) {
                    if (waitingHandler.isRunCanceled()) {
                        return;
                    }
                    waitingHandler.increaseSecondaryProgressCounter();
                }

                psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);

                if (!validatedOnly || psParameter.getMatchValidationLevel().isValidated()) {

                    spectrumMatch = identification.getSpectrumMatch(spectrumKey);

                    PeptideAssumption peptideAssumption = spectrumMatch.getBestPeptideAssumption();
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSParameter

        if (keys == null) {
            keys = identification.getProteinIdentification();
        }
        int line = 1;
        PSParameter psParameter = new PSParameter();
        ProteinMatch proteinMatch = null;

        if (peptideSection != null) {
            if (waitingHandler != null) {
                waitingHandler.setWaitingText("Loading Peptides. Please Wait...");
                waitingHandler.resetSecondaryProgressCounter();
            }
            identification.loadPeptideMatches(waitingHandler);
            if (waitingHandler != null) {
                waitingHandler.setWaitingText("Loading Peptide Details. Please Wait...");
                waitingHandler.resetSecondaryProgressCounter();
            }
            identification.loadPeptideMatchParameters(psParameter, waitingHandler);
        }

        if (waitingHandler != null) {
            waitingHandler.setWaitingText("Loading Proteins. Please Wait...");
            waitingHandler.resetSecondaryProgressCounter();
        }
        identification.loadProteinMatches(keys, waitingHandler);
        if (waitingHandler != null) {
            waitingHandler.setWaitingText("Loading Protein Details. Please Wait...");
            waitingHandler.resetSecondaryProgressCounter();
        }
        identification.loadProteinMatchParameters(keys, psParameter, waitingHandler);

        if (waitingHandler != null) {
            waitingHandler.setWaitingText("Exporting. Please Wait...");
            waitingHandler.resetSecondaryProgressCounter();
            waitingHandler.setMaxSecondaryProgressCounter(keys.size());
        }

        for (String proteinKey : keys) {

            if (waitingHandler != null) {
                if (waitingHandler.isRunCanceled()) {
                    return;
                }
                waitingHandler.increaseSecondaryProgressCounter();
            }

            if (decoys || !ProteinMatch.isDecoy(proteinKey)) {

                psParameter = (PSParameter) identification.getProteinMatchParameter(proteinKey, psParameter);

                if (!validatedOnly || psParameter.getMatchValidationLevel().isValidated()) {

                    boolean first = true;

                    if (indexes) {
                        writer.write(line + "");
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSParameter

     * @throws InterruptedException
     */
    public void exportSpectra(File destinationFolder, WaitingHandler waitingHandler, ExportType exportType, SequenceMatchingPreferences sequenceMatchingPreferences)
            throws IOException, MzMLUnmarshallerException, SQLException, ClassNotFoundException, InterruptedException {

        PSParameter psParameter = new PSParameter();

        if (exportType == ExportType.non_validated_peptides
                || exportType == ExportType.validated_psms_peptides
                || exportType == ExportType.validated_psms_peptides_proteins) {
            if (waitingHandler != null) {
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSParameter

     * @throws SQLException
     * @throws IOException
     * @throws ClassNotFoundException
     */
    private boolean shallExport(String spectrumKey, ExportType exportType, SequenceMatchingPreferences sequenceMatchingPreferences) throws SQLException, IOException, ClassNotFoundException, InterruptedException {
        PSParameter psParameter = new PSParameter();
        switch (exportType) {
            case non_validated_psms:
            case validated_psms:
                if (identification.matchExists(spectrumKey)) {
                    psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
                    if (psParameter.getMatchValidationLevel().isValidated()) {
                        SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
                        if (spectrumMatch.getBestPeptideAssumption() != null) {
                            boolean decoy = false;
                            for (String accession : spectrumMatch.getBestPeptideAssumption().getPeptide().getParentProteins(sequenceMatchingPreferences)) {
                                if (sequenceFactory.isDecoyAccession(accession)) {
                                    decoy = true;
                                    break;
                                }
                            }
                            return !decoy && exportType == ExportType.validated_psms;
                        } else {
                            return false;
                        }
                    }
                }
                return exportType == ExportType.non_validated_psms;
            case non_validated_peptides:
            case validated_psms_peptides:
                if (identification.matchExists(spectrumKey)) {
                    SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
                    if (spectrumMatch.getBestPeptideAssumption() != null) {
                        Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
                        boolean decoy = false;
                        for (String accession : peptide.getParentProteins(sequenceMatchingPreferences)) {
                            if (sequenceFactory.isDecoyAccession(accession)) {
                                decoy = true;
                                break;
                            }
                        }
                        if (!decoy) {
                            String peptideKey = peptide.getMatchingKey(sequenceMatchingPreferences);
                            psParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter);
                            if (exportType == ExportType.non_validated_peptides || ((PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter)).getMatchValidationLevel().isValidated()) {
                                if (psParameter.getMatchValidationLevel().isValidated()) {
                                    return exportType == ExportType.validated_psms_peptides;
                                }
                            }
                        }
                    }
                    return exportType == ExportType.non_validated_peptides;
                } else {
                    return false;
                }
            case non_validated_proteins:
            case validated_psms_peptides_proteins:
                if (identification.matchExists(spectrumKey)) {
                    SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
                    if (spectrumMatch.getBestPeptideAssumption() != null) {
                        Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
                        boolean decoy = false;
                        for (String accession : peptide.getParentProteins(sequenceMatchingPreferences)) {
                            if (sequenceFactory.isDecoyAccession(accession)) {
                                decoy = true;
                                break;
                            }
                        }
                        if (!decoy) {
                            String peptideKey = peptide.getMatchingKey(sequenceMatchingPreferences);
                            if (exportType == ExportType.non_validated_proteins
                                    || ((PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter)).getMatchValidationLevel().isValidated()
                                    && ((PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter)).getMatchValidationLevel().isValidated()) {
                                ArrayList<String> proteins = peptide.getParentProteins(sequenceMatchingPreferences);
                                for (String accession : proteins) {
                                    ArrayList<String> accessions = identification.getProteinMap().get(accession);
                                    if (accessions != null) {
                                        for (String proteinKey : accessions) {
                                            psParameter = (PSParameter) identification.getProteinMatchParameter(proteinKey, psParameter);
                                            if (psParameter.getMatchValidationLevel().isValidated()) {
                                                return exportType == ExportType.validated_psms_peptides_proteins;
                                            }
                                        }
                                    }
                                }
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSParameter

                                writer.write("Starred" + SEPARATOR);
                            }
                            writer.write(System.getProperty("line.separator"));
                        }

                        PSParameter proteinPSParameter = new PSParameter();
                        PSParameter peptidePSParameter = new PSParameter();
                        int proteinCounter = 0;

                        progressDialog.setTitle("Loading Protein Matches. Please Wait...");
                        identification.loadProteinMatches(progressDialog);
                        progressDialog.setTitle("Loading Protein Details. Please Wait...");
                        identification.loadProteinMatchParameters(proteinPSParameter, progressDialog);

                        progressDialog.setPrimaryProgressCounterIndeterminate(false);
                        progressDialog.setMaxPrimaryProgressCounter(proteinKeys.size());
                        progressDialog.setValue(0);
                        progressDialog.setTitle("Copying to File. Please Wait...");

                        // store the maximal protein set of validated proteins
                        ArrayList<String> maximalProteinSet = new ArrayList<String>();

                        for (String proteinKey : proteinKeys) { // @TODO: replace by batch selection!!!

                            if (progressDialog.isRunCanceled()) {
                                break;
                            }

                            proteinPSParameter = (PSParameter) identification.getProteinMatchParameter(proteinKey, proteinPSParameter);

                            if (!ProteinMatch.isDecoy(proteinKey) || !onlyValidated) {
                                if ((onlyValidated && proteinPSParameter.getMatchValidationLevel().isValidated()) || !onlyValidated) {
                                    if ((!includeHidden && !proteinPSParameter.isHidden()) || includeHidden) {
                                        if ((onlyStarred && proteinPSParameter.isStarred()) || !onlyStarred) {
                                            if (indexes) {
                                                writer.write(++proteinCounter + SEPARATOR);
                                            }

                                            ProteinMatch proteinMatch = identification.getProteinMatch(proteinKey);
                                            if (mainAccession) {
                                                writer.write(proteinMatch.getMainMatch() + SEPARATOR);
                                            }
                                            if (createMaximalProteinSet && !maximalProteinSet.contains(proteinMatch.getMainMatch())) {
                                                maximalProteinSet.add(proteinMatch.getMainMatch());
                                            }
                                            if (createMaximalProteinSet || otherAccessions) {
                                                boolean first = true;

                                                // sort so that the protein accessions always come in the same order
                                                ArrayList<String> allProteins = proteinMatch.getTheoreticProteinsAccessions();
                                                Collections.sort(allProteins);
                                                StringBuilder completeProteinGroup = new StringBuilder();

                                                for (String otherProtein : allProteins) {
                                                    if (otherAccessions && !otherProtein.equalsIgnoreCase(proteinMatch.getMainMatch())) {
                                                        if (first) {
                                                            first = false;
                                                        } else {
                                                            writer.write(", ");
                                                        }
                                                        writer.write(otherProtein);
                                                    }
                                                    if (createMaximalProteinSet && !maximalProteinSet.contains(otherProtein)) {
                                                        maximalProteinSet.add(otherProtein);
                                                    }

                                                    if (completeProteinGroup.length() > 0) {
                                                        completeProteinGroup.append(", ");
                                                    }

                                                    completeProteinGroup.append(otherProtein);
                                                }

                                                if (otherAccessions) {
                                                    writer.write(SEPARATOR);
                                                    writer.write(completeProteinGroup.toString());
                                                    writer.write(SEPARATOR);
                                                }
                                            }
                                            if (piDetails) {
                                                writer.write(proteinPSParameter.getProteinInferenceClassAsString() + SEPARATOR);
                                            }
                                            if (description) {
                                                try {
                                                    writer.write(sequenceFactory.getHeader(proteinMatch.getMainMatch()).getSimpleProteinDescription() + SEPARATOR);
                                                } catch (Exception e) {
                                                    writer.write("error: " + e.getLocalizedMessage() + SEPARATOR);
                                                }
                                            }

                                            // gene name and chromosome number
                                            String tempGeneName = null;
                                            if (geneName || chromosomeNumber) {
                                                tempGeneName = sequenceFactory.getHeader(proteinMatch.getMainMatch()).getGeneName();
                                            }
                                            if (geneName) {
                                                if (tempGeneName != null && !identification.getProteinMatch(proteinKey).isDecoy()) {
                                                    writer.write(tempGeneName);
                                                }
                                                writer.write(SEPARATOR);
                                            }
                                            if (chromosomeNumber) {
                                                String chromosomeNumber = geneFactory.getChromosomeForGeneName(tempGeneName);
                                                if (chromosomeNumber != null && !identification.getProteinMatch(proteinKey).isDecoy()) {
                                                    writer.write(chromosomeNumber);
                                                }
                                                writer.write(SEPARATOR);
                                            }

                                            if (sequenceCoverage) {
                                                try {
                                                    HashMap<Integer, Double> sequenceCoverage;
                                                    try {
                                                        sequenceCoverage = peptideShakerGUI.getIdentificationFeaturesGenerator().getSequenceCoverage(proteinKey);
                                                    } catch (Exception e) {
                                                        peptideShakerGUI.catchException(e);
                                                        sequenceCoverage = new HashMap<Integer, Double>();
                                                    }
                                                    Double sequenceCoverageConfident = 100 * sequenceCoverage.get(MatchValidationLevel.confident.getIndex());
                                                    Double sequenceCoverageDoubtful = 100 * sequenceCoverage.get(MatchValidationLevel.doubtful.getIndex());
                                                    Double validatedCoverage = sequenceCoverageConfident + sequenceCoverageDoubtful;
                                                    writer.write(validatedCoverage + SEPARATOR);
                                                    writer.write(peptideShakerGUI.getIdentificationFeaturesGenerator().getObservableCoverage(proteinKey) * 100 + SEPARATOR);
                                                } catch (Exception e) {
                                                    writer.write("error: " + e.getLocalizedMessage() + SEPARATOR);
                                                }
                                            }
                                            if (showNonEnzymaticPeptidesColumn) {

                                                ArrayList<String> peptideKeys = proteinMatch.getPeptideMatchesKeys();
                                                Protein currentProtein = sequenceFactory.getProtein(proteinMatch.getMainMatch());
                                                boolean allPeptidesEnzymatic = true;

                                                identification.loadPeptideMatches(peptideKeys, null);
                                                identification.loadPeptideMatchParameters(peptideKeys, peptidePSParameter, null);

                                                // see if we have non-tryptic peptides
                                                for (String peptideKey : peptideKeys) {

                                                    String peptideSequence = identification.getPeptideMatch(peptideKey).getTheoreticPeptide().getSequence();
                                                    peptidePSParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, peptidePSParameter);

                                                    if (peptidePSParameter.getMatchValidationLevel().isValidated()) {

                                                        boolean isEnzymatic = currentProtein.isEnzymaticPeptide(peptideSequence,
                                                                peptideShakerGUI.getSearchParameters().getEnzyme(),
                                                                peptideShakerGUI.getSequenceMatchingPreferences());

View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSParameter

                            }

                            writer.write(System.getProperty("line.separator"));
                        }

                        PSParameter peptidePSParameter = new PSParameter();
                        PSParameter secondaryPSParameter = new PSParameter();
                        int peptideCounter = 0;
                        HashMap<String, HashMap<Integer, String[]>> surroundingAAs = new HashMap<String, HashMap<Integer, String[]>>();
                        ProteinMatch proteinMatch = null;
                        ModificationProfile ptmProfile = peptideShakerGUI.getSearchParameters().getModificationProfile();

                        // @TODO: try to batch load the spectra? as this would speed up the export...
                        progressDialog.setTitle("Loading Peptide Matches. Please Wait...");
                        identification.loadPeptideMatches(progressDialog);
                        progressDialog.setTitle("Loading Peptide Details. Please Wait...");
                        identification.loadPeptideMatchParameters(peptidePSParameter, progressDialog);

                        progressDialog.setPrimaryProgressCounterIndeterminate(false);
                        progressDialog.setMaxPrimaryProgressCounter(peptideKeys.size());
                        progressDialog.setValue(0);
                        progressDialog.setTitle("Copying to File. Please Wait...");

                        for (String peptideKey : peptideKeys) {

                            if (progressDialog.isRunCanceled()) {
                                break;
                            }

                            boolean shared = false;
                            PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);
                            peptidePSParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, peptidePSParameter);

                            if (!peptideMatch.getTheoreticPeptide().isDecoy(peptideShakerGUI.getSequenceMatchingPreferences()) || !onlyValidated) {
                                if ((onlyValidated && peptidePSParameter.getMatchValidationLevel().isValidated()) || !onlyValidated) {
                                    if ((!includeHidden && !peptidePSParameter.isHidden()) || includeHidden) {
                                        if ((onlyStarred && peptidePSParameter.isStarred()) || !onlyStarred) {

                                            Peptide peptide = peptideMatch.getTheoreticPeptide();
                                            ArrayList<String> possibleProteins = new ArrayList<String>();
                                            ArrayList<String> orderedProteinsKeys = new ArrayList<String>(); // @TODO: could be merged with one of the other maps perhaps?

                                            if (accession || proteinDescription || surroundings || location || uniqueOnly) {
                                                if (proteinKey == null) {
                                                    for (String parentProtein : peptide.getParentProteins(peptideShakerGUI.getSequenceMatchingPreferences())) {
                                                        ArrayList<String> parentProteins = identification.getProteinMap().get(parentProtein);
                                                        if (parentProteins != null) {
                                                            for (String proteinKey : parentProteins) {
                                                                if (!possibleProteins.contains(proteinKey)) {
                                                                    try {
                                                                        proteinMatch = identification.getProteinMatch(proteinKey);
                                                                        if (proteinMatch.getPeptideMatchesKeys().contains(peptideKey)) {
                                                                            possibleProteins.add(proteinKey);
                                                                        }
                                                                    } catch (Exception e) {
                                                                        // protein deleted due to protein inference issue and not deleted from the map in versions earlier than 0.14.6
                                                                        System.out.println("Non-existing protein key in protein map: " + proteinKey);
                                                                        e.printStackTrace();
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    shared = possibleProteins.size() > 1;
                                                    proteinMatch = identification.getProteinMatch(possibleProteins.get(0));
                                                } else {
                                                    proteinMatch = identification.getProteinMatch(proteinKey);
                                                }
                                            }

                                            if (shared && uniqueOnly) {
                                                // these will be ignored as the user requested unique only
                                            } else {

                                                if (indexes) {
                                                    writer.write(++peptideCounter + SEPARATOR);
                                                }

                                                if (accession || proteinDescription) {
                                                    String mainMatch, secondaryProteins = "", peptideProteins = "";
                                                    String mainMatchDescription, secondaryProteinsDescriptions = "", peptideProteinDescriptions = "";
                                                    ArrayList<String> accessions = new ArrayList<String>();

                                                    mainMatch = proteinMatch.getMainMatch();
                                                    mainMatchDescription = sequenceFactory.getHeader(mainMatch).getSimpleProteinDescription();
                                                    boolean first = true;

                                                    if (!shared) {
                                                        orderedProteinsKeys.add(mainMatch);
                                                    }

                                                    accessions.addAll(proteinMatch.getTheoreticProteinsAccessions());
                                                    Collections.sort(accessions);
                                                    for (String key : accessions) {
                                                        if (!key.equals(mainMatch)) {
                                                            if (first) {
                                                                first = false;
                                                            } else {
                                                                secondaryProteins += "; ";
                                                                secondaryProteinsDescriptions += "; ";
                                                            }
                                                            secondaryProteins += key;
                                                            secondaryProteinsDescriptions += sequenceFactory.getHeader(key).getSimpleProteinDescription();
                                                            orderedProteinsKeys.add(key);
                                                        }
                                                    }

                                                    if (shared) {
                                                        mainMatch = "shared peptide";
                                                        mainMatchDescription = "shared peptide";
                                                    }

                                                    first = true;
                                                    ArrayList<String> peptideAccessions = new ArrayList<String>(peptide.getParentProteins(peptideShakerGUI.getSequenceMatchingPreferences()));
                                                    Collections.sort(peptideAccessions);
                                                    for (String key : peptideAccessions) {
                                                        if (shared || !accessions.contains(key)) {
                                                            if (first) {
                                                                first = false;
                                                            } else {
                                                                peptideProteins += "; ";
                                                                peptideProteinDescriptions += "; ";
                                                            }
                                                            peptideProteins += key;
                                                            peptideProteinDescriptions += sequenceFactory.getHeader(key).getSimpleProteinDescription();
                                                            orderedProteinsKeys.add(key);
                                                        }
                                                    }

                                                    if (accession) {
                                                        writer.write(mainMatch + SEPARATOR);
                                                        writer.write(secondaryProteins + SEPARATOR);
                                                        writer.write(peptideProteins + SEPARATOR);
                                                    }
                                                    if (proteinDescription) {
                                                        writer.write(mainMatchDescription + SEPARATOR);
                                                        writer.write(secondaryProteinsDescriptions + SEPARATOR);
                                                        writer.write(peptideProteinDescriptions + SEPARATOR);
                                                    }
                                                }

                                                if (proteinInferenceType) {
                                                    writer.write(peptidePSParameter.getProteinInferenceClassAsString() + SEPARATOR);
                                                }

                                                if (location || surroundings) {
                                                    for (String proteinAccession : orderedProteinsKeys) {
                                                        surroundingAAs.put(proteinAccession,
                                                                sequenceFactory.getProtein(proteinAccession).getSurroundingAA(peptide.getSequence(),
                                                                        peptideShakerGUI.getDisplayPreferences().getnAASurroundingPeptides(),
                                                                        peptideShakerGUI.getSequenceMatchingPreferences()));
                                                    }
                                                }

                                                if (surroundings) {

                                                    String subSequence = "";

                                                    for (String proteinAccession : orderedProteinsKeys) {
                                                        ArrayList<Integer> starts = new ArrayList<Integer>(surroundingAAs.get(proteinAccession).keySet());
                                                        Collections.sort(starts);
                                                        boolean first = true;
                                                        for (int start : starts) {
                                                            if (first) {
                                                                first = false;
                                                            } else {
                                                                subSequence += ", ";
                                                            }
                                                            subSequence += surroundingAAs.get(proteinAccession).get(start)[0];
                                                        }

                                                        subSequence += "; ";
                                                    }

                                                    subSequence = subSequence.substring(0, subSequence.length() - 1);

                                                    writer.write(subSequence + SEPARATOR);
                                                }

                                                if (sequence) {
                                                    writer.write(peptide.getSequence() + SEPARATOR);
                                                    writer.write(peptide.getTaggedModifiedSequence(peptideShakerGUI.getSearchParameters().getModificationProfile(),
                                                            false, false, true) + SEPARATOR);
                                                }

                                                if (surroundings) {

                                                    String subSequence = "";

                                                    for (String proteinAccession : orderedProteinsKeys) {
                                                        ArrayList<Integer> starts = new ArrayList<Integer>(surroundingAAs.get(proteinAccession).keySet());
                                                        Collections.sort(starts);
                                                        boolean first = true;
                                                        for (int start : starts) {
                                                            if (first) {
                                                                first = false;
                                                            } else {
                                                                subSequence += ", ";
                                                            }
                                                            subSequence += surroundingAAs.get(proteinAccession).get(start)[1];
                                                        }
                                                        subSequence += "; ";
                                                    }

                                                    subSequence = subSequence.substring(0, subSequence.length() - 1);

                                                    writer.write(subSequence + SEPARATOR);
                                                }

                                                if (enzymatic) {
                                                    boolean isEnzymatic = sequenceFactory.getProtein(proteinMatch.getMainMatch()).isEnzymaticPeptide(peptide.getSequence(),
                                                            peptideShakerGUI.getSearchParameters().getEnzyme(), peptideShakerGUI.getSequenceMatchingPreferences());

                                                    writer.write(isEnzymatic + SEPARATOR);
                                                }

                                                if (location) {
                                                    String start = "";
                                                    String end = "";
                                                    for (String proteinAccession : orderedProteinsKeys) {
                                                        int endAA;
                                                        String sequence = peptide.getSequence();
                                                        ArrayList<Integer> starts = new ArrayList<Integer>(surroundingAAs.get(proteinAccession).keySet());
                                                        Collections.sort(starts);
                                                        boolean first = true;
                                                        for (int startAa : starts) {
                                                            if (first) {
                                                                first = false;
                                                            } else {
                                                                start += ", ";
                                                                end += ", ";
                                                            }
                                                            start += startAa;
                                                            endAA = startAa + sequence.length();
                                                            end += endAA;
                                                        }

                                                        start += "; ";
                                                        end += "; ";
                                                    }

                                                    start = start.substring(0, start.length() - 2);
                                                    end = end.substring(0, end.length() - 2);

                                                    writer.write(start + SEPARATOR + end + SEPARATOR);
                                                }
                                                if (modifications) {
                                                    writer.write(getPeptideModificationsAsString(peptide, false));
                                                    writer.write(SEPARATOR);
                                                }
                                                if (modifications) {
                                                    writer.write(getPeptideModificationsAsString(peptide, true));
                                                    writer.write(SEPARATOR);
                                                }
                                                if (ptmLocations) {
                                                    writer.write(getPeptideModificationLocations(peptide, peptideMatch, ptmProfile));
                                                    writer.write(SEPARATOR);
                                                }
                                                if (charges) {
                                                    writer.write(getPeptidePrecursorChargesAsString(peptideMatch));
                                                    writer.write(SEPARATOR);
                                                }
                                                if (nSpectra) {
                                                    int cpt = 0;

                                                    // @TODO: replace with: peptideShakerGUI.getIdentificationFeaturesGenerator().getNValidatedSpectraForPeptide(peptideKey);?
                                                    identification.loadSpectrumMatchParameters(peptideMatch.getSpectrumMatches(), secondaryPSParameter, null);
                                                    for (String spectrumKey : peptideMatch.getSpectrumMatches()) {
                                                        secondaryPSParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, secondaryPSParameter);
                                                        if (secondaryPSParameter.getMatchValidationLevel().isValidated()) {
                                                            cpt++;
                                                        }
                                                    }
                                                    writer.write(cpt + SEPARATOR);
                                                }
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSParameter

                            }

                            writer.write(System.getProperty("line.separator"));
                        }

                        PSParameter psParameter = new PSParameter();
                        int psmCounter = 0;

                        HashMap<String, ArrayList<String>> spectrumKeys = new HashMap<String, ArrayList<String>>();
                        if (psmKeys == null) {
                            spectrumKeys = identification.getSpectrumIdentificationMap();
                        } else {
                            for (String spectrumKey : psmKeys) {
                                String spectrumFile = Spectrum.getSpectrumFile(spectrumKey);
                                if (!spectrumKeys.containsKey(spectrumFile)) {
                                    spectrumKeys.put(spectrumFile, new ArrayList<String>());
                                }
                                spectrumKeys.get(spectrumFile).add(spectrumKey);
                            }
                        }

                        int fileCounter = 0;

                        for (String spectrumFile : spectrumKeys.keySet()) {

                            if (psmKeys == null) {
                                progressDialog.setTitle("Copying Spectrum Matches to File. Please Wait... (" + ++fileCounter + "/" + spectrumKeys.size() + ")");
                                identification.loadSpectrumMatches(spectrumFile, progressDialog);
                                progressDialog.setTitle("Copying Spectrum Matches Details to File. Please Wait... (" + fileCounter + "/" + spectrumKeys.size() + ")");
                                identification.loadSpectrumMatchParameters(spectrumFile, psParameter, progressDialog);
                            } else {
                                progressDialog.setTitle("Copying Spectrum Matches to File. Please Wait... (" + ++fileCounter + "/" + spectrumKeys.size() + ")");
                                identification.loadSpectrumMatches(spectrumKeys.get(spectrumFile), progressDialog);
                                progressDialog.setTitle("Copying Spectrum Matches Details to File. Please Wait... (" + fileCounter + "/" + spectrumKeys.size() + ")");
                                identification.loadSpectrumMatchParameters(spectrumKeys.get(spectrumFile), psParameter, progressDialog);
                            }

                            progressDialog.setMaxPrimaryProgressCounter(spectrumKeys.get(spectrumFile).size());
                            progressDialog.setValue(0);
                            for (String psmKey : spectrumKeys.get(spectrumFile)) {

                                if (progressDialog.isRunCanceled()) {
                                    break;
                                }

                                SpectrumMatch spectrumMatch = identification.getSpectrumMatch(psmKey);
                                psParameter = (PSParameter) identification.getSpectrumMatchParameter(psmKey, psParameter);
                                PeptideAssumption bestAssumption = spectrumMatch.getBestPeptideAssumption();

                                if (!bestAssumption.getPeptide().isDecoy(peptideShakerGUI.getSequenceMatchingPreferences()) || !onlyValidated) {
                                    if ((onlyValidated && psParameter.getMatchValidationLevel().isValidated()) || !onlyValidated) {
                                        if ((!includeHidden && !psParameter.isHidden()) || includeHidden) {
                                            if ((onlyStarred && psParameter.isStarred()) || !onlyStarred) {

                                                if (indexes) {
                                                    writer.write(++psmCounter + SEPARATOR);
                                                }

                                                if (accessions || proteinDescription) {

                                                    String proteinAccessions = "";
                                                    String proteinDescriptions = "";

                                                    boolean first = true;
                                                    for (String protein : bestAssumption.getPeptide().getParentProteins(peptideShakerGUI.getSequenceMatchingPreferences())) {
                                                        if (first) {
                                                            first = false;
                                                        } else {
                                                            if (accessions) {
                                                                proteinAccessions += ", ";
                                                            }
                                                            if (proteinDescription) {
                                                                proteinDescriptions += "; ";
                                                            }
                                                        }
                                                        if (accessions) {
                                                            proteinAccessions += protein;
                                                        }
                                                        if (proteinDescription) {
                                                            proteinDescriptions += sequenceFactory.getHeader(protein).getSimpleProteinDescription();
                                                        }
                                                    }
                                                    if (accessions) {
                                                        writer.write(proteinAccessions + SEPARATOR);
                                                    }
                                                    if (proteinDescription) {
                                                        writer.write(proteinDescriptions + SEPARATOR);
                                                    }
                                                }
                                                if (sequence) {
                                                    writer.write(bestAssumption.getPeptide().getSequence() + SEPARATOR);
                                                }
                                                if (modification) {
                                                    HashMap<String, ArrayList<Integer>> modMap = new HashMap<String, ArrayList<Integer>>();
                                                    for (ModificationMatch modificationMatch : bestAssumption.getPeptide().getModificationMatches()) {
                                                        if (modificationMatch.isVariable()) {
                                                            if (!modMap.containsKey(modificationMatch.getTheoreticPtm())) {
                                                                modMap.put(modificationMatch.getTheoreticPtm(), new ArrayList<Integer>());
                                                            }
                                                            modMap.get(modificationMatch.getTheoreticPtm()).add(modificationMatch.getModificationSite());
                                                        }
                                                    }
                                                    boolean first = true, first2;
                                                    ArrayList<String> mods = new ArrayList<String>(modMap.keySet());
                                                    Collections.sort(mods);
                                                    for (String mod : mods) {
                                                        if (first) {
                                                            first = false;
                                                        } else {
                                                            writer.write(", ");
                                                        }
                                                        first2 = true;
                                                        writer.write(mod + "(");
                                                        for (int aa : modMap.get(mod)) {
                                                            if (first2) {
                                                                first2 = false;
                                                            } else {
                                                                writer.write(", ");
                                                            }
                                                            writer.write(aa + "");
                                                        }
                                                        writer.write(")");
                                                    }
                                                    writer.write(SEPARATOR);
                                                }
                                                if (location) {
                                                    ArrayList<String> modList = new ArrayList<String>();
                                                    for (ModificationMatch modificationMatch : bestAssumption.getPeptide().getModificationMatches()) {
                                                        if (modificationMatch.isVariable()) {
                                                            PTM refPtm = ptmFactory.getPTM(modificationMatch.getTheoreticPtm());
                                                            for (String equivalentPtm : ptmProfile.getSimilarNotFixedModifications(refPtm.getMass())) {
                                                                if (!modList.contains(equivalentPtm)) {
                                                                    modList.add(equivalentPtm);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    Collections.sort(modList);
                                                    PSPtmScores ptmScores = new PSPtmScores();
                                                    boolean first = true;
                                                    for (String mod : modList) {
                                                        if (spectrumMatch.getUrParam(ptmScores) != null) {
                                                            if (first) {
                                                                first = false;
                                                            } else {
                                                                writer.write(", ");
                                                            }
                                                            ptmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());
                                                            writer.write(mod + " (");
                                                            if (ptmScores != null && ptmScores.getPtmScoring(mod) != null) {
                                                                PtmScoring ptmScoring = ptmScores.getPtmScoring(mod);
                                                                boolean firstSite = true;
                                                                for (int site : ptmScoring.getOrderedPtmLocations()) {
                                                                    if (firstSite) {
                                                                        firstSite = false;
                                                                    } else {
                                                                        writer.write(", ");
                                                                    }
                                                                    int ptmConfidence = ptmScoring.getLocalizationConfidence(site);
                                                                    if (ptmConfidence == PtmScoring.NOT_FOUND) {
                                                                        writer.write(site + ": Not Scored"); // Well this should not happen
                                                                    } else if (ptmConfidence == PtmScoring.RANDOM) {
                                                                        writer.write(site + ": Random");
                                                                    } else if (ptmConfidence == PtmScoring.DOUBTFUL) {
                                                                        writer.write(site + ": Doubtfull");
                                                                    } else if (ptmConfidence == PtmScoring.CONFIDENT) {
                                                                        writer.write(site + ": Confident");
                                                                    } else if (ptmConfidence == PtmScoring.VERY_CONFIDENT) {
                                                                        writer.write(site + ": Very Confident");
                                                                    }
                                                                }
                                                            } else {
                                                                writer.write("Not Scored");
                                                            }
                                                            writer.write(")");
                                                        }
                                                    }
                                                    writer.write(SEPARATOR);
                                                    if (ptmScoringPreferences.isProbabilitsticScoreCalculation()) {
                                                        first = true;
                                                        for (String mod : modList) {
                                                            if (spectrumMatch.getUrParam(ptmScores) != null) {
                                                                if (first) {
                                                                    first = false;
                                                                } else {
                                                                    writer.write(", ");
                                                                }
                                                                ptmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());
                                                                writer.write(mod + " (");
                                                                if (ptmScores != null && ptmScores.getPtmScoring(mod) != null) {
                                                                    PtmScoring ptmScoring = ptmScores.getPtmScoring(mod);
                                                                    boolean firstSite = true;
                                                                    ArrayList<Integer> sites = new ArrayList<Integer>(ptmScoring.getProbabilisticSites());
                                                                    Collections.sort(sites);
                                                                    for (int site : sites) {
                                                                        if (firstSite) {
                                                                            firstSite = false;
                                                                        } else {
                                                                            writer.write(", ");
                                                                        }
                                                                        writer.write(site + ": " + ptmScoring.getProbabilisticScore(site));
                                                                    }
                                                                } else {
                                                                    writer.write("Not Scored");
                                                                }
                                                                writer.write(")");
                                                            }
                                                        }
                                                    }
                                                    writer.write(SEPARATOR);
                                                    first = true;
                                                    for (String mod : modList) {
                                                        if (spectrumMatch.getUrParam(ptmScores) != null) {
                                                            if (first) {
                                                                first = false;
                                                            } else {
                                                                writer.write(", ");
                                                            }
                                                            ptmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());
                                                            writer.write(mod + " (");
                                                            if (ptmScores != null && ptmScores.getPtmScoring(mod) != null) {
                                                                PtmScoring ptmScoring = ptmScores.getPtmScoring(mod);
                                                                boolean firstSite = true;
                                                                ArrayList<Integer> sites = new ArrayList<Integer>(ptmScoring.getDSites());
                                                                Collections.sort(sites);
                                                                for (int site : sites) {
                                                                    if (firstSite) {
                                                                        firstSite = false;
                                                                    } else {
                                                                        writer.write(", ");
                                                                    }
                                                                    writer.write(site + ": " + ptmScoring.getDeltaScore(site));
                                                                }
                                                            } else {
                                                                writer.write("Not Scored");
                                                            }
                                                            writer.write(")");
                                                        }
                                                    }
                                                    writer.write(SEPARATOR);
                                                }
                                                if (file) {
                                                    writer.write(spectrumFile + SEPARATOR);
                                                }
                                                if (title) {
                                                    writer.write(Spectrum.getSpectrumTitle(spectrumMatch.getKey()) + SEPARATOR);
                                                }
                                                if (precursor) {
                                                    Precursor prec = spectrumFactory.getPrecursor(spectrumMatch.getKey());
                                                    writer.write(prec.getMz() + SEPARATOR);
                                                    writer.write(prec.getPossibleChargesAsString() + SEPARATOR);
                                                    writer.write(bestAssumption.getIdentificationCharge().value + SEPARATOR);
                                                    writer.write(prec.getRt() + SEPARATOR);
                                                    writer.write(bestAssumption.getPeptide().getMass() + SEPARATOR);
                                                    writer.write(bestAssumption.getDeltaMass(prec.getMz(), peptideShakerGUI.getSearchParameters().isPrecursorAccuracyTypePpm()) + SEPARATOR);
                                                    writer.write(bestAssumption.getIsotopeNumber(prec.getMz()) + SEPARATOR);
                                                }
                                                if (score) {
                                                    writer.write(psParameter.getPsmScore() + SEPARATOR);
                                                }
                                                if (confidence) {
                                                    writer.write(psParameter.getPsmConfidence() + SEPARATOR);
                                                }
                                                if (!onlyValidated) {
                                                    MatchValidationLevel matchValidationLevel = psParameter.getMatchValidationLevel();
                                                    writer.write(matchValidationLevel.toString());
                                                    if (matchValidationLevel == MatchValidationLevel.doubtful && !psParameter.getReasonDoubtful().equals("")) {
                                                        writer.write(" (" + psParameter.getReasonDoubtful() + ")");
                                                    }
                                                    writer.write(SEPARATOR);

                                                    if (bestAssumption.getPeptide().isDecoy(peptideShakerGUI.getSequenceMatchingPreferences())) {
                                                        writer.write(1 + SEPARATOR);
                                                    } else {
                                                        writer.write(0 + SEPARATOR);
                                                    }
                                                }
                                                if (includeHidden) {
                                                    writer.write(psParameter.isHidden() + SEPARATOR);
                                                }
                                                writer.write(System.getProperty("line.separator"));
                                            }

                                        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.