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;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
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.QuantifySet;
......@@ -15,8 +23,11 @@ public class OdsDoc {
public OdsDoc(ShortFormMassChroQmlReader reader) throws Exception {
this.odfdoc = OdfSpreadsheetDocument.newSpreadsheetDocument();
// List<OdfTable> tr = odfdoc.getTableList();
// OdfTable tr = odfdoc.getTableList().get(0);
this.removeAllTables();
//tr.
QuantifySet quantifySet = reader.getQuantifySet();
......@@ -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 {
logger.debug("writeQuantify");
if (quantify.hasSearchItemPeptide()) {
logger.debug("hasSearchItemPeptide");
new SearchItemPeptideTable(this, quantify);
}
if (quantify.hasSearchItemMz()) {
//new SearchItemMzTable(this, quantify);
new SearchItemMzTable(this, quantify);
}
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 {
return this.xmlId;
}
public boolean hasSearchItemPeptide() {
public boolean hasSearchItemPeptide() throws Exception {
if (searchItemSet == null) {
throw new Exception("searchItemSet is null");
}
for (SearchItemBase search : searchItemSet) {
logger.debug("search.getClass() "+search.getClass());
if (search.getClass().equals(SearchItemPeptide.class)) {
return true;
}
......
......@@ -31,9 +31,12 @@ public class SearchItemSet implements Set<SearchItemBase> {
return (SearchItemPeptide) searchItemBaseList.get(xmlId.hashCode());
}
public boolean addAll(Collection<? extends SearchItemBase> arg0) {
// TODO Auto-generated method stub
return false;
public boolean addAll(Collection<? extends SearchItemBase> searchItemList) {
boolean changed = false;
for (SearchItemBase searchItem:searchItemList) {
changed = this.add(searchItem);
}
return changed;
}
public void clear() {
......@@ -60,8 +63,7 @@ public class SearchItemSet implements Set<SearchItemBase> {
}
public Iterator<SearchItemBase> iterator() {
// TODO Auto-generated method stub
return null;
return searchItemBaseList.values().iterator();
}
public boolean remove(Object arg0) {
......
......@@ -27,6 +27,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
.getLogger(SaxHandlerMassChroQml.class);
SearchItemSet searchItemSet = new SearchItemSet();
private SearchItemSet searchItemPeptideSet = new SearchItemSet();
MsRunSet msRunSet = new MsRunSet();
GroupSet groupSet = new GroupSet();
QuantificationMethodSet quantificationMethodSet = new QuantificationMethodSet();
......@@ -76,6 +77,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
SearchItemMz mz = new SearchItemMz(new Double(mzListStr[i]));
this.searchItemSet.add(mz);
currentQuantify.getSearchItemSet().add(mz);
}
}
......@@ -135,6 +137,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
SearchItemMzRt mzrt = new SearchItemMzRt(mz, rt);
this.searchItemSet.add(mzrt);
currentQuantify.getSearchItemSet().add(mzrt);
}
/*
......@@ -147,6 +150,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
SearchItemPeptide peptide = new SearchItemPeptide(
attrs.getValue("id"));
this.searchItemSet.add(peptide);
this.searchItemPeptideSet.add(peptide);
peptide.setMh(new Double(attrs.getValue("mh")));
peptide.setMods(new Double(attrs.getValue("mods")));
// peptide.setMods(new Double(attrs.getValue("mods")));
......@@ -231,13 +235,12 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
"quantification_data is not asssociated to any searchItem");
}
if (currentQuantify == null) {
throw new Exception(
"currentQuantify is null");
throw new Exception("currentQuantify is null");
}
SearchItemQuantification quant = new SearchItemQuantification(
this.currentMsRun, currentSearchItem);
currentQuantify.getSearchItemQuantificationSet().add(quant);
quantificationList.add(quant);
......@@ -265,6 +268,7 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
}
}
/*
* <quantification_method id="qzivy1">
*/
......@@ -273,10 +277,10 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
try {
if (attrs.getValue("id") == null) {
throw new Exception(
"id attribute is missing");
throw new Exception("id attribute is missing");
}
QuantificationMethod group = new QuantificationMethod(attrs.getValue("id"));
QuantificationMethod group = new QuantificationMethod(
attrs.getValue("id"));
this.quantificationMethodSet.add(group);
} catch (Exception e) {
......@@ -287,90 +291,107 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
}
}
/*
* <group data_ids="samp0 samp1" id="G1"/>
*/
public void startElementgroup(String nameSpaceUri,
Attributes attrs) throws SAXException {
public void startElementgroup(String nameSpaceUri, Attributes attrs)
throws SAXException {
try {
if (attrs.getValue("id") == null) {
throw new Exception(
"id attribute is missing");
throw new Exception("id attribute is missing");
}
if (attrs.getValue("data_ids") == null) {
throw new Exception(
"data_ids attribute is missing");
throw new Exception("data_ids attribute is missing");
}
Group group = new Group(attrs.getValue("id"));
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]);
group.getMsRunSet().add(msRun);
}
this.groupSet.add(group);
} 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();
logger.error(message);
throw new SAXException(message);
}
}
/*
* <quantify id="q2" withingroup="G2" quantification_method_id="qzivy1">
*/
public void startElementquantify(String nameSpaceUri,
Attributes attrs) throws SAXException {
public void startElementquantify(String nameSpaceUri, Attributes attrs)
throws SAXException {
try {
if (attrs.getValue("id") == null) {
throw new Exception(
"id attribute is missing");
throw new Exception("id attribute is missing");
}
if (attrs.getValue("withingroup") == null) {
throw new Exception(
"withingroup attribute is missing");
throw new Exception("withingroup attribute is missing");
}
if (attrs.getValue("quantification_method_id") == null) {
throw new Exception(
"quantification_method_id attribute is missing");
"quantification_method_id attribute is missing");
}
Group group = groupSet.getByXmlId(attrs.getValue("withingroup"));
QuantificationMethod method = this.quantificationMethodSet.getByXmlId(attrs.getValue("quantification_method_id"));
Quantify quant = new Quantify(attrs.getValue("id"), group, method);
this.quantifySet.add(quant);
QuantificationMethod method = this.quantificationMethodSet
.getByXmlId(attrs.getValue("quantification_method_id"));
currentQuantify = new Quantify(attrs.getValue("id"), group, method);
this.quantifySet.add(currentQuantify);
} catch (Exception e) {
String message = "ERROR in startElementquantify "
+ e.getMessage();
String message = "ERROR in startElementquantify " + e.getMessage();
logger.error(message);
throw new SAXException(message);
}
}
/*
* <result quantify_id="q2">
*/
public void startElementresult(String nameSpaceUri,
Attributes attrs) throws SAXException {
public void startElementresult(String nameSpaceUri, Attributes attrs)
throws SAXException {
try {
if (attrs.getValue("quantify_id") == null) {
throw new Exception(
"quantify_id attribute is missing");
throw new Exception("quantify_id attribute is missing");
}
currentQuantify = this.quantifySet.getByXmlId(attrs.getValue("quantify_id"));
currentQuantify = this.quantifySet.getByXmlId(attrs
.getValue("quantify_id"));
if (currentQuantify == null) {
throw new Exception(
"currentQuantify attribute is null");
throw new Exception("currentQuantify attribute is null");
}
} catch (Exception e) {
String message = "ERROR in startElementresult "
+ e.getMessage();
String message = "ERROR in startElementresult " + e.getMessage();
logger.error(message);
throw new SAXException(message);
}
......
Markdown is supported
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