Results 1 to 10 of 10
  1. #1
    hcadet is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Cool 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 added
    Last edited by Fubarable; 04-03-2010 at 08:09 PM. Reason: Moderator Edit: Code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Can you please elaborate more your matching criteria. I'm not clear with that. What asterisk you want to find?

  3. #3
    hcadet is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Smile 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;

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  6. #6
    hcadet is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Question

    "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:

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  8. #8
    hcadet is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default

    okay so I will be using the Array still, right? Let me try it with the array.

  9. #9
    hcadet is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default

    Hello guys I must say I am new to java and is kind of hard to understand the concepts for me.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by hcadet View Post
    Hello guys I must say I am new to java and is kind of hard to understand the concepts for me.
    That's why we helped you here. But you must put some effort first of all. If you comes with any error let us know. What you've done so far?

Similar Threads

  1. data structure and data base??
    By ahmed13 in forum Advanced Java
    Replies: 8
    Last Post: 03-27-2009, 06:48 AM
  2. how to store the data in data base
    By eclipse3.4ide in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 05:25 AM
  3. error while retrieving data from data base
    By kirtesh4u in forum New To Java
    Replies: 5
    Last Post: 11-15-2008, 05:10 PM
  4. Replies: 0
    Last Post: 10-31-2008, 03:13 PM
  5. Data Sorting in a .data file using java
    By stutiger99 in forum New To Java
    Replies: 2
    Last Post: 10-08-2008, 03:52 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
  •