Results 1 to 7 of 7
  1. #1
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default 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:
    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>
    The file is correct, I only need to make the program not to print the red line.
    I know why he prints it.
    But how do I remove it?

    Java Code:
    xD
    I anyone could help me it would be great. :)
    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.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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?

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    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:

    Java Code:
    boolean endFasta= false;
    // ...
    if (endFasta)
    	output1b.println("</fasta>"); 
    endFasta= true;
    kind regards,

    Jos

    edit: too slow again ... ;-)
    Last edited by JosAH; 02-28-2011 at 11:43 AM.
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Ha! Too slow :-P

  5. #5
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    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

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by masijade View Post
    Ha! Too slow :-P
    Yep, rub it in, rub it in ...

    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    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

  1. how can i remove a line from an ordinary text file?
    By jayeshsugunan in forum New To Java
    Replies: 2
    Last Post: 08-11-2010, 10:05 AM
  2. Remove a Blank Line from Text file
    By nitinverma in forum CLDC and MIDP
    Replies: 8
    Last Post: 06-15-2010, 06:12 AM
  3. remove variables/line in a text file
    By ddatta8 in forum New To Java
    Replies: 2
    Last Post: 01-04-2009, 03:05 AM
  4. how do i remove this line?
    By eyal1983 in forum NetBeans
    Replies: 6
    Last Post: 01-01-2009, 02:55 AM
  5. [SOLVED] Remove All Line from File
    By Mir in forum New To Java
    Replies: 41
    Last Post: 07-17-2008, 09:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •