use of com.compomics.util.experiment.identification.Advocate in project peptide-shaker by compomics.
the class PeptideShakerMethods method getSearchEnginesText.
/**
* Returns the search engines usage details.
*
* @param projectDetails the PeptideShaker project details
*
* @return the search engines usage details
*/
public static String getSearchEnginesText(ProjectDetails projectDetails) {
StringBuilder text = new StringBuilder();
text.append("Peak lists obtained from MS/MS spectra were identified using ");
ArrayList<Integer> searchEngines = projectDetails.getIdentificationAlgorithms();
Collections.sort(searchEngines);
HashMap<String, ArrayList<String>> algorithmToVersionMap = projectDetails.getAlgorithmNameToVersionsMap();
for (int i = 0; i < searchEngines.size(); i++) {
if (i > 0) {
if (i == searchEngines.size() - 1) {
text.append(" and ");
} else {
text.append(", ");
}
}
Advocate advocate = Advocate.getAdvocate(searchEngines.get(i));
String ref = advocate.getPmid();
if (ref == null) {
ref = "add reference here";
}
text.append(advocate.getName()).append(" ");
ArrayList<String> versions = algorithmToVersionMap.get(advocate.getName());
if (versions == null || versions.isEmpty()) {
text.append("version [add version here]");
} else if (versions.size() == 1) {
if (versions.get(0) != null) {
text.append("version ").append(versions.get(0));
} else {
text.append("version unknown");
}
} else {
text.append("versions ");
Collections.sort(versions);
for (int j = 0; j < versions.size(); j++) {
if (j > 0) {
if (j == versions.size() - 1) {
text.append(" and ");
} else {
text.append(", ");
}
}
if (versions.get(0) != null) {
text.append(versions.get(j));
} else {
text.append("unknown");
}
}
}
text.append(" [PMID ").append(ref).append("]");
}
text.append(".");
return text.toString();
}
use of com.compomics.util.experiment.identification.Advocate in project peptide-shaker by compomics.
the class PepXmlExport method writeSearchHit.
/**
* Writes a search hit section.
*
* @param sw the XML file writer
* @param identification the identification object containing the
* identification results
* @param identificationParameters the identification parameters
* @param waitingHandler a waiting handler to display progress and allow
* interrupting the process
*
* @throws IOException exception thrown whenever an error is encountered
* while reading or writing a file
*/
private void writeSearchHit(SimpleXmlWriter sw, IdentificationParameters identificationParameters, PeptideAssumption peptideAssumption, double precursorMz, PSParameter psParameter, boolean mainHit) throws IOException {
Peptide peptide = peptideAssumption.getPeptide();
StringBuilder searchHitStart = new StringBuilder();
searchHitStart.append("<search_hit hit_rank=\"").append(peptideAssumption.getRank()).append("\" ").append("peptide=\"").append(peptide.getSequence()).append("\" ");
TreeMap<String, int[]> proteinMapping = peptide.getProteinMapping();
String proteins = proteinMapping.navigableKeySet().stream().collect(Collectors.joining(","));
searchHitStart.append("protein=\"").append(proteins).append("\" ").append("num_tot_proteins=\"").append(proteinMapping.size()).append("\" ").append("calc_neutral_pep_mass=\"").append(peptideAssumption.getTheoreticMass()).append("\" ").append("massdiff=\"").append(peptideAssumption.getDeltaMz(precursorMz, false, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection())).append("\">");
sw.writeLine(searchHitStart.toString());
sw.increaseIndent();
if (proteinMapping.size() > 1) {
for (String accession : proteinMapping.navigableKeySet()) {
StringBuilder proteinLine = new StringBuilder();
proteinLine.append("<alternative_protein protein=\"").append(accession).append("\"/>");
sw.writeLine(proteinLine.toString());
}
}
ModificationMatch[] modificationMatches = peptide.getVariableModifications();
if (modificationMatches.length > 0) {
HashMap<Integer, Double> modifiedAminoAcids = new HashMap<>(modificationMatches.length);
Double nTermMass = null;
Double cTermMass = null;
for (ModificationMatch modificationMatch : modificationMatches) {
Modification modification = modificationFactory.getModification(modificationMatch.getModification());
ModificationType modificationType = modification.getModificationType();
if (modificationType == ModificationType.modn_protein || modificationType == ModificationType.modn_peptide) {
if (nTermMass == null) {
nTermMass = Atom.H.getMonoisotopicMass();
}
nTermMass += modification.getMass();
} else if (modificationType == ModificationType.modc_protein || modificationType == ModificationType.modc_peptide) {
if (cTermMass == null) {
cTermMass = Atom.H.getMonoisotopicMass() + Atom.O.getMonoisotopicMass();
}
cTermMass += modification.getMass();
} else {
int site = modificationMatch.getSite();
Double modMass = modifiedAminoAcids.get(site);
if (modMass == null) {
modMass = 0.0;
}
modMass += modification.getMass();
modifiedAminoAcids.put(site, modMass);
}
}
StringBuilder modificationStart = new StringBuilder();
modificationStart.append("<modification_info");
if (nTermMass != null) {
modificationStart.append(" mod_nterm_mass=\"").append(nTermMass).append("\"");
}
if (cTermMass != null) {
modificationStart.append(" mod_cterm_mass=\"").append(nTermMass).append("\"");
}
modificationStart.append(">");
sw.writeLine(modificationStart.toString());
if (!modifiedAminoAcids.isEmpty()) {
sw.increaseIndent();
for (Integer site : modifiedAminoAcids.keySet()) {
double modifiedMass = modifiedAminoAcids.get(site);
StringBuilder modificationSite = new StringBuilder();
modificationSite.append("<mod_aminoacid_mass position=\"").append(site).append("\" mass=\"").append(modifiedMass).append("\"/>");
sw.writeLine(modificationSite.toString());
}
sw.decreaseIndent();
}
sw.writeLine("</modification_info>");
}
if (mainHit) {
StringBuilder searchScore = new StringBuilder();
searchScore.append("<search_score name=\"PSM raw score\" value=\"").append(psParameter.getTransformedScore()).append("\"/>");
sw.writeLine(searchScore.toString());
searchScore = new StringBuilder();
searchScore.append("<search_score name=\"PSM score\" value=\"").append(psParameter.getTransformedScore()).append("\"/>");
sw.writeLine(searchScore.toString());
searchScore = new StringBuilder();
searchScore.append("<search_score name=\"PSM PEP\" value=\"").append(psParameter.getProbability()).append("\"/>");
sw.writeLine(searchScore.toString());
searchScore = new StringBuilder();
searchScore.append("<search_score name=\"PSM confidence\" value=\"").append(psParameter.getConfidence()).append("\"/>");
sw.writeLine(searchScore.toString());
} else {
StringBuilder searchScore = new StringBuilder();
searchScore.append("<search_score name=\"Identification algorithm raw score\" value=\"").append(peptideAssumption.getRawScore()).append("\"/>");
sw.writeLine(searchScore.toString());
searchScore = new StringBuilder();
searchScore.append("<search_score name=\"Identification algorithm score\" value=\"").append(peptideAssumption.getScore()).append("\"/>");
sw.writeLine(searchScore.toString());
searchScore = new StringBuilder();
searchScore.append("<search_score name=\"Identification algorithm PEP\" value=\"").append(psParameter.getProbability()).append("\"/>");
sw.writeLine(searchScore.toString());
searchScore = new StringBuilder();
searchScore.append("<search_score name=\"Identification algorithm confidence\" value=\"").append(psParameter.getConfidence()).append("\"/>");
sw.writeLine(searchScore.toString());
}
sw.writeLine("<analysis_result>");
int advocateId = peptideAssumption.getAdvocate();
Advocate advocate = Advocate.getAdvocate(advocateId);
StringBuilder parameterLine = new StringBuilder();
parameterLine.append("<parameter name=\"algorithm\" value=\"").append(advocate.getName()).append("\"/>");
sw.writeLineIncreasedIndent(parameterLine.toString());
for (ModificationMatch modificationMatch : modificationMatches) {
parameterLine = new StringBuilder();
parameterLine.append("<parameter name=\"ptm\" value=\"").append(modificationMatch.getModification()).append(" (").append(modificationMatch.getSite()).append(")").append("\"/>");
sw.writeLine(parameterLine.toString());
}
parameterLine = new StringBuilder();
parameterLine.append("<parameter name=\"charge\" value=\"").append(Integer.toString(peptideAssumption.getIdentificationCharge())).append("\"/>");
sw.writeLine(parameterLine.toString());
parameterLine = new StringBuilder();
parameterLine.append("<parameter name=\"isotope\" value=\"").append(peptideAssumption.getIsotopeNumber(precursorMz, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection())).append("\"/>");
sw.writeLine(parameterLine.toString());
sw.writeLineDecreasedIndent("</analysis_result>");
sw.writeLineDecreasedIndent("</search_hit>");
}
use of com.compomics.util.experiment.identification.Advocate 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++;
}
}
use of com.compomics.util.experiment.identification.Advocate in project peptide-shaker by compomics.
the class ProjectDetails method getIdentificationAlgorithms.
/**
* Returns a list of identification algorithms used based on the
* identification files of the project.
*
* @return a list of identification algorithms indexed by the static field
* of the Advocate class
*/
public ArrayList<Integer> getIdentificationAlgorithms() {
ArrayList<Integer> result = new ArrayList<>();
for (HashMap<String, ArrayList<String>> advocateVersions : identificationAlgorithms.values()) {
for (String advocateName : advocateVersions.keySet()) {
Advocate advocate = Advocate.getAdvocate(advocateName);
if (advocate == null) {
throw new IllegalArgumentException("Identification algorithm " + advocateName + " not recognized.");
}
int advocateId = advocate.getIndex();
if (!result.contains(advocateId)) {
result.add(advocateId);
}
}
}
return result;
}
Aggregations