-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
68 lines (56 loc) · 1.63 KB
/
Main.java
File metadata and controls
68 lines (56 loc) · 1.63 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
import java.util.Map;
public class Main {
static char qualityChar = 'I';
static String qualString;
static int readLength;
static int readShift;
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception
{
/*
* args[0] = input fasta
* args[1] = read length
* args[2] = read shift
*/
Map<String,String> seqs;
try{
seqs = FASTAParser.parseDNA(args[0]);
readLength = Integer.parseInt(args[1]);
readShift = Math.max(Integer.parseInt(args[2]),1);
}
catch(Exception e)
{
System.err.println("Usage: java -jar Genome2Reads.jar input.fasta read_length[Int] read_shift[int] > out.fastq");
System.err.println("Example: java -jar Genome2Reads.jar genome.fasta 100 1 > reads.fastq");
System.err.println("read_length: length of the reads generated");
System.err.println("read_shift: tiling density; next read starts at position i + read_shift");
System.err.println("An error occured when parsing the command line:");
e.printStackTrace();
return;
}
StringBuffer qualBuffer = new StringBuffer(readLength);
for(int i=0; i<readLength; i++)
qualBuffer.append(qualityChar);
qualString = qualBuffer.toString();
String seq;
String readname;
int count;
String readseq;
for(String name : seqs.keySet())
{
seq = seqs.get(name);
count = 1;
readname = name.split("[\\s]+")[0] + "_read_";
for(int i=0; i<seq.length()-readLength+1; i+=readShift)
{
readseq=seq.substring(i, i+readLength);
readseq=readseq.toUpperCase();
System.out.println("@"+readname+count+"\n"+readseq+"\n+\n"+qualString);
count++;
}
}
}
}