I am trying to parse a GFF file and search for a particular gene ID, and if found, convert the whole row of that gene ID into an element of a JSONArray.
However, when I do the above, the column headers are not present in the array:
try{
BufferedReader reader = new BufferedReader(new FileReader(filepath));
json = "";
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null ) {
if (line.contains("Solyc02g065040")){
sb.append(line);
sb.append("\n");
System.out.println(sb);
}
else{
//do nothing
}
}
json = sb.toString();
System.out.println(json);
reader.close();
String [] gffArray = json.split("\n");
System.out.println(gffArray);
JSONArray jsArray = new JSONArray();
for (int i = 0; i < gffArray.length; i++) {
jsArray.put(gffArray[i]);
}
System.out.println(jsArray);
The output looks like this:
["SL3.0ch02\tmaker_ITAG\tgene\t36723123\t36723359\t.\t-\t.\tID=gene:Solyc02g065040.1;Alias=Solyc02g065040;Name=Solyc02g065040.1;length=236"]
Whereas I wanted it to look like this, retaining headers:
["seqname":"SL3.0ch02", "source":"maker_ITAG","feature":"gene", "start":"36723123", "end":"36723359","attribute":"ID=gene:Solyc02g065040.1;Alias=Solyc02g065040;Name=Solyc02g065040.1;length=236"]
I need it to be like this so that I can populate a table in javafx according to these by saying:
(jsArray.getJSONObject(i).getString("seqname"))
(jsArray.getJSONObject(i).getString("gene"))
Any help would be appreciated, thanks.