-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleSequence.java
More file actions
54 lines (47 loc) · 1.57 KB
/
SampleSequence.java
File metadata and controls
54 lines (47 loc) · 1.57 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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Random;
public class SampleSequence {
public static void main(String[] args) {
try {
LinkedList list = new LinkedList();
String fileName = args[0];
//String fileName = "C:\\Users\\tshaw\\Desktop\\Kelvin_Metagenomics\\SecondManuscript\\G1-7U-15_S11_L001_merge.fasta";
FileInputStream fstream = new FileInputStream(fileName);
DataInputStream din = new DataInputStream(fstream);
BufferedReader in = new BufferedReader(new InputStreamReader(din));
while (in.ready()) {
String name = in.readLine();
String seq = in.readLine();
list.add(name + "\n" + seq + "\n");
}
in.close();
String outputFile = args[1];
//String outputFile = "C:\\Users\\tshaw\\Desktop\\Kelvin_Metagenomics\\SecondManuscript\\G1-7U-15_S11_L001_merge_resample.fasta";
FileWriter fwriter = new FileWriter(outputFile);
BufferedWriter out = new BufferedWriter(fwriter);
int count = 5000;
int n = 1;
while (count > 0) {
Random rand = new Random();
int num = rand.nextInt(list.size());
String str = (String)list.get(num);
str = str.replaceAll(">", "");
str = ">G1.7U.15_" + n + " " + str;
n++;
out.write(str);
list.remove(num);
count--;
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}