Results 1 to 7 of 7
Thread: How to remove the 1 line....
- 02-28-2011, 11:02 AM #1
How to remove the 1 line....
I need a little help with my code.
I am reading in an file with an GeneID name, and under the a sequence.
I almost got the XML file I need.
And I also have another program to read the correct XML file.
But I have 1 little problem with the write XML program.
What my program writes is:
The file is correct, I only need to make the program not to print the red line.Java Code:<?xml version="1.0"?> <data> [COLOR="Red"]</fasta>[/COLOR] <fasta> <geneID>>Contig1</geneID> <sequentie>tgctttagtatatcattacttattttaatttagcttttatgtcacaaacttggtcacaat</sequentie> <sequentie>gtttaaacactcttagagacagtattcccctttctcaatatagtgtatggatacaaccct</sequentie> <sequentie>taaaagcacttgaaaacaacaacaccttatctttattagcacccaattcacaagttctta</sequentie> <sequentie>attacattaataaacacctaaaagctcaaatcaaaaatgcggttgcacaacacaacaaaa</sequentie> <sequentie>atttaaaaatttttataagtattgcatctaatcaaaatacccaacagcatatcactcctt</sequentie> <sequentie>tatttgaagactatacatttgataatttaatactgggcaatgccaatcaaatggcctatg</sequentie> <sequentie>gcgcaactaaacaaattgctgaaaatataaaaacctcgccctataatccttttattatct</sequentie> </fasta> <fasta> <geneID>>contig2</geneID> <sequentie>aaaaaaatcaaaatattaaagtgatttacgtacccttgatggattttgttagaaatatta</sequentie> <sequentie>cctctagcctgaggcacaatactattgaaaatattaaaactttttatcagtctgctgatt</sequentie> <sequentie>tattattggttgatgatattcatttaattgcaggaaaggaaaaatctcaagaagagtttt</sequentie> <sequentie>ttcatatttttaatttcctatttaatggtaaaaagcaaattatttttacctgcgatcaat</sequentie> <sequentie>cgcctaaaaacataaaatcactagaaaatcgtttaaaaactcgattttcacaaggtttaa</sequentie> <sequentie>acctacatttaactcccccagaattagagatgcgtgctgctattttgcttaaaaaatcac</sequentie> <sequentie>aaaataaaagaattaacatcaacttaacagaagacactgctttatttattgctactcata</sequentie> <sequentie>ttgcttctaatgttagagaccttgaaggggctcttcttaaactcaaagcttttgttgatt</sequentie> <sequentie>tttcaaaaataaatcatgattttatttctaaagagattgtcgaaacagccttaggtgatt</sequentie> </fasta> </data>
I know why he prints it.
But how do I remove it?
I anyone could help me it would be great. :)Java Code:xD
I must note that I will remove my programming code later, becose there is also 1 of my fellow students busy with programming in Java too. The rest has another programming language.Last edited by Lund01; 02-28-2011 at 12:05 PM.
- 02-28-2011, 11:31 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
created a boolean called "started" or something with the value false and then add the "</fasta>" in the loop only when started is true and set started to true at the end of the while loop. You also notice that the "geneid" lines have an extra ">", right? Try substring 1 instead of substring 0 if this is not what you want. Of course, this is also all assuming that the very first line in the file will be a line that starts with ">". If it is not you will have some free floating "sequence" lines, even if those first few lines contain only garbage, is that what you want?
Also, why are you not using the XML tools included in the JDK to structure and write the XML, rather than attempting to do it yourself?
- 02-28-2011, 11:39 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
A cheap hack would be to introduce a small boolean variable that is initially set to false. It determines whether or not that /fasta text will be printed:
kind regards,Java Code:boolean endFasta= false; // ... if (endFasta) output1b.println("</fasta>"); endFasta= true;
Jos
edit: too slow again ... ;-)Last edited by JosAH; 02-28-2011 at 11:43 AM.
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-28-2011, 11:41 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Ha! Too slow :-P
- 02-28-2011, 11:43 AM #5
I will have a look at the boolean. :)
When I started I didn't know about XML parsers, and I could not find much info on them. So I write one myself.
I have another program who needs to read an XML file, and with that one I did use a XML parser. But it would be great if this one also would work correct.
Thanks,
Lund
- 02-28-2011, 11:44 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
- 03-01-2011, 01:40 AM #7
Why not use an XML parsing package? Like Simple 2.4.1
Its easy, fast, and makes parsing xml a snap compared to DOM.
Similar Threads
-
how can i remove a line from an ordinary text file?
By jayeshsugunan in forum New To JavaReplies: 2Last Post: 08-11-2010, 10:05 AM -
Remove a Blank Line from Text file
By nitinverma in forum CLDC and MIDPReplies: 8Last Post: 06-15-2010, 06:12 AM -
remove variables/line in a text file
By ddatta8 in forum New To JavaReplies: 2Last Post: 01-04-2009, 03:05 AM -
how do i remove this line?
By eyal1983 in forum NetBeansReplies: 6Last Post: 01-01-2009, 02:55 AM -
[SOLVED] Remove All Line from File
By Mir in forum New To JavaReplies: 41Last Post: 07-17-2008, 09:44 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks