Skip to content
Snippets Groups Projects
Commit ba4df1b2 authored by Olivier Langella's avatar Olivier Langella
Browse files

objects to writer XPIP files

parent 4de67483
No related branches found
No related tags found
No related merge requests found
package fr.inra.pappso.xtandempipeline.output;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import javax.xml.stream.XMLOutputFactory;
//import com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter;
import javax.xml.stream.XMLStreamWriter;
import org.apache.log4j.Logger;
import fr.inra.moulon.proticport.model.exceptions.ProticPortException;
import fr.inra.pappso.xtandempipeline.MsException.MSMSException;
import fr.inra.pappso.xtandempipeline.class_msms.Identification;
import fr.inra.pappso.xtandempipeline.thread.DataType_Base;
import fr.inra.pappso.xtandempipeline.thread.process;
public class XpipOutput {
private static final Logger logger = Logger.getLogger(XpipOutput.class);
XMLStreamWriter writer;
OutputStream outputStream;
XpipWriter xpipWriter;
public XpipOutput() throws ProticPortException {
}
public void open(OutputStream outputStream) throws MSMSException {
try {
this.outputStream = outputStream;
XMLOutputFactory factory = XMLOutputFactory.newInstance();
// OutputStreamWriter noIndentOutput = new OutputStreamWriter(
// outputStream, "UTF8");
// XMLStreamWriter writer =
// factory.createXMLStreamWriter(noIndentOutput);
OutputStreamWriter output = new OutputStreamWriter(outputStream,
"UTF8");
writer = new IndentingXMLStreamWriter(
factory.createXMLStreamWriter(output));
writer.writeStartDocument("UTF-8", "1.0");
xpipWriter = new XpipWriter(writer);
logger.debug("No errors writing XPIP. All seems OK!");
} catch (Exception e) {
try {
outputStream.write(e.getMessage().toString().getBytes());
} catch (IOException e1) {
logger.debug("ERROR : " + e.getMessage(), e);
}
// throw new ProticPortException ("ERROR writing mzXml "+
// e.getMessage());
logger.debug("ERROR writing XPIP : " + e.getMessage(), e);
}
}
public void close() {
try {
xpipWriter.close();
outputStream.flush();
logger.debug("No errors writing XPIP. All seems OK!");
} catch (Exception e) {
try {
outputStream.write(e.getMessage().toString().getBytes());
} catch (IOException e1) {
logger.debug("ERROR : " + e.getMessage(), e);
}
// throw new ProticPortException ("ERROR writing mzXml "+
// e.getMessage());
logger.debug("ERROR writing XPIP : " + e.getMessage(), e);
}
}
public void write(ArrayList<Identification> identifications,
DataType_Base datatype, process p) throws Exception {
xpipWriter.write(identifications, datatype, p);
}
}
package fr.inra.pappso.xtandempipeline.output;
import java.util.ArrayList;
import javax.xml.stream.XMLStreamException;
//import com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter;
import javax.xml.stream.XMLStreamWriter;
import org.apache.log4j.Logger;
import fr.inra.moulon.proticport.model.Controller;
import fr.inra.pappso.xtandempipeline.XtandemPipelineMain;
import fr.inra.pappso.xtandempipeline.XtandemPipelineSession;
import fr.inra.pappso.xtandempipeline.class_msms.Identification;
import fr.inra.pappso.xtandempipeline.class_msms.Match;
import fr.inra.pappso.xtandempipeline.class_msms.Modifs;
import fr.inra.pappso.xtandempipeline.class_msms.MsRun;
import fr.inra.pappso.xtandempipeline.class_msms.MapDb.Peptide;
import fr.inra.pappso.xtandempipeline.thread.DataType_Base;
import fr.inra.pappso.xtandempipeline.thread.process;
public class XpipWriter {
private static final Logger logger = Logger.getLogger(XpipWriter.class);
private ArrayList<Identification> idents;
private XMLStreamWriter writer;
private process pro;
protected XpipWriter(XMLStreamWriter writer) throws Exception {
logger.info("Save project ...");
this.writer = writer;
writer.writeStartElement("xtandem_pipeline");
writer.writeAttribute("version", XtandemPipelineMain.version);
}
private void write_result_to(Identification ident) throws Exception {
writer.writeStartElement("identification");
writer.writeStartElement("modifs_list_mass");
for (Modifs mod : ident.get_modifs_liste().get_modifs_order()) {
writer.writeEmptyElement("modifs_mass");
writer.writeAttribute("modvalue", "" + mod.get_modvalue());
}
writer.writeEndElement();
writer.writeStartElement("samples");
for (MsRun samp : ident.getMsRunSet()) {
writer.writeEmptyElement("sample");
writer.writeAttribute("value", samp.getSampleName());
}
writer.writeEndElement();
writer.writeStartElement("match_list");
for (Match m : ident.get_protein_liste().getMatchOrder())
this.write_match_to(m, ident);
writer.writeEndElement();
// on ferme l'ident
writer.writeEndElement();
// writer.flush();
}
private void write_match_to(Match m, Identification ident) throws Exception {
writer.writeStartElement("match");
writer.writeAttribute("validate", "" + m.isIsvalidate());
writer.writeAttribute("PAI", "" + m.getPAI());
writer.writeAttribute("emPAI", "" + m.getEmPAI());
writer.writeStartElement("protein");
writer.writeAttribute("peptide_number", ""
+ m.get_protein_match().get_peptides_numbers());
writer.writeAttribute("evalue", "" + m.get_protein_match().get_evalue());
writer.writeAttribute("URL", m.get_protein_match().getDatabase()
.getDatabasePath());
writer.writeAttribute("description", m.get_protein_match()
.get_description());
// sample evalue
for (MsRun sample : m.get_protein_match().get_hash_sample_evalue()
.keySet()) {
writer.writeEmptyElement("protein_evalue");
writer.writeAttribute("evalue", ""
+ m.get_protein_match().get_hash_sample_evalue()
.get(sample));
writer.writeAttribute("sample", sample.getSampleName());
// writer.writeCharacters(endline);
}
writer.writeStartElement("sequence");
writer.writeCharacters(m.get_protein_match().get_sequence());
writer.writeEndElement();
writer.writeEndElement();
writer.writeStartElement("peptide_list");
for (Peptide pep : m.get_all_peptides())
this.write_peptide_to(pep);
writer.writeEndElement();
// on ferme le match
writer.writeEndElement();
// on compte les match
pro.add_current_progress();
}
private void write_peptide_to(Peptide pep) throws Exception {
writer.writeStartElement("peptide");
writer.writeAttribute("sample", pep.get_sample());
pep.getIdentificationDataSource().writeXpipPeptideSourceAttribute(
writer);
writer.writeAttribute("scan", "" + pep.get_scan());
writer.writeAttribute("scan_in_xtandem", "" + pep.get_scan());
writer.writeAttribute("RT", "" + pep.get_RT_in_sec());
writer.writeAttribute("mhplus_obser", "" + pep.get_mhplus_obser());
writer.writeAttribute("mhplus_theo", "" + pep.get_mhplus_theo());
writer.writeAttribute("deltamass", "" + pep.get_deltamass());
writer.writeAttribute("sequence", pep.getSequence());
writer.writeAttribute("pre", pep.get_pre());
writer.writeAttribute("post", pep.get_post());
writer.writeAttribute("start", "" + pep.get_start());
writer.writeAttribute("stop", "" + pep.get_stop());
writer.writeAttribute("charge", "" + pep.get_charge());
writer.writeAttribute("evalue", "" + pep.get_evalue());
writer.writeAttribute("hypercorr", "" + pep.get_hypercorr());
writer.writeAttribute("validate", "" + pep.isValidate());
writer.writeStartElement("modifs");
for (Modifs mod : pep.get_Modifs()) {
writer.writeEmptyElement("modif");
writer.writeAttribute("aa", "" + mod.get_AA());
writer.writeAttribute("modvalue", "" + mod.get_modvalue());
writer.writeAttribute("posi", "" + mod.get_posi());
writer.writeAttribute("posi_in_prot", "" + mod.getPosi_in_prot());
}
writer.writeEndElement();
// on ferme le peptide
writer.writeEndElement();
}
protected void close() throws XMLStreamException {
writer.writeEndDocument();
}
protected void write(ArrayList<Identification> identifications,
DataType_Base datatype, process p) throws Exception {
this.idents = identifications;
this.pro = p;
// <DataSource>
// <PROTICport
// url="http://uln.moulon.inra.fr/~langella/proticdev/web_view/proticport/"
// user="langella" />
// </DataSource>
if (XtandemPipelineSession.getInstance().isPROTICportDataSource()) {
writer.writeStartElement("DataSource");
writer.writeEmptyElement("PROTICport");
Controller ppc = XtandemPipelineSession.getInstance()
.getPROTICportController();
writer.writeAttribute("url", ppc.getProticPortUrl().toString());
writer.writeAttribute("user", ppc.getUser().getLogin());
writer.writeEndElement();
}
writer.writeEmptyElement("information");
writer.writeAttribute("Data_Type", datatype.getType());
int count = 0;
for (Identification ident : idents)
count += ident.get_protein_liste().size();
writer.writeAttribute("match_number", "" + count);
writer.writeEmptyElement("filter_params");
writer.writeAttribute("pep_evalue", ""
+ datatype.getConf().get_peptide_evalue());
writer.writeAttribute("prot_evalue", ""
+ datatype.getConf().get_protein_evalue());
writer.writeAttribute("pep_number", ""
+ datatype.getConf().get_peptide_number());
writer.writeAttribute("filter_to_all", ""
+ datatype.getConf().get_protein_filter_to_complete());
writer.writeAttribute("database_filter", datatype.getConf()
.get_database_filter().getPath());
writer.writeStartElement("identifications");
for (Identification ident : idents)
this.write_result_to(ident);
writer.writeEndElement();
// on ferme le root
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
writer.close();
logger.info("Save project finish");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment