Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLS help me java programming language The similarity between DNA sequences is im

ID: 3905465 • Letter: P

Question

PLS help me java programming language

The similarity between DNA sequences is important for biological research. In this case, you are asked to find similarities between the DNA sequences given as inputs and to keep them in a file.

On each line of the DNA.txt file;
<Alive name> <space> <DNA sequence>

The similarities between DNA sequences after reading them
Hamming distance in the form of simple calculation is required. (DNA sequences are different in nature, but they are different lengths.
For the question, let's say they are all the same length.)

D 1 = AT GAGCT ACG
D 2 = AT CGCCT ACA

Hamming distance between sequences (the same nucleic acid in the same index is underlined)

H(D1,D2)=NE/L=6/10=0,6

You have to resemble this (S (D 1, D 2)) as follows.

he format of each line of the similarity.txt file should be as follows:
<alive name with DNA sequence D1> <space> <living name with DNA sequence D2> <space> S (D 1, D 2)

Explanation / Answer


Given below is the code for the question. Since I don't have your same input file DNA.txt, I created a small file with just 2 DNA sequences
You may test with your file. You should not have any issues.

To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
NOTE: Please make sure you place your input file in the correct folder. If using eclipse, the file should be in the project directly and NOT INSIDE src folder.

input file DNA.txt
=======
A AT GAGCT ACG
B AT CGCCT ACA


DNA.java
=====

public class DNA {
private String livingName;
private String dnaSequence;

public DNA()
{
livingName = "";
dnaSequence = "";
}

public DNA(String name, String dna)
{
livingName = name;
dnaSequence = dna;
}
public String getLivingName() {
return livingName;
}

public void setLivingName(String livingName) {
this.livingName = livingName;
}

public String getDnaSequence() {
return dnaSequence;
}

public void setDnaSequence(String dnaSequence) {
this.dnaSequence = dnaSequence;
}

public int getDNALength()
{
int length = 0;
for(int i = 0; i < dnaSequence.length(); i++)
{
if(dnaSequence.charAt(i) != ' ')
length++;
}
return length;
}

public double getHammingDistance(DNA other)
{
double matched = 0;
if(getDNALength() == other.getDNALength())
{
for(int i = 0; i < dnaSequence.length(); i++)
{
if(dnaSequence.charAt(i) != ' ' && dnaSequence.charAt(i) == other.dnaSequence.charAt(i)) //matching
{
matched++;
}
}
}
return matched / getDNALength();
}
}

ProcessDNA.java
========
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;


public class ProcessDNA {


public static void main(String[] args) {
String filename;
String livingName, dnaSeq;
Scanner keyboard = new Scanner(System.in);
Scanner infile = null;

System.out.print("Enter input filename containing DNA sequence data: ");
filename = keyboard.nextLine();

try {
infile = new Scanner(new File(filename));
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
System.exit(1);
}

ArrayList<DNA> dnas = new ArrayList<DNA>();
while(infile.hasNext())
{
DNA d = new DNA(infile.next(), infile.nextLine());
dnas.add(d);
}

infile.close();


//generate output file
String outFilename = "similarity.txt";
DNA d1, d2;

try {
PrintWriter outFile = new PrintWriter(outFilename);
for(int i = 0; i < dnas.size(); i++)
{
d1 = dnas.get(i);
for(int j = 0 ; j < dnas.size(); j++)
{
if(i < j) //don't perform similarity check with itself, also reverse order is not needed S(D1, D2) is same as S(D2, D1)
{
d2 = dnas.get(j);
outFile.printf("%s %s %.2f " , d1.getLivingName() , d2.getLivingName() , d1.getHammingDistance(d2));
}
}
}

outFile.close();

System.out.println("Please REFRESH project and check output file " + outFilename );

} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}

}

}

output file similarity.txt
======
A B 0.60

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote