-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiSearchRevised.java
More file actions
106 lines (92 loc) · 3.74 KB
/
Copy pathMultiSearchRevised.java
File metadata and controls
106 lines (92 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MultiSearchRevised
{
public static void main(String[] args)
{
String filePath ="C:\\Users\\sami0\\OneDrive\\Documents\\Downloads\\KEGGdatabase.txt"; // Change this to the path of your file
String charactersToSearch = "agtc"; // Characters you want to search for
// Initialize counters for each character
int countA = 0, countT = 0, countC = 0, countG = 0, countat = 0, countgc = 0;
try (BufferedReader br = new BufferedReader(new FileReader(filePath)))
{
String line;
String wordToFind1 = "at";
String regex1 = Pattern.quote(wordToFind1) ;
Pattern pattern1 = Pattern.compile(regex1);
String wordToFind2 = "gc";
String regex2 = Pattern.quote(wordToFind2) ;
Pattern pattern2 = Pattern.compile(regex2);
Pattern pattern = Pattern.compile("[" + charactersToSearch + "]"); // Create regex pattern
for(int i=1;i<=30;i++)
{
while ((line = br.readLine()) != null)
{
if (line.trim().isEmpty())
{
break;
}
Matcher matcher1 = pattern1.matcher(line);
while(matcher1.find())
{
countat++;
}
Matcher matcher2 = pattern2.matcher(line);
while(matcher2.find())
{
countgc++;
}
Matcher matcher = pattern.matcher(line);
while (matcher.find())
{
char foundChar = matcher.group().charAt(0);
//System.out.println(foundChar);
switch (foundChar)
{
case 'a':
countA++; break;
case 't':
countT++; break;
case 'c':
countC++; break;
case 'g':
countG++; break;
}
}
}
float totl=countA+countT+countC+countG;
float perA=(countA/totl)*100;
float perT=(countT/totl)*100;
float perC=(countC/totl)*100;
float perG=(countG/totl)*100;
// Display the count of each character
System.out.println("Sequence "+i);
System.out.println("Total content : " + totl );
System.out.print("A content : " + countA+" " );
System.out.println("A content(%) : " + perA + "%");
System.out.print("T content : " + countT +" ");
System.out.println("T content(%) : " + perT + "%");
System.out.print("C content : " + countC +" ");
System.out.println("C content(%) : " + perC + "%");
System.out.print("G content : " + countG +" ");
System.out.println("G content(%) : " + perG + "%");
System.out.println("No. of AT dimers : " + countat );
System.out.println("No. of GC dimers : " + countgc );
System.out.println();
countA = 0;
countT = 0;
countC = 0;
countG = 0;
countat = 0;
countgc = 0;
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}