Commit d5e1bac7 authored by Olivier Langella's avatar Olivier Langella
Browse files

working ods document

git-svn-id: https://subversion.renater.fr/masschroq/trunk@2075 e4b6dbb4-9209-464b-83f7-6257456c460c
parent df247a29
package fr.inra.pappso.masschroq.convert.ods; package fr.inra.pappso.masschroq.convert.ods;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument; import org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument;
import org.odftoolkit.odfdom.doc.table.OdfTable;
import org.odftoolkit.odfdom.dom.element.office.OfficeBodyElement;
import org.odftoolkit.odfdom.dom.element.table.TableTableElement;
import org.odftoolkit.odfdom.pkg.OdfElement;
import org.w3c.dom.NodeList;
import fr.inra.pappso.masschroq.entities.Quantify.Quantify; import fr.inra.pappso.masschroq.entities.Quantify.Quantify;
import fr.inra.pappso.masschroq.entities.Quantify.QuantifySet; import fr.inra.pappso.masschroq.entities.Quantify.QuantifySet;
...@@ -15,8 +23,11 @@ public class OdsDoc { ...@@ -15,8 +23,11 @@ public class OdsDoc {
public OdsDoc(ShortFormMassChroQmlReader reader) throws Exception { public OdsDoc(ShortFormMassChroQmlReader reader) throws Exception {
this.odfdoc = OdfSpreadsheetDocument.newSpreadsheetDocument(); this.odfdoc = OdfSpreadsheetDocument.newSpreadsheetDocument();
// List<OdfTable> tr = odfdoc.getTableList(); // OdfTable tr = odfdoc.getTableList().get(0);
this.removeAllTables();
//tr.
QuantifySet quantifySet = reader.getQuantifySet(); QuantifySet quantifySet = reader.getQuantifySet();
...@@ -25,16 +36,39 @@ public class OdsDoc { ...@@ -25,16 +36,39 @@ public class OdsDoc {
} }
} }
private void removeAllTables() {
List<OdfTable> tableList = new ArrayList<OdfTable>();
try {
OdfElement root = odfdoc.getContentDom().getRootElement();
OfficeBodyElement officeBody = OdfElement.findFirstChildNode(OfficeBodyElement.class, root);
OdfElement typedContent = OdfElement.findFirstChildNode(
OdfElement.class, officeBody);
NodeList childList = typedContent.getChildNodes();
for (int i = 0;
i < childList.getLength();
i++) {
if (childList.item(i) instanceof TableTableElement) {
childList.item(i).getParentNode().removeChild(childList.item(i));
//tableList.add(OdfTable.getInstance((TableTableElement) childList.item(i)));
}
}
} catch (Exception e) {
logger.error("error in removeAllTables "+e.getMessage());
}
//return tableList;
}
private void writeQuantify(Quantify quantify) throws Exception { private void writeQuantify(Quantify quantify) throws Exception {
logger.debug("writeQuantify"); logger.debug("writeQuantify");
if (quantify.hasSearchItemPeptide()) { if (quantify.hasSearchItemPeptide()) {
logger.debug("hasSearchItemPeptide");
new SearchItemPeptideTable(this, quantify); new SearchItemPeptideTable(this, quantify);
} }
if (quantify.hasSearchItemMz()) { if (quantify.hasSearchItemMz()) {
//new SearchItemMzTable(this, quantify); new SearchItemMzTable(this, quantify);
} }
if (quantify.hasSearchItemMzRt()) { if (quantify.hasSearchItemMzRt()) {
//new SearchItemMzRtTable(this, quantify); new SearchItemMzRtTable(this, quantify);
} }
} }
......
package fr.inra.pappso.masschroq.convert.ods;
import org.apache.log4j.Logger;
import org.odftoolkit.odfdom.dom.element.table.TableTableElement;
import fr.inra.pappso.masschroq.entities.Quantify.Quantify;
import fr.inra.pappso.masschroq.entities.SearchItemQuantification.SearchItemQuantification;
import fr.inra.pappso.masschroq.entities.SearchItemQuantification.SearchItemQuantificationSet;
import fr.inra.pappso.masschroq.entities.searchItems.SearchItemMzRt;
public class SearchItemMzRtTable extends SearchItemTable {
private static final Logger logger = Logger
.getLogger(SearchItemMzRtTable.class);
public SearchItemMzRtTable(OdsDoc doc, Quantify quantify)
throws Exception {
super(doc, quantify);
logger.debug("SearchItemMzTable");
rowHeader = new SearchItemTableHeaderRow(this, quantify,
SearchItemMzRt.class);
table.getOdfElement().setTableNameAttribute(quantify.getXmlId()+"-mzrt");
/*
* if (searchItemClass.equals(SearchItemMz.class)) {
* table.getOdfElement().setTableNameAttribute("mz"); } if
* (searchItemClass.equals(SearchItemMzRt.class)) {
* table.getOdfElement().setTableNameAttribute("mzrt"); }
*/
SearchItemQuantificationSet quantificationSet = quantify
.getSearchItemQuantificationSet();
for (SearchItemQuantification quantification : quantificationSet) {
if (quantification.getSearchItem().getClass()
.equals(SearchItemMzRt.class)) {
writeSearchItemQuantification(quantification);
}
}
}
public TableTableElement getOdfElement() {
return table.getOdfElement();
}
}
\ No newline at end of file
package fr.inra.pappso.masschroq.convert.ods;
import org.apache.log4j.Logger;
import org.odftoolkit.odfdom.dom.element.table.TableTableElement;
import fr.inra.pappso.masschroq.entities.Quantify.Quantify;
import fr.inra.pappso.masschroq.entities.SearchItemQuantification.SearchItemQuantification;
import fr.inra.pappso.masschroq.entities.SearchItemQuantification.SearchItemQuantificationSet;
import fr.inra.pappso.masschroq.entities.searchItems.SearchItemMz;
public class SearchItemMzTable extends SearchItemTable {
private static final Logger logger = Logger
.getLogger(SearchItemMzTable.class);
public SearchItemMzTable(OdsDoc doc, Quantify quantify)
throws Exception {
super(doc, quantify);
logger.debug("SearchItemMzTable");
rowHeader = new SearchItemTableHeaderRow(this, quantify,
SearchItemMz.class);
table.getOdfElement().setTableNameAttribute(quantify.getXmlId()+"-mz");
/*
* if (searchItemClass.equals(SearchItemMz.class)) {
* table.getOdfElement().setTableNameAttribute("mz"); } if
* (searchItemClass.equals(SearchItemMzRt.class)) {
* table.getOdfElement().setTableNameAttribute("mzrt"); }
*/
SearchItemQuantificationSet quantificationSet = quantify
.getSearchItemQuantificationSet();
for (SearchItemQuantification quantification : quantificationSet) {
if (quantification.getSearchItem().getClass()
.equals(SearchItemMz.class)) {
writeSearchItemQuantification(quantification);
}
}
}
public TableTableElement getOdfElement() {
return table.getOdfElement();
}
}
\ No newline at end of file
...@@ -69,8 +69,12 @@ public class Quantify { ...@@ -69,8 +69,12 @@ public class Quantify {
return this.xmlId; return this.xmlId;
} }
public boolean hasSearchItemPeptide() { public boolean hasSearchItemPeptide() throws Exception {
if (searchItemSet == null) {
throw new Exception("searchItemSet is null");
}
for (SearchItemBase search : searchItemSet) { for (SearchItemBase search : searchItemSet) {
logger.debug("search.getClass() "+search.getClass());
if (search.getClass().equals(SearchItemPeptide.class)) { if (search.getClass().equals(SearchItemPeptide.class)) {
return true; return true;
} }
......
...@@ -31,9 +31,12 @@ public class SearchItemSet implements Set<SearchItemBase> { ...@@ -31,9 +31,12 @@ public class SearchItemSet implements Set<SearchItemBase> {
return (SearchItemPeptide) searchItemBaseList.get(xmlId.hashCode()); return (SearchItemPeptide) searchItemBaseList.get(xmlId.hashCode());
} }
public boolean addAll(Collection<? extends SearchItemBase> arg0) { public boolean addAll(Collection<? extends SearchItemBase> searchItemList) {
// TODO Auto-generated method stub boolean changed = false;
return false; for (SearchItemBase searchItem:searchItemList) {
changed = this.add(searchItem);
}
return changed;
} }
public void clear() { public void clear() {
...@@ -60,8 +63,7 @@ public class SearchItemSet implements Set<SearchItemBase> { ...@@ -60,8 +63,7 @@ public class SearchItemSet implements Set<SearchItemBase> {
} }
public Iterator<SearchItemBase> iterator() { public Iterator<SearchItemBase> iterator() {
// TODO Auto-generated method stub return searchItemBaseList.values().iterator();
return null;
} }
public boolean remove(Object arg0) { public boolean remove(Object arg0) {
......
...@@ -27,6 +27,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler { ...@@ -27,6 +27,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
.getLogger(SaxHandlerMassChroQml.class); .getLogger(SaxHandlerMassChroQml.class);
SearchItemSet searchItemSet = new SearchItemSet(); SearchItemSet searchItemSet = new SearchItemSet();
private SearchItemSet searchItemPeptideSet = new SearchItemSet();
MsRunSet msRunSet = new MsRunSet(); MsRunSet msRunSet = new MsRunSet();
GroupSet groupSet = new GroupSet(); GroupSet groupSet = new GroupSet();
QuantificationMethodSet quantificationMethodSet = new QuantificationMethodSet(); QuantificationMethodSet quantificationMethodSet = new QuantificationMethodSet();
...@@ -76,6 +77,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler { ...@@ -76,6 +77,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
SearchItemMz mz = new SearchItemMz(new Double(mzListStr[i])); SearchItemMz mz = new SearchItemMz(new Double(mzListStr[i]));
this.searchItemSet.add(mz); this.searchItemSet.add(mz);
currentQuantify.getSearchItemSet().add(mz);
} }
} }
...@@ -135,6 +137,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler { ...@@ -135,6 +137,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
SearchItemMzRt mzrt = new SearchItemMzRt(mz, rt); SearchItemMzRt mzrt = new SearchItemMzRt(mz, rt);
this.searchItemSet.add(mzrt); this.searchItemSet.add(mzrt);
currentQuantify.getSearchItemSet().add(mzrt);
} }
/* /*
...@@ -147,6 +150,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler { ...@@ -147,6 +150,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
SearchItemPeptide peptide = new SearchItemPeptide( SearchItemPeptide peptide = new SearchItemPeptide(
attrs.getValue("id")); attrs.getValue("id"));
this.searchItemSet.add(peptide); this.searchItemSet.add(peptide);
this.searchItemPeptideSet.add(peptide);
peptide.setMh(new Double(attrs.getValue("mh"))); peptide.setMh(new Double(attrs.getValue("mh")));
peptide.setMods(new Double(attrs.getValue("mods"))); peptide.setMods(new Double(attrs.getValue("mods")));
// peptide.setMods(new Double(attrs.getValue("mods"))); // peptide.setMods(new Double(attrs.getValue("mods")));
...@@ -231,13 +235,12 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler { ...@@ -231,13 +235,12 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
"quantification_data is not asssociated to any searchItem"); "quantification_data is not asssociated to any searchItem");
} }
if (currentQuantify == null) { if (currentQuantify == null) {
throw new Exception( throw new Exception("currentQuantify is null");
"currentQuantify is null");
} }
SearchItemQuantification quant = new SearchItemQuantification( SearchItemQuantification quant = new SearchItemQuantification(
this.currentMsRun, currentSearchItem); this.currentMsRun, currentSearchItem);
currentQuantify.getSearchItemQuantificationSet().add(quant); currentQuantify.getSearchItemQuantificationSet().add(quant);
quantificationList.add(quant); quantificationList.add(quant);
...@@ -265,6 +268,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler { ...@@ -265,6 +268,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
} }
} }
/* /*
* <quantification_method id="qzivy1"> * <quantification_method id="qzivy1">
*/ */
...@@ -273,10 +277,10 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler { ...@@ -273,10 +277,10 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
try { try {
if (attrs.getValue("id") == null) { if (attrs.getValue("id") == null) {
throw new Exception( throw new Exception("id attribute is missing");
"id attribute is missing");
} }
QuantificationMethod group = new QuantificationMethod(attrs.getValue("id")); QuantificationMethod group = new QuantificationMethod(
attrs.getValue("id"));
this.quantificationMethodSet.add(group); this.quantificationMethodSet.add(group);
} catch (Exception e) { } catch (Exception e) {
...@@ -287,90 +291,107 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler { ...@@ -287,90 +291,107 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
} }
} }
/* /*
* <group data_ids="samp0 samp1" id="G1"/> * <group data_ids="samp0 samp1" id="G1"/>
*/ */
public void startElementgroup(String nameSpaceUri, public void startElementgroup(String nameSpaceUri, Attributes attrs)
Attributes attrs) throws SAXException { throws SAXException {
try { try {
if (attrs.getValue("id") == null) { if (attrs.getValue("id") == null) {
throw new Exception( throw new Exception("id attribute is missing");
"id attribute is missing");
} }
if (attrs.getValue("data_ids") == null) { if (attrs.getValue("data_ids") == null) {
throw new Exception( throw new Exception("data_ids attribute is missing");
"data_ids attribute is missing");
} }
Group group = new Group(attrs.getValue("id")); Group group = new Group(attrs.getValue("id"));
String[] msrunListStr = attrs.getValue("data_ids").split(" "); String[] msrunListStr = attrs.getValue("data_ids").split(" ");
for (int i=0; i < msrunListStr.length;i++) { for (int i = 0; i < msrunListStr.length; i++) {
MsRun msRun = this.msRunSet.getByXmlId(msrunListStr[i]); MsRun msRun = this.msRunSet.getByXmlId(msrunListStr[i]);
group.getMsRunSet().add(msRun); group.getMsRunSet().add(msRun);
} }
this.groupSet.add(group); this.groupSet.add(group);
} catch (Exception e) { } catch (Exception e) {
String message = "ERROR in startElementgroup " String message = "ERROR in startElementgroup " + e.getMessage();
logger.error(message);
throw new SAXException(message);
}
}
/*
* <peptides_in_peptide_list mode="real_or_mean"/>
*/
public void startElementpeptides_in_peptide_list(String nameSpaceUri,
Attributes attrs) throws SAXException {
try {
if (currentQuantify == null) {
throw new Exception(
"currentQuantify is null");
}
currentQuantify.getSearchItemSet().addAll(this.searchItemPeptideSet);
} catch (Exception e) {
String message = "ERROR in startElementquantify "
+ e.getMessage(); + e.getMessage();
logger.error(message); logger.error(message);
throw new SAXException(message); throw new SAXException(message);
} }
} }
/* /*
* <quantify id="q2" withingroup="G2" quantification_method_id="qzivy1"> * <quantify id="q2" withingroup="G2" quantification_method_id="qzivy1">
*/ */
public void startElementquantify(String nameSpaceUri, public void startElementquantify(String nameSpaceUri, Attributes attrs)
Attributes attrs) throws SAXException { throws SAXException {
try { try {
if (attrs.getValue("id") == null) { if (attrs.getValue("id") == null) {
throw new Exception( throw new Exception("id attribute is missing");
"id attribute is missing");
} }
if (attrs.getValue("withingroup") == null) { if (attrs.getValue("withingroup") == null) {
throw new Exception( throw new Exception("withingroup attribute is missing");
"withingroup attribute is missing");
} }
if (attrs.getValue("quantification_method_id") == null) { if (attrs.getValue("quantification_method_id") == null) {
throw new Exception( throw new Exception(
"quantification_method_id attribute is missing"); "quantification_method_id attribute is missing");
} }
Group group = groupSet.getByXmlId(attrs.getValue("withingroup")); Group group = groupSet.getByXmlId(attrs.getValue("withingroup"));
QuantificationMethod method = this.quantificationMethodSet.getByXmlId(attrs.getValue("quantification_method_id")); QuantificationMethod method = this.quantificationMethodSet
Quantify quant = new Quantify(attrs.getValue("id"), group, method); .getByXmlId(attrs.getValue("quantification_method_id"));
this.quantifySet.add(quant); currentQuantify = new Quantify(attrs.getValue("id"), group, method);
this.quantifySet.add(currentQuantify);
} catch (Exception e) { } catch (Exception e) {
String message = "ERROR in startElementquantify " String message = "ERROR in startElementquantify " + e.getMessage();
+ e.getMessage();
logger.error(message); logger.error(message);
throw new SAXException(message); throw new SAXException(message);
} }
} }
/* /*
* <result quantify_id="q2"> * <result quantify_id="q2">
*/ */
public void startElementresult(String nameSpaceUri, public void startElementresult(String nameSpaceUri, Attributes attrs)
Attributes attrs) throws SAXException { throws SAXException {
try { try {
if (attrs.getValue("quantify_id") == null) { if (attrs.getValue("quantify_id") == null) {
throw new Exception( throw new Exception("quantify_id attribute is missing");
"quantify_id attribute is missing");
} }
currentQuantify = this.quantifySet.getByXmlId(attrs.getValue("quantify_id")); currentQuantify = this.quantifySet.getByXmlId(attrs
.getValue("quantify_id"));
if (currentQuantify == null) { if (currentQuantify == null) {
throw new Exception( throw new Exception("currentQuantify attribute is null");
"currentQuantify attribute is null");
} }
} catch (Exception e) { } catch (Exception e) {
String message = "ERROR in startElementresult " String message = "ERROR in startElementresult " + e.getMessage();
+ e.getMessage();
logger.error(message); logger.error(message);
throw new SAXException(message); throw new SAXException(message);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment