-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashSearch.java
45 lines (41 loc) · 1.31 KB
/
HashSearch.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
package fionaApp;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
public class HashSearch {
public static void main(String[] args) throws IOException {
String geneIDfile = "D:/lotus/mfanwID.bed";
List<String> geneIDList =ToolsList.getStringList(geneIDfile);
HashMap<String, Integer> geneIDhash = new HashMap<String, Integer>();
int code =0;
for (int i = 0; i < geneIDList.size(); i++) {
code++;
String str = geneIDList.get(i);
geneIDhash.put(str, code);
}
String targetfileString = "D:/lotus/ref_Chinese_Lotus_1.1_top_level.gff3";
String resultFile = "D:/lotus/ChineseLotusSelected.gff3";
FileWriter fWriter = new FileWriter(resultFile);
BufferedWriter fWriterBuffer = new BufferedWriter(fWriter);
FileReader file = new FileReader(targetfileString);
BufferedReader filein = new BufferedReader(file);
String line = null;
int lineno = 0;
while ((line = filein.readLine()) != null) {
String gene = line.split("\t")[0];
if (geneIDhash.containsKey(gene)) {
lineno++;
fWriterBuffer.write(line);
fWriterBuffer.newLine();
}
}
fWriterBuffer.close();
filein.close();
System.out.println(lineno);
}
}