Introduction Genomics DNA is the fundamental encoding of the
Solution
import java.util.*;
public class DNAsequence {
static Scanner sc=new Scanner(System.in);
static int countc=0;
static int countg=0;
static float fraction=0.0f;
public static void main(String[] args) {
boolean valid;
String DNA;
String DNA2;
while(true)
{
System.out.println(\"Enter DNA Sequence: \");
DNA = sc.nextLine();
if(chkvalid(DNA))
{
System.out.println(\"Sequence 1: \" + DNA);
countss(DNA);
countgg(DNA);
detfraction(DNA);
System.out.print(\"Complement: \");
complement(DNA);
break;
}
else
{
System.out.println(\"Please enter Valid DNA Sequence!\");
}
}
while(true)
{
System.out.println(\"Enter DNA2 Sequence: \");
DNA2 = sc.nextLine();
if(chkvalid(DNA2))
{
System.out.println(\"Sequence 1: \" + DNA2);
countss(DNA2);
countgg(DNA2);
detfraction(DNA2);
System.out.print(\"Complement: \");
complement(DNA2);
break;
}
else
{
System.out.println(\"Please enter Valid DNA Sequence!\");
}
}
bestalignment(DNA,DNA2);
}
private static boolean chkvalid(String DNA) {
if (DNA.matches(\"[ATGC]+\")) {
return true;
}else
return false;
}
public static void countss(String DNA){
for(int i=0;i<DNA.length();i++){
if(DNA.charAt(i)==\'C\')
countc++;
}
System.out.println(\"count of c:\"+countc);
}
public static void countgg(String DNA){
for(int i=0;i<DNA.length();i++){
if(DNA.charAt(i)==\'G\')
countg++;
}
System.out.println(\"count of g:\"+countg);
}
public static void detfraction(String DNA){
if(countc >=DNA.length()/2||countg>=DNA.length()/2)
fraction=0.5f;
System.out.println(\"cg ratio:\"+fraction);
}
public static void complement(String DNA){
String cp=\"\";
for(int i=0;i<DNA.length();i++){
if(DNA.charAt(i)==\'A\')
cp+=\'T\';
else if(DNA.charAt(i)==\'T\')
cp+=\'A\';
if(DNA.charAt(i)==\'C\')
cp+=\'G\';
else if(DNA.charAt(i)==\'G\')
cp+=\'C\';
}
System.out.println(cp);
}
public static void bestalignment(String DNA,String DNA2){
List<Integer>alist=new ArrayList<Integer>();
int bigs=0;
int add=0;
int s1=DNA.length();
int s2=DNA2.length();
int diff1=0;
int diff2=0;
if(s1>s2)
diff1=s1-s2;
else
diff1=s2-s1;
diff2=diff1;
int i=0;
while(i<=diff2){
for(int j=0;j<DNA2.length();j++){
char a=DNA.charAt(j+i);
char b=DNA2.charAt(j);
if(a==b)
add++;
}
alist.add(add);
add=0;
i++;
}
//System.out.println(alist);
for(int k=0;k<alist.size();k++){
if(alist.get(k)>bigs)
bigs=alist.get(k);
}
System.out.println(\"best alignment is:\"+bigs);
}
}
OUTPUT:
Enter DNA Sequence:
AATCTATA
Sequence 1: AATCTATA
count of c:1
count of g:0
cg ratio:0.0
Complement: TTAGATAT
Enter DNA2 Sequence:
AAGATA
Sequence 1: AAGATA
count of c:1
count of g:1
cg ratio:0.0
Complement: TTCTAT
[4, 1, 3]
best alignment is:4
OUTPUT:
Enter DNA Sequence:
CTAAGT
Sequence 1: CTAAGT
count of c:1
count of g:1
cg ratio:0.0
Complement: GATTCA
Enter DNA2 Sequence:
GT
Sequence 1: GT
count of c:1
count of g:2
cg ratio:0.5
Complement: CA
best alignment is:2



