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 package org.utgenome.shell;
26
27 import org.utgenome.format.fasta.CompactFASTA;
28 import org.utgenome.format.fasta.GenomeSequence;
29 import org.utgenome.gwt.utgb.client.bio.ChrLoc;
30 import org.xerial.util.log.Logger;
31 import org.xerial.util.opt.Argument;
32
33
34
35
36
37
38
39 public class Sequence extends UTGBShellCommand {
40
41 private static Logger _logger = Logger.getLogger(Sequence.class);
42
43 @Argument(index = 0, name = "(ref pac)", required = true)
44 private String packFilePrefix;
45
46 @Argument(index = 1, name = "(chr:start-end)")
47 private String query;
48
49 @Override
50 public void execute(String[] args) throws Exception {
51
52 if (query == null)
53 throw new UTGBShellException("no query is given");
54
55 CompactFASTA f = new CompactFASTA(packFilePrefix);
56
57 ChrLoc loc = RegionQueryExpr.parse(query);
58 GenomeSequence seq = f.getSequence(loc.chr, loc.start - 1, loc.end);
59 if (seq == null) {
60 _logger.warn("no entry found: " + loc);
61 }
62
63 int cursor = 0;
64 final int step = 50;
65 while (cursor < seq.length()) {
66 for (int i = 0; i < step && cursor < seq.length(); ++i, ++cursor) {
67 System.out.print(seq.charAt(cursor));
68 }
69 System.out.println();
70 }
71
72 }
73
74 @Override
75 public String getOneLinerDescription() {
76 return "retrieve a genome sequence from a pack file";
77 }
78
79 @Override
80 public String name() {
81 return "seq";
82 }
83
84 }