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
extern crate getopts;
extern crate fasten;
extern crate rand;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use std::env;
use rand::{Rng,thread_rng};
use fasten::fasten_base_options;
fn main(){
let args: Vec<String> = env::args().collect();
let opts = fasten_base_options();
let matches = opts.parse(&args[1..]).expect("Error: could not parse parameters");
if matches.opt_present("help") {
println!("Create random reads from stdin.\n{}", opts.usage(&opts.short_usage(&args[0])));
std::process::exit(0);
}
let lines_per_read :u32={
if matches.opt_present("paired-end") {
8
}else{
4
}
};
print_reads_from_stdin(lines_per_read);
}
fn print_reads_from_stdin(lines_per_read :u32) -> () {
let mut seqs :Vec<String> = Vec::with_capacity(100000);
let my_file = File::open("/dev/stdin").expect("Could not open stdin");
let my_buffer=BufReader::new(my_file);
let mut lines = my_buffer.lines();
while let Some(id) = lines.next() {
let mut entry = id.expect("ERROR: could not parse the ID line");
for _ in 1..lines_per_read {
entry.push('\n');
let next_line = lines.next()
.expect("ERROR: could not get the next line")
.expect("ERROR: could not parse the next line");
entry.push_str(&next_line);
}
seqs.push(entry);
}
let mut rng = thread_rng();
rng.shuffle(&mut seqs);
for seq in seqs {
println!("{}",seq);
}
}