-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.java
128 lines (107 loc) · 4 KB
/
Parser.java
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package identificationjava;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Parser {
String outputFile;
TreeMap<String,Organism> organisms = new TreeMap<>();
public Parser(String outputFile) {
super();
this.outputFile = outputFile;
organisms = OrganismHolder.getInstance().getOrganisms();
}
public void populateHits(){
String id ="";
final File folder = new File(outputFile);
File[] filesList = folder.listFiles();
Arrays.sort(filesList);
for (final File fileEntry : filesList) {
File output = new File(fileEntry.getPath());
Organism organism = new Organism(fileEntry.getName());
String fileName = fileEntry.getName();
//System.out.println(fileName);
if (organisms.containsKey(fileName))
{
//System.out.println(outputFile+ ": filename: "+fileName);
organism = organisms.get(fileName);
organism.newHits();
//System.out.println("new hits");
}
try (BufferedReader br = new BufferedReader(new FileReader(output))) {
String line;
Hit hit = new Hit();
while ((line = br.readLine()) != null) {
//process the line.
//System.out.println(line);
String value="";
Pattern p = Pattern.compile("\\>(.*?)\\<");
Matcher m = p.matcher(line);
while(m.find())
{
value = m.group(1); //is your string. do what you want
}
if (line.contains("</Hsp>")&&hit.positive!=hit.alignLength&&!organism.containsID(hit.getId())){
//System.out.println(organism.name+": "+ hit.id);
organism.addHit(hit);
}
else if (line.contains("<Hsp>")) {
hit = new Hit();
}
else if (line.contains("<Hit_id>")) {
id = value;
}
else if (line.contains("<Hsp_num>")) {
hit.setId(id);
}
else if (line.contains("<Hsp_gaps>")) {
hit.setGaps(Integer.parseInt(value));
}
else if (line.contains("<Hsp_score>")) {
hit.setScore(Integer.parseInt(value));
}
else if (line.contains("<Hsp_query-from>")) {
hit.setQueryFrom(Integer.parseInt(value));
}
else if (line.contains("<Hsp_query-to>")) {
hit.setQueryTo(Integer.parseInt(value));
}
else if (line.contains("<Hsp_hit-from>")) {
hit.setHitFrom(Integer.parseInt(value));
}
else if (line.contains("<Hsp_hit-to>")) {
hit.setHitTo(Integer.parseInt(value));
}
else if (line.contains("<Hsp_qseq>")) {
hit.setQuerySequence(value);
}
else if (line.contains("<Hsp_hseq>")) {
hit.setHitSequence(value);
}
else if (line.contains("<Hsp_positive>")) {
hit.setPositive(Integer.parseInt(value));
}
else if (line.contains("<Hsp_align-len>")) {
hit.setAlignLength(Integer.parseInt(value));
}
}
organisms.put(fileName, organism);
//System.out.print(organism.hits.size()+"\n");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.print(organisms.size()+"\n");
OrganismHolder.getInstance().setOrganisms(organisms);
}
}
}