-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddChrTest.java
51 lines (43 loc) · 1.45 KB
/
AddChrTest.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
package fionaApp;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class AddChrTest{
public String combinearraystring(String[] arr_name) {
String newline = new String();
for (int i = 0; i < arr_name.length; i++) {
newline = newline.concat(arr_name[i]);
newline = newline.concat("\t");
}return(newline);
}
public void modifyFile(String filepath,String resultpath) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filepath)));
File newBEDfile= new File(resultpath);
BufferedWriter bw = new BufferedWriter(new FileWriter(newBEDfile));
String str= "chr";
String regEx1="Pt";
String regEx2="Mt";
String newline =null;
for (String line = br.readLine(); line != null; line = br.readLine()) {
if ((!line.startsWith(regEx1)) && (!line.startsWith(regEx2))) {
newline = line;
}else if (line.startsWith(regEx1)) {
newline = line.replaceFirst(regEx1, "p");
} else {
newline = line.replaceFirst(regEx2, "m");
}
bw.write(str+newline);
bw.newLine();
}
bw.close();
br.close();
}
public static void main(String[] args) throws IOException {
AddChrTest object= new AddChrTest();
object.modifyFile("G:\\bamBed\\untri\\tdrZp4.bed","G:\\bamBed\\untri\\tdrZp4Chr.bed");
}
}