File: HT2Module.java

package info (click to toggle)
hisat2 2.2.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,448 kB
  • sloc: cpp: 97,109; python: 11,075; perl: 7,279; sh: 2,328; ansic: 1,458; makefile: 532; javascript: 273; java: 116
file content (122 lines) | stat: -rw-r--r-- 3,203 bytes parent folder | download | duplicates (3)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * Copyright 2018, Chanhee Park <parkchanhee@gmail.com> and Daehwan Kim <infphilo@gmail.com>
 *
 * This file is part of HISAT 2.
 *
 * HISAT 2 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * HISAT 2 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with HISAT 2.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

public class HT2Module {
	static {
		System.loadLibrary("ht2jni");
    }
    
    public static class HT2Position {
        int chr_id;
        int direction;
        long position;

        HT2Position(int id, int dir, int pos) {
            this.chr_id = id;
            this.direction = dir;
            this.position = pos;
        }

        @Override
        public String toString()
        {
            return getClass().getSimpleName() 
                    + "[chr_id=" + chr_id 
                    + ", direction=" + direction 
                    + ", position=" + position + "]";
        }
    }

    private native long init(String indexName, Map<String, Integer> options);
    private native void close(long handle);
    private native Map<String, Integer> get_options();

    private native String index_getrefnamebyid(long handle, int id);
    private native List<String> index_getrefnames(long handle);
    private native List<HT2Position> repeat_expand(long handle, String name, long rpos, long rlen);

    private long handle;

    HT2Module() {
        handle = 0;
    }

    public void initLibrary(String indexName) {
        initLibrary(indexName, null);
    }

    public void initLibrary(String indexName, Map<String, Integer> options)
    {
        if(handle == 0) {
            handle = init(indexName, options);
        }
    }

    public Map<String, Integer> initOption()
    {
        return get_options();
    }

    public String getRefNameById(int chr_id)
    {
        if(handle == 0) {
            // TODO: Exception
            return "";
        }

        // TODO: Exception(OutOfIndex)
        return index_getrefnamebyid(handle, chr_id);
    }

    public List<String> getRefNames()
    {
        if(handle == 0) {
            // TODO: Exception
            return new ArrayList<>();
        }
        return index_getrefnames(handle);
    }

    public List<HT2Position> repeatExpand(String name, long position, long length)
    {
        if(handle == 0) {
            // TODO: Exception
            return new ArrayList<>();
        }
        return repeat_expand(handle, name, position, length);
    }

    public void cleanup()
    {
        if(handle != 0) {
            close(handle);
            handle = 0;
        }
    }

    public void finalize() {
        cleanup();
    }

}