Question

Programming language: Java m: substring length n: input strings d: Hamming distance (mismatch) I: Number of...

Programming language: Java

m: substring length

n: input strings

d: Hamming distance (mismatch)

I: Number of letters in Sample input string (s1, s2, s3)

Strings consists of: A, C, G, and T

Example outputs: Generate all possible possibilities of length m(4) using the values A, C, G, and T. EX possibilites: {A,A,A,A A,A,A,C.... G,G,G,G} and find all the possible combinations that have the same sequence with a hamming distance of 1 (only 1 difference)

Given n input strings of length l (i.e., there are l alphabets in each input string),

(a) develop an algorithm (i.e., a simple list of step-by-step recipe on how to create outputs from the given inputs) to find all substrings of length m that are common in all n input string with at most d mismatch (i.e., hamming distance of d). The set of possible alphabets in the input strings consists of A, C, G, and T.

Example #1: (n=3, l=10, m=4, and d=1)

Sample input strings: S1: ACTGACGCAG, S2: TCACAACGGG, and S3: GAGTCCAGTT

Expected Outputs: ACAG, CAGA, CCCA, and TCAG

Example #2: (n=3, l=10, m=4, and d=1)

Sample input strings: S1: GGAGGCCTGA, S2: TCAAGTCACA, and 3: GATCTTCAGG

Expected Outputs: AAGG, GGTC, GTCT, CAGA, CAGG, CATG, CCAG, CTCA

0 0
Add a comment Improve this question Transcribed image text
Answer #1


import java.util.Scanner;


public class JavaApplication {

  
// Hamming distance match or not
  
public static boolean getStringMatch(int n,int l,int m,int d,String [] s,String str){
boolean ret=false;
int count=0;// this part store the number of Hamming distance from every string
int d_=0;// count distance
  
  
// each string
  
for(int i=0;i<n;i++){
  
// store string
String curStr=s[i];
  
// each string match the substring of length m
for(int j=0;j<l-m+1;j++){
d_=0;
  
  
// match each character
for(int k=0;k<m;k++){
  
// if not match
// increase distance
if(curStr.charAt(j+k)!=str.charAt(k)){
d_++;
}
}
  
  
// if distance <d
// increase count and break
// because it is found
if(d_<=d){
  
count++;
break;
}
  
}
}
  
// finaly check str match with all strings
if(count==n){
ret=true;
}
  
  
return(ret);
}

  
  
public static void main(String[] args) {
  
// to input from user
  
Scanner sc= new Scanner(System.in);
  
int m,n,d,l;
  
System.out.print("Enter value of n : ");
n=sc.nextInt();
  
System.out.print("Enter value of l : ");
l=sc.nextInt();
  
System.out.print("Enter value of m : ");
m=sc.nextInt();
  
System.out.print("Enter value of d : ");
d=sc.nextInt();

// to store user inputs
  
String [] list=new String[n];
  
// user strings
for(int i=0;i<n;i++){
System.out.print("\nEnter input String "+(i+1)+" : ");
list[i]=sc.next();
  
}
sc.close();
  
// size of all combination of string of length m
int pVal=(int)Math.pow(m, m);
  
String [] combinations=new String[pVal];
  
// initialize
  
for(int i=0;i<pVal;i++){
combinations[i]="";
}
  
  
  
char [] chs=new char[4];
  
  
// each characters
chs[0]='A';
chs[1]='G';
chs[2]='C';
chs[3]='T';
  
// to index
  
int x=0,y=0,z=0,w=0;
  
// create combination of 4 characters
  
  
for(int i=0;i<pVal;i++){
  
  
// geting corresponding index
  
x=i/(int)Math.pow(m, 3);// for first index
y=(i/(int)Math.pow(m, 2))%4;// for 2 nd index
z=(i/m)%4;// for 3 rd index
w=i%4; // for last index
  
combinations[i]+=chs[x];
combinations[i]+=chs[y];
combinations[i]+=chs[z];
combinations[i]+=chs[w];
  
}
  
System.out.print("\n\nPossible outputs are : ");
  
// outputs
  
for(int i=0;i<pVal;i++){
  
  
// if distance found , then print
  
if(getStringMatch(n,l,m,d,list,combinations[i])==true){
System.out.print(combinations[i]+" ");
}
  
}
  
System.out.println();
}
  
}

Add a comment
Know the answer?
Add Answer to:
Programming language: Java m: substring length n: input strings d: Hamming distance (mismatch) I: Number of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA PROGRAMMING I want to make sure I have learned the compareto statements correct and other...

    JAVA PROGRAMMING I want to make sure I have learned the compareto statements correct and other things. This was on my lecture slide today and I don't understand the compare to regarding how they get values for the strings. Please answer the following. Suppose that s1, s2, and s3 are three strings, given as follows String s1 = "Welcome to Java". String s2 = "Programming is fun". String s3- "Welcome to Java" hat are the results of the following expressions?...

  • Write a Java program for all items in Question Use System.out.println() for each resulting string. Let...

    Write a Java program for all items in Question Use System.out.println() for each resulting string. Let s1 be " Welcome " and s2 be " welcome ". Write the code for the following statements: a. Check whether s1 is equal to s2 and assign the result to a Boolean variable isEqual. b. Check whether s1 is equal to s2, ignoring case, and assign the result to a Boolean variable isEqual. c. Compare s1 with s2 and assign the result to...

  • A java program for this question please! Recursion: A word is considered elfish if it contains...

    A java program for this question please! Recursion: A word is considered elfish if it contains the letters: e, l, and f in it, in any order. For example, we would say that the following words are elfish: whiteleaf, tasteful, unfriendly, and waffles, because they each contain those letters. Write a recursive method called elfish(), that, given a word, tells us whether or not that word is elfish. The signature of the method should be: public static boolean elfish(String word)...

  • Example 18.7 The Mistuned Piano Strings Two identical piano strings of length 0.775 m are each tuned exactly to 400 Hz....

    Example 18.7 The Mistuned Piano Strings Two identical piano strings of length 0.775 m are each tuned exactly to 400 Hz. The tension in one of the strings is then increased by 1.0%. If they are now struck, what is the beat frequency between the fundamentals of the two strings? SOLVE IT Conceptualize As the tension in one of the strings is changed, its fundamental frequency changes. Therefore, when both strings are played, they will have different frequencies and beats...

  • Programming project in Java: You are allowed to use the following methods from the Java API:...

    Programming project in Java: You are allowed to use the following methods from the Java API: class String length charAt class StringBuilder length charAt append toString class Character any method Create a class called HW2 that contains the following methods: 1. isAlphabeticalOrder takes a String as input and returns a boolean: The method returns true if all the letters of the input string are in alphabetical order, regardless of case. The method returns false otherwise. Do not use arrays to...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

  • DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an...

    DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an unknown number of cells filled with data. As before, the array will already be filled with strings, some of which contain the string "Angela". You will create a method called countItUp which returns and integer array containing the number of times each of the letters in my name occur within the strings within this array. For example, if the input array was wordFun =...

  • DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an...

    DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an unknown number of cells filled with data. As before, the array will already be filled with strings, some of which contain the string "Angela". You will create a method called countItUp which returns and integer array containing the number of times each of the letters in my name occur within the strings within this array. For example, if the input array was wordFun =...

  • Need Table F and how you do the calculations I. EXPERIMENT 1.10: STANDING WAVES ON STRINGS...

    Need Table F and how you do the calculations I. EXPERIMENT 1.10: STANDING WAVES ON STRINGS A. Abstract Waves on a string under tension and fixed at both ends result in well-defined modes of vibration with a spectrum of frequencies given by the formula below B. Formulas fn=n (*), n= 1, 2, 3,... v= T where fr is the frequency of the nth standing wave mode on the string of length L, linear mass density y, and under tension T,...

  • Please help me with the coding for LL(1)!! The given grammar was: P → PL |...

    Please help me with the coding for LL(1)!! The given grammar was: P → PL | L L → N; | M; | C N → print E M → print "W" W → TW | ε C → if E {P} | if E {P} else {P} E → (EOE) | V (note: this has a variable O) O → + | - | * V → 0 | 1 | 2 | 3 (note: this has a terminal...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT