Commit 9672a0df authored by Olivier Langella's avatar Olivier Langella
Browse files

git-svn-id: https://subversion.renater.fr/masschroq/trunk@2069 e4b6dbb4-9209-464b-83f7-6257456c460c
parent 3b56da95
......@@ -30,7 +30,7 @@ public class McStudioMain {
String output = args[1];
new Mc2Ods(reader, output);
//new Mc2Ods(reader, output);
} catch (Exception e) {
Shell shell = new Shell(display);
......
......@@ -41,6 +41,7 @@ public class Mc2Ods {
}
MsRunSet msRunSet = reader.getMsRunSet();
logger.debug("msRunSet size "+ msRunSet.size());
// int data[][] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11,
// 12
// } };
......
package fr.inra.pappso.masschroq.convert.ods;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.log4j.Logger;
......@@ -12,6 +13,7 @@ import org.odftoolkit.odfdom.dom.element.table.TableTableRowElement;
import fr.inra.pappso.masschroq.entities.MsRun.MsRun;
import fr.inra.pappso.masschroq.entities.MsRun.MsRunSet;
import fr.inra.pappso.masschroq.entities.SearchItemQuantification.SearchItemQuantification;
import fr.inra.pappso.masschroq.entities.SearchItemQuantification.SearchItemQuantificationValueBase;
import fr.inra.pappso.masschroq.entities.searchItems.SearchItemBase;
import fr.inra.pappso.masschroq.entities.searchItems.SearchItemMz;
import fr.inra.pappso.masschroq.entities.searchItems.SearchItemMzRt;
......@@ -30,7 +32,7 @@ public class SearchItemTable {
private HashMap<SearchItemBase, SearchItemTableRow> searchItem2row;
public SearchItemTable(OdfSpreadsheetDocument odfdoc,
MsRunSet msRunSet, Class<? extends SearchItemBase> searchItemClass) {
MsRunSet msRunSet, Class<? extends SearchItemBase> searchItemClass) throws Exception {
table = OdfTable.newTable(odfdoc);
odfdoc.getTableList().add(table);
rowHeader = new SearchItemTableHeaderRow(this, msRunSet, searchItemClass);
......@@ -55,20 +57,31 @@ public class SearchItemTable {
}
public void writeSearchItemQuantification(
SearchItemQuantification quantification) {
SearchItemQuantification quantification) throws Exception {
searchItem2row = new HashMap<SearchItemBase, SearchItemTableRow>();
SearchItemTableRow currentRow = null;
if (searchItem2row.containsKey(quantification.getSearchItem())) {
currentRow = searchItem2row.get(quantification.getSearchItem());
} else {
currentRow = new SearchItemTableRow(getOdfElement().newTableTableRowElement(),
currentRow = new SearchItemTableRow(this,
quantification.getSearchItem());
searchItem2row.put(quantification.getSearchItem(), currentRow);
}
MsRun msRun = quantification.getMsRun();
currentRow.writeQuantification(quantification);
}
public int getNbValuesPerRows() {
return rowHeader.getNbValuesPerRows();
}
public Integer getPositionsOfMsRun(MsRun msRun) {
return rowHeader.getPositionsOfMsRun(msRun);
}
public ArrayList<Class<? extends SearchItemQuantificationValueBase>> getQuantifValuesToWrite() {
return rowHeader.getQuantifValuesToWrite();
}
}
\ No newline at end of file
......@@ -24,12 +24,20 @@ public class SearchItemTableHeaderRow {
private HashMap<MsRun, Integer> msRun2position = new HashMap<MsRun, Integer>();
private ArrayList<Class<? extends SearchItemQuantificationValueBase>> quantValues= new ArrayList<Class<? extends SearchItemQuantificationValueBase>>();
private ArrayList<Class<? extends SearchItemQuantificationValueBase>> quantValues = new ArrayList<Class<? extends SearchItemQuantificationValueBase>>();
private MsRunSet msRunSet;
public SearchItemTableHeaderRow(SearchItemTable table, MsRunSet msRunSet,
Class<? extends SearchItemBase> searchItemClass) {
Integer i=0;
Class<? extends SearchItemBase> searchItemClass) throws Exception {
this.msRunSet = msRunSet;
quantValues.add(SearchItemQuantificationArea.class);
if (msRunSet == null) {
throw new Exception("msRunSet is null");
}
TableTableRowElement header1 = table.getOdfElement()
.newTableTableRowElement();
currentRow = table.getOdfElement().newTableTableRowElement();
......@@ -38,29 +46,48 @@ public class SearchItemTableHeaderRow {
cell = currentRow.newTableTableCellElement(0, "string");
cell.setOfficeStringValueAttribute("sequence");
header1.newTableTableCellElement(0, "string");
i++;
}
}
if (searchItemClass.equals(SearchItemMz.class)) {
}
if (searchItemClass.equals(SearchItemMzRt.class)) {
}
quantValues.add(SearchItemQuantificationArea.class);
Integer i = 0;
for (MsRun msRun : msRunSet) {
cell = header1.newTableTableCellElement(0, "string");
cell.setOfficeStringValueAttribute(msRun.getXmlId());
msRun2position.put(msRun, i);
cell = currentRow.newTableTableCellElement(0, "string");
cell.setOfficeStringValueAttribute("area");
i++;
int j = 0;
for (Class<? extends SearchItemQuantificationValueBase> quantValue : quantValues) {
cell = currentRow.newTableTableCellElement(0, "string");
if (quantValue.equals(SearchItemQuantificationArea.class)) {
cell.setOfficeStringValueAttribute("area");
}
if (j > 0) {
header1.newTableTableCellElement(0, "string");
}
j++;
}
i = i + j;
}
}
public int getNbValuesPerRows() {
return (this.msRunSet.size() * quantValues.size());
}
public Integer getPositionsOfMsRun(MsRun msRun) {
if (msRun2position.containsKey(msRun)) {
return msRun2position.get(msRun);
}
return null;
}
public ArrayList<Class<? extends SearchItemQuantificationValueBase>> getQuantifValuesToWrite() {
return quantValues;
}
}
\ No newline at end of file
package fr.inra.pappso.masschroq.convert.ods;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import org.odftoolkit.odfdom.dom.element.table.TableTableCellElement;
import org.odftoolkit.odfdom.dom.element.table.TableTableRowElement;
import fr.inra.pappso.masschroq.entities.MsRun.MsRun;
import fr.inra.pappso.masschroq.entities.SearchItemQuantification.SearchItemQuantification;
import fr.inra.pappso.masschroq.entities.SearchItemQuantification.SearchItemQuantificationValueBase;
import fr.inra.pappso.masschroq.entities.searchItems.SearchItemBase;
import fr.inra.pappso.masschroq.entities.searchItems.SearchItemPeptide;
public class SearchItemTableRow {
private static final Logger logger = Logger.getLogger(SearchItemTableRow.class);
private static final Logger logger = Logger
.getLogger(SearchItemTableRow.class);
TableTableRowElement currentRow;
public SearchItemTableRow (TableTableRowElement currentRow, SearchItemBase searchItem) {
this.currentRow = currentRow;
ArrayList<TableTableCellElement> cellsOfValues = new ArrayList<TableTableCellElement>(
0);
private SearchItemTable table;
public SearchItemTableRow(SearchItemTable table, SearchItemBase searchItem) {
this.table = table;
this.currentRow = table.getOdfElement().newTableTableRowElement();
if (searchItem.getClass().equals(SearchItemPeptide.class)) {
SearchItemPeptide peptide = (SearchItemPeptide) searchItem;
TableTableCellElement cell = currentRow.newTableTableCellElement(0,
......@@ -23,6 +35,31 @@ public class SearchItemTableRow {
cell.setOfficeStringValueAttribute(peptide.getSequence());
}
int nb = table.getNbValuesPerRows();
for (int i = 0; i < nb; i++) {
logger.debug("cellsOfValues i "+i);
cellsOfValues.add(currentRow.newTableTableCellElement(0, "float"));
}
}
public void writeQuantification(SearchItemQuantification quantification) throws Exception {
MsRun msRun = quantification.getMsRun();
Integer pos= table.getPositionsOfMsRun(msRun);
logger.debug("msRun "+msRun.getXmlId()+" pos "+pos);
if (pos == null) {
throw new Exception ("msRun "+msRun.getXmlId()+" is not taken into account for this table");
}
ArrayList<Class<? extends SearchItemQuantificationValueBase>> quantifValues = table.getQuantifValuesToWrite();
for (Class<? extends SearchItemQuantificationValueBase> quantifClass:quantifValues) {
logger.debug("class "+quantifClass.getName()+" cellsOfValues get pos "+pos);
TableTableCellElement cell = this.cellsOfValues.get(pos);
cell.setOfficeValueTypeAttribute("float");
cell.setOfficeValueAttribute(quantification.getValue(quantifClass));
}
}
}
\ No newline at end of file
......@@ -50,8 +50,7 @@ public class MsRunSet implements Set<MsRun> {
}
public Iterator<MsRun> iterator() {
// TODO Auto-generated method stub
return null;
return msRunList.values().iterator();
}
public boolean remove(Object arg0) {
......@@ -70,8 +69,7 @@ public class MsRunSet implements Set<MsRun> {
}
public int size() {
// TODO Auto-generated method stub
return 0;
return msRunList.size();
}
public Object[] toArray() {
......
package fr.inra.pappso.masschroq.entities;
import org.apache.log4j.Logger;
import org.odftoolkit.odfdom.dom.element.table.TableTableRowElement;
abstract public class Quantify {
private static final Logger logger = Logger.getLogger(Quantify.class);
public Quantify() {
logger.debug("Quantify begin");
}
}
package fr.inra.pappso.masschroq.entities.SearchItemQuantification;
import java.util.HashMap;
import java.util.SortedMap;
import java.util.TreeMap;
......@@ -14,10 +15,10 @@ public class SearchItemQuantification {
MsRun msRun;
SearchItemBase searchItem;
SortedMap<Class<SearchItemQuantificationValueBase>, SearchItemQuantificationValueBase> values = new TreeMap<Class<SearchItemQuantificationValueBase>, SearchItemQuantificationValueBase>();
HashMap<Class<? extends SearchItemQuantificationValueBase>, SearchItemQuantificationValueBase> values = new HashMap<Class<? extends SearchItemQuantificationValueBase>, SearchItemQuantificationValueBase>();
public SearchItemQuantification(MsRun currentMsRun, SearchItemBase searchItem) {
logger.debug("SearchItemQuantification begin");
//logger.debug("SearchItemQuantification begin");
this.searchItem = searchItem;
this.msRun = currentMsRun;
}
......@@ -25,11 +26,7 @@ public class SearchItemQuantification {
@SuppressWarnings("unchecked")
public
void add(SearchItemQuantificationValueBase value) {
values.put((Class<SearchItemQuantificationValueBase>) value.getClass(), value);
}
SearchItemQuantificationValueBase get(Class<SearchItemQuantificationValueBase> classname) {
return values.get(classname);
values.put(value.getClass(), value);
}
public SearchItemBase getSearchItem() {
......@@ -39,4 +36,9 @@ public class SearchItemQuantification {
public MsRun getMsRun() {
return this.msRun;
}
public Double getValue(
Class<? extends SearchItemQuantificationValueBase> quantifClass) {
return values.get(quantifClass).toDouble();
}
}
package fr.inra.pappso.masschroq.entities.SearchItemQuantification;
import org.apache.log4j.Logger;
public class SearchItemQuantificationArea extends SearchItemQuantificationValueBase {
private static final Logger logger = Logger.getLogger(SearchItemQuantificationArea.class);
public class SearchItemQuantificationArea extends
SearchItemQuantificationValueBase {
private static final Logger logger = Logger
.getLogger(SearchItemQuantificationArea.class);
protected double area;
public SearchItemQuantificationArea(double area) {
logger.debug("SearchItemQuantificationArea begin");
//logger.debug("SearchItemQuantificationArea begin");
this.area = area;
}
public Double toDouble() {
return this.area;
}
}
......@@ -7,7 +7,12 @@ abstract public class SearchItemQuantificationValueBase {
private static final Logger logger = Logger.getLogger(SearchItemQuantificationValueBase.class);
public SearchItemQuantificationValueBase() {
logger.debug("SearchItemQuantificationValueBase begin");
//logger.debug("SearchItemQuantificationValueBase begin");
}
public Double toDouble() {
// TODO Auto-generated method stub
return null;
}
}
......@@ -12,7 +12,16 @@ abstract public class SearchItemBase {
logger.debug("SearchItemBase begin");
}
@Override
abstract public int hashCode();
@Override
public boolean equals(Object aThat) {
if (this.hashCode() == aThat.hashCode()) {
return true;
}
return false;
}
public void printHeader(TableTableRowElement currentRow) {
......
......@@ -15,5 +15,10 @@ public class SearchItemMz extends SearchItemBase {
return mzcode.hashCode();
}
@Override
public String toString () {
return new String("-" + mz);
}
}
......@@ -20,6 +20,10 @@ public class SearchItemMzRt extends SearchItemMz {
return mzcode.hashCode();
}
@Override
public String toString () {
return new String("-" + mz+"-"+rt);
}
}
......@@ -41,5 +41,9 @@ public class SearchItemPeptide extends SearchItemMzRt {
public String getSequence() {
return this.sequence;
}
@Override
public String toString () {
return xmlId;
}
}
......@@ -97,8 +97,10 @@ public class SearchItemSet implements Set<SearchItemBase> {
public boolean add(SearchItemBase e) {
Integer fingerPrint = e.hashCode();
if (this.searchItemBaseList.containsKey(fingerPrint)) {
logger.debug("e is in "+e.toString());
return false;
} else {
logger.debug("e is not in "+e.toString());
searchItemBaseList.put(fingerPrint, e);
}
return true;
......
......@@ -248,4 +248,46 @@ public class SaxHandlerMassChroQml extends SaxBaseHandler {
}
}
/*
* <quantify id="q2" withingroup="G2" quantification_method_id="qzivy1">
*/
public void startElementquantify(String nameSpaceUri,
Attributes attrs) throws SAXException {
try {
if (attrs.getValue("quantify_id") == null) {
throw new Exception(
"quantify_id attribute is missing");
}
} catch (Exception e) {
String message = "ERROR in startElementresult "
+ e.getMessage();
logger.error(message);
throw new SAXException(message);
}
}
/*
* <result quantify_id="q2">
*/
public void startElementresult(String nameSpaceUri,
Attributes attrs) throws SAXException {
try {
if (attrs.getValue("quantify_id") == null) {
throw new Exception(
"quantify_id attribute is missing");
}
} catch (Exception e) {
String message = "ERROR in startElementresult "
+ e.getMessage();
logger.error(message);
throw new SAXException(message);
}
}
}
\ No newline at end of file
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