I am writing a java progam and I am stuck. I need to read a fasta file. parse it out by sequence ID number ( ex:by05f64.y1). Also I then need to create a loop to prompt an input line to enter a sequence ID, and if it exist prints out the sequence.
Here is the file
>by05e12.y1|BF724769
CCGCCGTGCGCCCAGCCAGCCATGGGGAAGATCACCCTCTACGAGGACCG
GGGCTTCCAGGGCCGCCACTACGAATGCAGCAGCGACCACCCCAACCTGC AGCCCTACTTGAGGAATTCGAACTCGGCGCGCGTGGACAGCGGCTGCTGG ATGCTCTATGAGCAGCCCAACTACTCGGGCCTCCAGTACTTCCTGCGCCG CGGCGACTATGCCGACCACCAGCAGTGGATGGGCCTCAGCGACTCGGTCC GCTCCTGCCGCCTC
----------
>by09f05.y1|BF73659
CACCAGCTCAGCACCGCCGTGCGCCCAGCCAGCCATGGGGAAGATCACCC TCTACGAGGACCGGGGCTTCCAGGGCCGCCACTACGAATGCAGCAGCGAC CACCCCAACCTGCGGAATTCCTTGAGCCGCTGCAACTCGGCGCGCGTGGA CAGCGGCTGCTGGATGCTCTATGAGCAGCCCAACTACTCGGGCCTCCAGT ACTTCCTGCGCCGCGGCGACTATGCCGACCACCAGCAGTGGATGGGCCTC AGCGACTCGGTCCGCTCCTGCCGCCTCATCCCCCACTCTGGCTCTCACAG GATCAGACTCTATGAGGAATTCCCCTACAGAGGCCAGATGATAGAGTTCA CTGAGGACTGCTCCTGTCTTCAGGACCGCTTCCGCTTCAATGAAATCCAC TCCCTCAACGTGCTGGAGGGCTCCTGGGTCCTCTACGAGCTGTCCAACTA
CCGAGGACGGCAGTACCTG
Here is what I have so far
import java.io.*; import java.util.*; public class hmwk4_1{
public static void main(String args[]) {
BufferedReader bufRead = new BufferedReader(new FileReader("dna.txt"));
{ String myLine; if (myLine.startsWith(">")) { String[] seqInfo = myLine.substring(1).split(" "); String seqId = seqInfo[0]; (seqId.equals(seq)) //it matches with the user's input {
//read the rest of the lines until we find another '>' or the file finishes
while ( ((myLine = bufRead.readLine()) != null) && (!myLine.startsWith(">")))
{
System.out.println(myLine);
} } break; //out of your while loop since we found the sequence
} } }
public static void main1(String args[]) {
Scanner input = new Scanner(System.in);
hmwk4_1 Myhmwk4_1= new hmwk4_1();
/Prompt user to enter a DNA sequence
System.out.println("Please enter a sequence ID: ");
String sequence = input.nextLine();
System.out.println();
} }
So the intent is after java reads and parses the file. The user will enter the sequence ID number such as (>by05e12.y1|BF724769
) and if the sequence id exist the sequence will print out. If not it will print out an error. However I am still receiving error here [seqId.equals(seq))] seq cannot be resolved. Can someone help
thanks!, I edited the code a little and now I am getting that userId cannot be resolved into a variable
I got ! , just needed to string userId=null
Hello,
can you share the final code with us please?
Thanks!