Results 1 to 10 of 10
Thread: Printing DNA data
- 04-03-2010, 05:16 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
Printing DNA data
Hello everyone I am taking a class in Java and I have to print DNA and underneath it I need to print a (*) where I find a match. Here is the output to be more clear.
>gi|116268103|ref|NP_001070736.1| zinc finger FYVE domain-containing protein 19 [Homo sapiens]
contains the zinc finger site: CSGCLSFSAAVPRTGNTQQKVCKQC
at locations:
103 128
Java Code:MNYDSQQPPLPPLPYAGCRRASGFPALGRGGTVPVGVWGGAGQGREGRSW GEGPRGPGLGRRDLSSADPAVLGATMESRCYGCAVKFTLFKKEYGCKNCG RAFCSGCLSFSAAVPRTGNTQQKVCKQCHEVLTRGSSANASKWSPPQNYK ************************* KRVAALEAKQKPSTSQSQGLTRQDQMIAERLARLRQENKPKLVPSQAEIE ARLAALKDERQGSIPSTQEMEARLAALQGRVLPSQTPQPAHHTPDTRTQA QQTQDLLTQLAAEVAIDESWKGGGPAASLQNDLNQGGPGSTNSKRQANWS LEEEKSRLLAEAALELREENTRQERILALAKRLAMLRGQDPERVTLQDYR LPDSDDDEDEETAIQRVLQQLTEEASLDEASGFNIPAEQASRPWTQPRGA EPEAQDVDPRPEAEEEELPWCCICNEDATLRCAGCDGDLFCARCFREGHD AFELKEHQTSAYSPPRAGQEH
if you see where the stars are that's what I need to accomplish, I can print the data but how do I go about printing things underneath a string. Here is the code that would generate the data.
*Java Code:/* 3)Modification the print out of the sequence to include a label underneath the zinc finger consensus sequence. */ import java.util.*; import java.io.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class hwk4_3 { public static void main(String[] args) { try{ ArrayList<String> a = new ArrayList<String>(); // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("zinkFinger.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String seqLine; //Read File Line By Line while ((seqLine = br.readLine()) != null) { //adds the lines of the file to this array //System.out.println("\n " + seqLine ); a.add(seqLine); }in.close(); String listString = ""; for (String s : a) { listString += s +"\n\n"; } //Sets the first header to be printed out. int fd = listString.indexOf(">"); int endheader = listString.indexOf("]"); endheader++; //sets the first sequence to be printed and parsed int endheader2 = listString.indexOf("]"); endheader2++; int sd = listString.indexOf(">", endheader2 ); do { //Separates all headers from the sequence for print. String header = listString.substring(fd, endheader); fd = listString.indexOf(">", endheader); endheader = listString.indexOf("]", fd); endheader++; /////////////////////////////////////////////////// //separates all the sequences from the headers for print. String subseq = listString.substring( endheader2, sd ); endheader2 = listString.indexOf("]", endheader2); sd = listString.indexOf(">", endheader2++); //Pattern match of the sequences Pattern p = Pattern.compile ("C[A-Z]{2}C[A-Z]{17}C[A-Z]{2}C"); Matcher m = p.matcher(""); m.reset( subseq ); //reset the input if ( m.find() ) { //Header print of the match. System.out.print("\n " + header); for (int i = 0; i<=10 //The pattern and the location print of the match. System.out.print("\n Contains the zinc finger site:" + m.group()); System.out.print("\n At locations:\n " + m.start() + " " + m.end() +"\n"); System.out.print(" " + m.group().replaceAll("************************")); //The actual sequence print of the match. //System.out.print(" " + subseq); } }while( sd != -1 ); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
I am using replaceAll() but that is not the solution. Can someone please help?
Thank you so much,
Hernando Cadet
Moderator Edit: Code tags addedLast edited by Fubarable; 04-03-2010 at 07:09 PM. Reason: Moderator Edit: Code tags added
- 04-04-2010, 01:10 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you please elaborate more your matching criteria. I'm not clear with that. What asterisk you want to find?
- 04-05-2010, 02:00 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
DNA matching
okay so the matching criteria is a zing finger or a regular expression.
Pattern p = Pattern.compile ("C[A-Z]{2}C[A-Z]{17}C[A-Z]{2}C");
Matcher m = p.matcher("");
Above is the regular expression. Once I find a match on the sequence, I need to show the match by printing asterisks underneath the match.
I am thinking two dimensional array but I am not sure.
Thanks;
-
Or a StringBuilder object could work -- or even a simple second String, either one. You'd add a " " if no match, and add "*" if in the region of the match.
- 04-05-2010, 03:18 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Looking at OPs requirement temporary string variable could be enough.
- 04-05-2010, 03:49 AM #6
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
"StringBuilder object could work" -- or even a simple second String, either one. You'd add a " " if no match, and add "*" if in the region of the match.
Looking at OPs requirement temporary string variable could be enough.
All suggestions seem to make sense but looking at the code above can you please give me an example of how I would be using what you just suggested?
Thank you so much;
:cool:
- 04-05-2010, 03:56 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Initialize a string variable. In each line of your original string, validate your pattern. Do necessary changes on it if any. Then concatenate with the temporary string.
- 04-05-2010, 04:09 AM #8
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
okay so I will be using the Array still, right? Let me try it with the array.
- 04-05-2010, 04:26 AM #9
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
Hello guys I must say I am new to java and is kind of hard to understand the concepts for me.
- 04-05-2010, 01:20 PM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
data structure and data base??
By ahmed13 in forum Advanced JavaReplies: 8Last Post: 03-27-2009, 05:48 AM -
how to store the data in data base
By eclipse3.4ide in forum New To JavaReplies: 5Last Post: 02-03-2009, 04:25 AM -
error while retrieving data from data base
By kirtesh4u in forum New To JavaReplies: 5Last Post: 11-15-2008, 04:10 PM -
Data Pipeline 2 - Data Transformation Toolkit for Java Released
By dele in forum Java SoftwareReplies: 0Last Post: 10-31-2008, 02:13 PM -
Data Sorting in a .data file using java
By stutiger99 in forum New To JavaReplies: 2Last Post: 10-08-2008, 02:52 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks