I don't understand this error....
Building the last parts on the program, I have one error I don't understand.
Error:
Code:
C:\Documents and Settings\.....\Converter.java:145: setAttribute(java.lang.String,java.lang.String) in org.w3c.dom.Element cannot be applied to (java.lang.String,java.lang.Float)
child2.setAttribute("calc_neutral_pep_mass", massaInfo2);
^
1 error
And this is my program:
Code:
/**
* Autheur: Oddens, Ilse X.M.
* Creation Date: 9 June 2011.
* Location: Leiden, the Netherlands.
* Student at the Hogeschool Leiden.
* Goal of this program: Read in a .msgfdb file and transform this to am .xml file.
* Programmed on: Windows XP
*/
import java.io.*;
import java.util.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
public class pepXMLConverter {
public static void main(String[] args) throws Exception {
// Make new Document
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
Document doc = docBuilder.newDocument();
//
ArrayList<Float> arrayList = new ArrayList<Float>();
// Create and add a root element.
Element elt = doc.createElement("root");
doc.appendChild(elt);
try {
// Create an instance for the file that needs to be loaded in the script.
Scanner in = new Scanner(System.in);
System.out.print("Enter the file name: ");
File file1 = new File(in.next());
Scanner s = new Scanner(file1);
// Keeps track of the count.
int getal = 0;
// Create a Dictionary (Hashmap).
// In here we have all the monoisotopic amino acid masses.
Map<String, Float> y = new HashMap<String, Float>();
y.put("A", 71.0371f);
y.put("R", 156.1011f);
y.put("N", 114.0429f);
y.put("D", 115.0269f);
y.put("C", 103.0091f);
y.put("E", 129.0425f);
y.put("Q", 128.0585f);
y.put("G", 57.0214f);
y.put("H", 137.0589f);
y.put("I", 113.0840f);
y.put("L", 113.0840f);
y.put("K", 128.0949f);
y.put("M", 131.0404f);
y.put("F", 147.0684f);
y.put("P", 97.0527f);
y.put("S", 87.0320f);
y.put("T", 101.0476f);
y.put("W", 186.0793f);
y.put("Y", 163.0633f);
y.put("V", 99.0684f);
// We read the lines from file1 one by one.
while (s.hasNextLine()) {
String line = s.nextLine();
// Skip the first line, and start with the second line.
if (getal >= 1) {
// Create the main tags:
// Create Child0.
Element child0 = doc.createElement("spectrum_query");
elt.appendChild(child0);
// Create Child1.
Element child1 = doc.createElement("search_result");
child0.appendChild(child1);
// Create Child2.
Element child2 = doc.createElement("search_hit");
child1.appendChild(child2);
// Create Child3.
Element child3 = doc.createElement("search_score");
child2.appendChild(child3);
// Create Child4.
Element child4 = doc.createElement("search_score");
child2.appendChild(child4);
// Create Child5.
Element child5 = doc.createElement("search_score");
child2.appendChild(child5);
// Read each line and seperate the words.
// After a 'tab space' the word gets seperated.
// -1 makes sure 'blank' field are alo taken with it, and not skipped.
String[] items = line.split("\t", -1);
String specFileInfo = items[0];
String scanInfo = items[1];
String actMethodInfo = items[2];
String precursorInfo = items[3];
String chargeInfo = items[4];
String peptideInfo = items[5];
String proteinInfo = items[6];
String deNovoScoreInfo = items[7];
String msgfScoreInfo = items[8];
String specProbInfo = items[9];
// Add some other values to specFileInfo2.
String specFileInfo2 = specFileInfo + "." + scanInfo + "." + scanInfo;
// Sperate the peptideInfo input in three sections.
// Ater a '.' the word gets seperated.
// -1 makes sure 'blank' field are alo taken with it.
String[] pept = peptideInfo.split("\\.",-1);
String peptide_prev_aaInfo = pept[0];
String peptide_zelfInfo = pept[1];
String peptide_next_aaInfo = pept[2];
// Calculate the peptide mass.
for (int i = 0; i < peptide_zelfInfo.length(); i++) {
String ss = peptide_zelfInfo.substring(i, i +1);
float mass = y.get(ss);
float massaInfo = mass + y.get(ss);
// Add these values to the arrayList.
arrayList.add(massaInfo);
}
// Get the last item that was stored in the arrayList.
Float massaInfo2 = arrayList.get(arrayList.size()-1);
// Add Attributes to the child0 tag.
child0.setAttribute("spectrum", specFileInfo2);
child0.setAttribute("start_scan", scanInfo);
child0.setAttribute("end_scan", scanInfo);
child0.setAttribute("precursor_neutral_mass", precursorInfo);
child0.setAttribute("assumed_charge", chargeInfo);
child0.setAttribute("index", "1");
child0.setAttribute("retention_time_sec", "0.0");
// Add Attributes to the child2 tag.
child2.setAttribute("hit_rank", "1");
child2.setAttribute("peptide", peptide_zelfInfo);
child2.setAttribute("peptide_prev_aa", peptide_prev_aaInfo);
child2.setAttribute("peptide_next_aa", peptide_next_aaInfo);
child2.setAttribute("protein", proteinInfo);
[COLOR="blue"]child2.setAttribute("calc_neutral_pep_mass", massaInfo2);[/COLOR]
child2.setAttribute("massdiff", "NOG DOEN!");
// Add Attributes to the child3, child4 and child5 tags.
child3.setAttribute("name", "DeNovoScore");
child3.setAttribute("value", deNovoScoreInfo);
child4.setAttribute("name", "MSGFScore");
child4.setAttribute("value", msgfScoreInfo);
child5.setAttribute("name", "SpecProb");
child5.setAttribute("value", specProbInfo);
}
// ++ adds +1 every line.
getal++;
}
// Set up a transformer.
TransformerFactory transFac = TransformerFactory.newInstance();
Transformer trans = transFac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
StringWriter sw = new StringWriter();
// Save to file.
StreamResult result = new StreamResult(new File("Converter_Output.pep.xml"));
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}