Question: Read a fasta file | Java
0
gravatar for ozdavidd
10 months ago by
ozdavidd0
ozdavidd0 wrote:

Hey, im in my final project for fiding hidden repeats in DNA sequence. I have to read a fasta file and get only the sequence without the genom's name, which starts with '>' and save it into a string. Whish you guys could help me Thanks

file java fasta • 943 views
ADD COMMENTlink modified 10 months ago by Hugo150 • written 10 months ago by ozdavidd0

what have you tried ?

ADD REPLYlink written 10 months ago by Pierre Lindenbaum116k

I know how to read a regular file, but I dont know what should indicate me to start reading the nucleotides. The question is - when the gonome name ended? So I cant really write something

ADD REPLYlink modified 10 months ago • written 10 months ago by ozdavidd0

Thank you very much.

ADD REPLYlink written 10 months ago by ozdavidd0
2
gravatar for Pierre Lindenbaum
10 months ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum116k wrote:

a solution:

ADD COMMENTlink written 10 months ago by Pierre Lindenbaum116k
0
gravatar for vmicrobio
10 months ago by
vmicrobio240
vmicrobio240 wrote:

Hi ozdavidd,

you may try this :

private void readFastaFile(File fastaFile) {
    InputStream flux;
    String line;
    try {
        flux = new FileInputStream(fastaFile);
        InputStreamReader lecture = new InputStreamReader(flux);
        BufferedReader buff = new BufferedReader(lecture);
        int lineNb = 0;
        StringBuilder sb = new StringBuilder();
        while ((line = buff.readLine()) != null){
            if (lineNb == 0) {
                this.header = line;
            }
            else {
                sb.append(line);
            }
            lineNb++;
        }
        this.sequence = sb.toString();
        buff.close();
    }
    catch(Exception e) {
        e.printStackTrace();
    }
}
ADD COMMENTlink written 10 months ago by vmicrobio240

Thanks for comment. what sould I put in

this.header = line;

ADD REPLYlink written 10 months ago by ozdavidd0

you can create a class FastaSequence containing the code above, add a 'getHeader' and 'getSequence' and then return only the sequence for your use

ADD REPLYlink written 10 months ago by vmicrobio240

What in this code indicates u for the start of the nucleotides?

ADD REPLYlink written 10 months ago by ozdavidd0
0
gravatar for Hugo
10 months ago by
Hugo150
Universidade de Vigo, Ourense (Spain)
Hugo150 wrote:

You may have a look at SEDA (http://www.sing-group.org/seda/), which also provides a Java API for easily manipulation of FASTA sequences (https://github.com/sing-group/seda).

ADD COMMENTlink written 10 months ago by Hugo150
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1019 users visited in the last hour