Help on a java programming problem
Given two sequences, where one is a substring of the other, we
define a substring alignment by matching the substring with the
longer sequence and placing gaps everywhere else. For example if
the input is ACCTGTAGG and TGT then the substring alignment
is
ACCTGTAGG
---TGT---
i need help designing program that prints the substring alignment of two unaligned sequences. If no substring alignment exists then the program should print "No alignment found"...im puzzled over this situation
Any advice on how to start?
Thank in advance
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
// SubstringAlignment.java
import java.util.Scanner;
public class SubstringAlignment {
// method to find substring alignment of two strings and print it
public static void printSubstringAlignment(String s1, String s2) {
// checking if s1 is not a substring of s2 and s2 is not a substring of
// s1
if (!s1.contains(s2) && !s2.contains(s1)) {
// no alignment
System.out.println("No alignment found");
} else {
char align[];
// checking if s1 contains s2 (s1 will be the bigger string)
if (s1.contains(s2)) {
// finding index of occurrance of s2 in s1
int index = s1.indexOf(s2);
// converting s1 into a char array
align = s1.toCharArray();
// filling all elements before index in align array with '-'
for (int i = 0; i < index; i++) {
align[i] = '-';
}
// filling all elements after index+s2.length in align array
// with '-'
for (int i = index + s2.length(); i < align.length; i++) {
align[i] = '-';
}
// displaying s1
System.out.println(s1);
// displaying alignment after converting align to String
System.out.println(new String(align));
} else {
// doing the same with s1 and s2 swapped.
int index = s2.indexOf(s1);
align = s2.toCharArray();
for (int i = 0; i < index; i++) {
align[i] = '-';
}
for (int i = index + s1.length(); i < align.length; i++) {
align[i] = '-';
}
System.out.println(s2);
System.out.println(new String(align));
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//asking and reading two strings
System.out.print("Enter first String: ");
String s1 = scanner.nextLine();
System.out.print("Enter second String: ");
String s2 = scanner.nextLine();
//printing substring alignment if exists
printSubstringAlignment(s1, s2);
}
}
/*OUTPUT (multiple runs)*/
Enter first String: ACCTGTAGG
Enter second String: TGT
ACCTGTAGG
---TGT---
Enter first String: java programming is fun
Enter second String: is
java programming is fun
-----------------is----
Enter first String: very cool
Enter second String: this is a very cool phone
this is a very cool phone
----------very cool------
Enter first String: some text
Enter second String: some other text
No alignment found
Help on a java programming problem Given two sequences, where one is a substring of the...
Problem 2: Sequence similarity measure. Let 3 and y be two given DNA sequences, represented as strings with characters in the set {A, G, C,T}. The similarity measure of r and y is defined as the maximum score of any alignment of r and y, where the score for an alignment is computed by adding substitution score and deletion and insertion scores, as explained below. (Some operations have negative scores.) The score for changing a character T, into a...
java
Object Oriented Programming The assignment can be done individually or in teams of two. Submit one assignment per team of two via Omnivox and NOT MIO.Assignments sent via MIO will be deducted marks. Assignments must be done alone or in groups and collaboration between individuals or groups is strictly forbidden. There will be a in class demo on June 1 make sure you are prepared, a doodle will be created to pick your timeslot. If you submit late, there...
IN JAVA PLEASE HELP!
ALSO PLEASE ADD COMMENTS
Summary Build two classes (Fraction and Fraction Counter) and a Driver for use in counting the number of unique fractions read from a text file. We'll use the ArrayList class to store our list of unique Fraction Counters. Rather than designing a monolithic chunk of code in main like we did in the previous homework, we'll practice distributing our code into containers (called classes) that you will design specifically to tackle this...
can i get some help with this program
CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write a Java program that uses recursion to find all solutions to the n-Queens problem, for 1 Sns 15. (Students who took CMPS 12A from me worked on an iterative, non-recursive approach to this same problem. You can see it at https://classes.soe.ucsc.edu/cmps012a/Spring l8/pa5.pdf.) Begin by reading the Wikipcdia article on the Eight Queens puzzle at: http://en.wikipedia.org/wiki/Eight queens_puzzle In...
C++ Programming
Hi! Sorry for all the material attached. I simply need help in
writing the Facility.cpp file and the other files are included in
case they're needed for understanding. I was able to complete the
mayday.cpp file but am stuck on Facility. The following link
contains a tar file with the files provided by the professor. Thank
you so much in advanced!
http://web.cs.ucdavis.edu/~fgygi/ecs40/homework/hw4/
Closer.h:
#ifndef CLOSER_H
#define CLOSER_H
#include <string>
#include "gcdistance.h"
struct Closer {
const double latitude, longitude;...