-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
754 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar | ||
.mvn/wrapper/maven-wrapper.jar | ||
src/resources/libgenomicsqlite* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>net.mlin</groupId> | ||
<artifactId>genomicsqlite-jdbc</artifactId> | ||
<version>${revision}</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>genomicsqlite-jdbc</name> | ||
<url>https://github.com/mlin/GenomicSQLite</url> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<name>Mike Lin</name> | ||
<email>dna@mlin.net</email> | ||
<organization>mlin.net LLC</organization> | ||
<organizationUrl>https://www.mlin.net</organizationUrl> | ||
</developer> | ||
</developers> | ||
|
||
<scm> | ||
<connection>scm:git:git://github.com/mlin/GenomicSQLite.git</connection> | ||
<developerConnection>scm:git:ssh://github.com:mlin/GenomicSQLite.git</developerConnection> | ||
<url>https://github.com/mlin/GenomicSQLite/tree/main</url> | ||
</scm> | ||
|
||
<distributionManagement> | ||
<repository> | ||
<id>internal.repo</id> | ||
<name>Temporary Staging Repository</name> | ||
<url>file://${project.build.directory}/mvn-repo</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.xerial</groupId> | ||
<artifactId>sqlite-jdbc</artifactId> | ||
<version>[3.31.1,)</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
<configuration> | ||
<trimStackTrace>false</trimStackTrace> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>3.7.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-project-info-reports-plugin</artifactId> | ||
<version>3.0.0</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.diffplug.spotless</groupId> | ||
<artifactId>spotless-maven-plugin</artifactId> | ||
<version>2.3.1</version> | ||
<configuration> | ||
<java> | ||
<includes> | ||
<include>src/**/*.java</include> | ||
</includes> | ||
<importOrder/> | ||
<removeUnusedImports/> | ||
<googleJavaFormat/> | ||
</java> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
191 changes: 191 additions & 0 deletions
191
bindings/jdbc/genomicsqlite-jdbc/src/main/java/net/mlin/genomicsqlite/GenomicSQLite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
package net.mlin.genomicsqlite; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.HashMap; | ||
|
||
public class GenomicSQLite { | ||
public static String version(Connection conn) throws SQLException { | ||
ResultSet row = conn.createStatement().executeQuery("SELECT genomicsqlite_version()"); | ||
row.next(); | ||
return row.getString(1); | ||
} | ||
|
||
public static String attachSQL( | ||
Connection conn, String dbFileName, String schemaName, String configJson) | ||
throws SQLException { | ||
PreparedStatement stmt = conn.prepareStatement("SELECT genomicsqlite_attach_sql(?,?,?)"); | ||
stmt.setString(1, dbFileName); | ||
stmt.setString(2, schemaName); | ||
stmt.setString(3, configJson); | ||
ResultSet row = stmt.executeQuery(); | ||
row.next(); | ||
return row.getString(1); | ||
} | ||
|
||
public static String attachSQL(Connection conn, String dbFileName, String schemaName) | ||
throws SQLException { | ||
return attachSQL(conn, dbFileName, schemaName, "{}"); | ||
} | ||
|
||
public static String vacuumIntoSQL(Connection conn, String destFileName, String configJson) | ||
throws SQLException { | ||
PreparedStatement stmt = conn.prepareStatement("SELECT genomicsqlite_vacuum_into_sql(?,?)"); | ||
stmt.setString(1, destFileName); | ||
stmt.setString(2, configJson); | ||
ResultSet row = stmt.executeQuery(); | ||
row.next(); | ||
return row.getString(1); | ||
} | ||
|
||
public static String vacuumIntoSQL(Connection conn, String destFileName) throws SQLException { | ||
return vacuumIntoSQL(conn, destFileName, "{}"); | ||
} | ||
|
||
public static String createGenomicRangeIndexSQL( | ||
Connection conn, | ||
String tableName, | ||
String rid, | ||
String beginPosition, | ||
String endPosition, | ||
int floor) | ||
throws SQLException { | ||
PreparedStatement stmt = | ||
conn.prepareStatement("SELECT create_genomic_range_index_sql(?,?,?,?,?)"); | ||
stmt.setString(1, tableName); | ||
stmt.setString(2, rid); | ||
stmt.setString(3, beginPosition); | ||
stmt.setString(4, endPosition); | ||
stmt.setInt(5, floor); | ||
ResultSet row = stmt.executeQuery(); | ||
row.next(); | ||
return row.getString(1); | ||
} | ||
|
||
public static String createGenomicRangeIndexSQL( | ||
Connection conn, String tableName, String rid, String beginPosition, String endPosition) | ||
throws SQLException { | ||
return createGenomicRangeIndexSQL(conn, tableName, rid, beginPosition, endPosition, -1); | ||
} | ||
|
||
public static String putReferenceAssemblySQL(Connection conn, String assembly) | ||
throws SQLException { | ||
PreparedStatement stmt = conn.prepareStatement("SELECT put_genomic_reference_assembly_sql(?)"); | ||
stmt.setString(1, assembly); | ||
ResultSet row = stmt.executeQuery(); | ||
row.next(); | ||
return row.getString(1); | ||
} | ||
|
||
public static String putReferenceSequenceSQL( | ||
Connection conn, | ||
String name, | ||
long length, | ||
String assembly, | ||
String refget_id, | ||
String meta_json, | ||
long rid) | ||
throws SQLException { | ||
PreparedStatement stmt = | ||
conn.prepareStatement("SELECT put_genomic_reference_sequence_sql(?,?,?,?,?,?)"); | ||
stmt.setString(1, name); | ||
stmt.setLong(2, length); | ||
stmt.setString(3, assembly); | ||
stmt.setString(4, refget_id); | ||
stmt.setString(5, meta_json); | ||
stmt.setLong(6, rid); | ||
ResultSet row = stmt.executeQuery(); | ||
row.next(); | ||
return row.getString(1); | ||
} | ||
|
||
public static String putReferenceSequenceSQL( | ||
Connection conn, | ||
String name, | ||
long length, | ||
String assembly, | ||
String refget_id, | ||
String meta_json) | ||
throws SQLException { | ||
PreparedStatement stmt = | ||
conn.prepareStatement("SELECT put_genomic_reference_sequence_sql(?,?,?,?,?)"); | ||
stmt.setString(1, name); | ||
stmt.setLong(2, length); | ||
if (assembly != null) stmt.setString(3, assembly); | ||
if (refget_id != null) stmt.setString(4, refget_id); | ||
if (meta_json != null) stmt.setString(5, meta_json); | ||
ResultSet row = stmt.executeQuery(); | ||
row.next(); | ||
return row.getString(1); | ||
} | ||
|
||
public static String putReferenceSequenceSQL( | ||
Connection conn, String name, long length, String assembly, String refget_id) | ||
throws SQLException { | ||
return putReferenceSequenceSQL(conn, name, length, assembly, refget_id, null); | ||
} | ||
|
||
public static String putReferenceSequenceSQL( | ||
Connection conn, String name, long length, String assembly) throws SQLException { | ||
return putReferenceSequenceSQL(conn, name, length, assembly, null, null); | ||
} | ||
|
||
public static String putReferenceSequenceSQL(Connection conn, String name, long length) | ||
throws SQLException { | ||
return putReferenceSequenceSQL(conn, name, length, null, null, null); | ||
} | ||
|
||
public static HashMap<Long, ReferenceSequence> getReferenceSequencesByRid( | ||
Connection conn, String assembly) throws SQLException { | ||
String sql = | ||
"SELECT _gri_rid, gri_refseq_name, gri_refseq_length, gri_assembly, gri_refget_id, gri_refseq_meta_json FROM _gri_refseq"; | ||
PreparedStatement stmt; | ||
if (assembly != null) { | ||
stmt = conn.prepareStatement(sql + " WHERE gri_assembly = ?"); | ||
stmt.setString(1, assembly); | ||
} else { | ||
stmt = conn.prepareStatement(sql); | ||
} | ||
ResultSet row = stmt.executeQuery(); | ||
HashMap<Long, ReferenceSequence> ans = new HashMap<Long, ReferenceSequence>(); | ||
while (row.next()) { | ||
ReferenceSequence grs = | ||
new ReferenceSequence( | ||
row.getLong(1), | ||
row.getString(2), | ||
row.getLong(3), | ||
row.getString(4), | ||
row.getString(5), | ||
row.getString(6)); | ||
ans.put(grs.rid, grs); | ||
} | ||
return ans; | ||
} | ||
|
||
public static HashMap<Long, ReferenceSequence> getReferenceSequencesByRid(Connection conn) | ||
throws SQLException { | ||
return getReferenceSequencesByRid(conn, null); | ||
} | ||
|
||
public static HashMap<String, ReferenceSequence> getReferenceSequencesByName( | ||
Connection conn, String assembly) throws SQLException { | ||
HashMap<String, ReferenceSequence> ans = new HashMap<String, ReferenceSequence>(); | ||
for (HashMap.Entry<Long, ReferenceSequence> entry : | ||
getReferenceSequencesByRid(conn, assembly).entrySet()) { | ||
ReferenceSequence grs = entry.getValue(); | ||
if (ans.containsKey(grs.name)) { | ||
throw new RuntimeException( | ||
"GenomicSQLite.getReferenceSequencesByName: duplicate name; try filtering by assembly"); | ||
} | ||
ans.put(grs.name, grs); | ||
} | ||
return ans; | ||
} | ||
|
||
public static HashMap<String, ReferenceSequence> getReferenceSequencesByName(Connection conn) | ||
throws SQLException { | ||
return getReferenceSequencesByName(conn, null); | ||
} | ||
} |
Oops, something went wrong.