Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: String counter

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default jcsp

    1 Parallel motif counting of strings.

    Recently, there has been some interest in Computational Linguistics and Bioinformatics in counting motifs in strings. In particular, counting all of the instances of a particular sub-string in a given string. For example, if we have a string ATATATAGTATA then there are 3 instances of the motif TATA in it.

    1.1 Implementation

    You will write a JCSP implementation that will count the number of occurences of a particular motif in a string, where the counting is distributed across the processes.
    Specification: The main program (runMotif) will accept as input the string to be examined, the motif to be searched and the number of processes npes that will perform the search. npes instances of the class motif will be constructed, each with a local copy of the string.
    Each instance of the class will examine a substring of the string and count the number of motifs that occur in each substring. Hint: think about the above example for say two processes. The number of motifs computed for each process must now be added together to compute a final sum.
    Note : you will not get any marks for performing a purely serial version of this code.




    can anyone help me to solve this?


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: jcsp

    Of coruse we can, what have you done so far and what are you stuck on?

    If you need something to get you started, here you go.

        public class MyClass {
     
            public static void main(String... arguments) {
                // Put your stuff here
            }
        }

    // Json

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: jcsp

    i'm dealing with making method for count motif..

    i made one main class and one other class to count the strings...

    method of counting motif... that's problem... help!!!

  4. #4
    Junior Member
    Join Date
    Dec 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default String counter

    public class stringP {
     
     
    	public static void main(String[] args) {
     
    		String name = "ATATATAGTATA";
    		char pattern = "TATA";
    	    int occurs = 0;
     
     
    	    for(int i=0; i < name.length(); i++) {
    	      char next = name.charAt(i);
    	      if(next == pattern) {
    	        occurs++;
    	      }
    	    }
     
    	    System.out.println("Occurs " + occurs + " time(s)");
     
     
    	}
     
    }


    i want to find string 'TATA' and count how many of them (include overlap)!
    help!!!
    Last edited by helloworld922; December 7th, 2009 at 11:01 PM.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: String counter

    Look into using the indexOf method of String.
    Defined as:
    public int indexOf(String str,
                       int fromIndex)
    You can use this method to iterate through the string quite easily
    You can do it a similar way that you outlined, just make sure you are comparing things that can be compared (eg char pattern = "TATA"; won't compile - do you want to compare Strings or character arrays?)

  6. #6
    Junior Member
    Join Date
    Dec 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: String counter

    i want to compare strings actually (TATA).
    im not sure how should i use indexOf method...
    can you apply that in my code?
    Last edited by chkang0130; December 7th, 2009 at 02:16 PM.

  7. #7
    Junior Member
    Join Date
    Dec 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default String counter - jcsp

    public class stringP {
     
     
    public static void main(String[] args) {
     
    String name = "ATATATAGTATA";
    char pattern = "TATA";
    int occurs = 0;
     
     
    for(int i=0; i < name.length(); i++) {
    char next = name.charAt(i);
    if(next == pattern) {
    occurs++;
    }
    }
     
    System.out.println("Occurs " + occurs + " time(s)");
     
     
    }
     
    }

    can anyone help me to make this as parallel (jcsp) ?
    Last edited by helloworld922; December 7th, 2009 at 11:01 PM. Reason: Please use [code] tags!

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: String counter

    indexOf gives you the position of the first occurrence of a string within a string, or -1 if it isn't found. Read the API for a full description. I'm not going to do it for you, but this should hopefully get you started...
    int loc = 0;
    loc = name.indexOf(pattern, loc);
    Now do this for the entire string (hint: use a loop)
    Last edited by helloworld922; December 7th, 2009 at 11:01 PM.

  9. #9
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: jcsp

    Here's a simple algorithm for doing that. fyi, this is how a Regex Engine works for constant strings.

    1. Start looking from the left (position 0)
    2. See if the letter matches the first letter in the string you want to match with (in your case, "T")
    3. If it does, keep matching subsequent letters until you form the string you want ("TATA")
    4. If it doesn't start step 2 again, but start with the second letter, third letter, etc. until you either have found the first instance of the string you want to match, or have reached the end of the string.

    To count up all the instances of the matching string, simply run the above algorithm but start each subsequent run on the start position of the previous matched string + 1

  10. #10
    Junior Member
    Join Date
    Dec 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: String counter

    See lecture notes, page 5.

    See you in class!
    Last edited by helloworld922; December 8th, 2009 at 12:43 PM. Reason: Please keep your comments respectful of other members

Similar Threads

  1. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM