diff --git a/6_biomedicine/dna_sequence_search/README.md b/6_biomedicine/dna_sequence_search/README.md
index 8485e625..55ec1f34 100644
--- a/6_biomedicine/dna_sequence_search/README.md
+++ b/6_biomedicine/dna_sequence_search/README.md
@@ -5,7 +5,7 @@ http://aias.top/
本例子提供了DNA序列搜索,支持上传文件文件,使用spark mlib计算模型提取特征,并基于milvus向量引擎进行后续检索。
-
+
#### 引擎特性
@@ -31,7 +31,7 @@ DNA序列测定方法有光学测序和芯片测序两种。
超参数minDF则指定词汇表中的词语至少要在多少个不同文档中出现。
模型训练,推理使用了spark mlib:
-
+
- [算法详细介绍](http://spark.apache.org/docs/latest/ml-features.html#countvectorizer)
@@ -39,7 +39,7 @@ DNA序列测定方法有光学测序和芯片测序两种。
#### 向量引擎索引策略
-
+
@@ -100,7 +100,7 @@ file:
linux:
path: /home/aias/file/
windows:
- path: D:/aias/file/
+ path: file:/D:/aias/file/
# 文件大小 /M
maxSize: 3000
...
@@ -114,51 +114,30 @@ java -jar dna-sequence-search-0.1.0.jar
```
-## 3. 后端向量引擎部署(docker)
+### 3. 后端向量引擎部署(Milvus 2.0)
#### 3.1 环境要求:
- 需要安装docker运行环境,Mac环境可以使用Docker Desktop
#### 3.2 拉取Milvus向量引擎镜像(用于计算特征值向量相似度)
-[安装文档](https://github.com/milvus-io/docs/blob/master/v0.10.0/site/zh-CN/quick_start/install_milvus/cpu_milvus_docker.md)
-##### 最新版本请参考官网
-- Milvus向量引擎参考链接
-[Milvus向量引擎官网](https://milvus.io/cn/docs/overview.md)
-[Milvus向量引擎Github](https://github.com/milvus-io)
-
+下载 milvus-standalone-docker-compose.yml 配置文件并保存为 docker-compose.yml
+[单机版安装文档](https://milvus.io/docs/v2.0.0/install_standalone-docker.md)
```bash
-sudo docker pull milvusdb/milvus:0.10.0-cpu-d061620-5f3c00
+wget https://github.com/milvus-io/milvus/releases/download/v2.0.0/milvus-standalone-docker-compose.yml -O docker-compose.yml
```
-#### 3.3 下载配置文件
-[vector_engine.zip](https://aias-home.oss-cn-beijing.aliyuncs.com/AIAS/image_search/vector_engine.zip)
-
-#### 3.4 启动 Docker 容器
-/Users/calvin/vector_engine为主机路径,根据需要修改。conf下为引擎所需的配置文件。
+#### 3.3 启动 Docker 容器
```bash
-docker run -d --name milvus_cpu_0.10.0 \
--p 19530:19530 \
--p 19121:19121 \
--p 9091:9091 \
--v /Users/calvin/vector_engine/db:/var/lib/milvus/db \
--v /Users/calvin/vector_engine/conf:/var/lib/milvus/conf \
--v /Users/calvin/vector_engine/logs:/var/lib/milvus/logs \
--v /Users/calvin/vector_engine/wal:/var/lib/milvus/wal \
-milvusdb/milvus:0.10.0-cpu-d061620-5f3c00
+sudo docker-compose up -d
```
#### 3.5 编辑向量引擎连接配置信息
- application.yml
- 根据需要编辑向量引擎连接ip地址127.0.0.1为容器所在的主机ip
```bash
-##################### 向量引擎 ###############################
+################## 向量引擎 ################
search:
host: 127.0.0.1
port: 19530
- indexFileSize: 1024 # maximum size (in MB) of each index file
- nprobe: 16
- nlist: 16384
- collectionName: dna #collection name
-
```
#### 4. 打开浏览器
@@ -166,11 +145,11 @@ search:
- 上传数据文件
1). 点击上传按钮上传文件.
-[测试数据](https://aias-home.oss-cn-beijing.aliyuncs.com/AIAS/6_biomedicine_sdks/dna_sequence_search/human_data.txt)
+[测试数据](https://aias-home.oss-cn-beijing.aliyuncs.com/AIAS/6_biomedicine/dna_sequence_search/human_data.txt)
2). 点击特征提取按钮.
等待文件解析,模型训练,特征提取,特征存入向量引擎。通过console可以看到进度信息。
-
+
- DNA序列搜索
@@ -179,42 +158,26 @@ search:
ATGCCCCAACTAAATACTACCGTATGGCCCACCATAATTACCCCCATACTCCTTACACTATTCCTCATCACCCAACTAAAAATATTAAACACAAACTACCACCTACCTCCCTCACCAAAGCCCATAAAAATAAAAAATTATAACAAACCCTGAGAACCAAAATGAACGAAAATCTGTTCGCTTCATTCATTGCCCCCACAATCCTAG
```
-
+
## 5. 帮助信息
- swagger接口文档:
http://localhost:8089/swagger-ui.html
-
+
- 初始化向量引擎(清空数据):
-me.aias.tools.MilvusInit.java
+
```bash
- String host = "127.0.0.1";
- int port = 19530;
- final String collectionName = "dna"; // collection name
-
- MilvusClient client = new MilvusGrpcClient();
- // Connect to Milvus server
- ConnectParam connectParam = new ConnectParam.Builder().withHost(host).withPort(port).build();
- try {
- Response connectResponse = client.connect(connectParam);
- } catch (ConnectFailedException e) {
- e.printStackTrace();
- }
-
- // 检查 collection 是否存在
- HasCollectionResponse hasCollection = hasCollection(client, collectionName);
- if (hasCollection.hasCollection()) {
- dropIndex(client, collectionName);
- dropCollection(client, collectionName);
- }
- ...
-
+me.aias.tools.MilvusInit.java
```
+- Milvus向量引擎参考链接
+[Milvus向量引擎官网](https://milvus.io/cn/docs/overview.md)
+[Milvus向量引擎Github](https://github.com/milvus-io)
+
### 官网:
[官网链接](http://www.aias.top/)
diff --git a/6_biomedicine/dna_sequence_search/dna-search-ui/package.json b/6_biomedicine/dna_sequence_search/dna-search-ui/package.json
index a2a7c68c..d458537d 100644
--- a/6_biomedicine/dna_sequence_search/dna-search-ui/package.json
+++ b/6_biomedicine/dna_sequence_search/dna-search-ui/package.json
@@ -15,7 +15,7 @@
"dependencies": {
"crypto-js": "^3.1.9-1",
"axios": "0.18.1",
- "core-js": "3.6.5",
+ "core-js": "3.21.0",
"easy-circular-progress": "1.0.4",
"echarts": "^4.2.1",
"element-ui": "2.13.2",
diff --git a/6_biomedicine/dna_sequence_search/dna_sequence_search/dna_sequence_search.iml b/6_biomedicine/dna_sequence_search/dna_sequence_search/dna_sequence_search.iml
deleted file mode 100644
index ebe77dd2..00000000
--- a/6_biomedicine/dna_sequence_search/dna_sequence_search/dna_sequence_search.iml
+++ /dev/null
@@ -1,319 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/6_biomedicine/dna_sequence_search/dna_sequence_search/pom.xml b/6_biomedicine/dna_sequence_search/dna_sequence_search/pom.xml
index 5d129450..3e807e53 100644
--- a/6_biomedicine/dna_sequence_search/dna_sequence_search/pom.xml
+++ b/6_biomedicine/dna_sequence_search/dna_sequence_search/pom.xml
@@ -65,7 +65,7 @@
io.milvus
milvus-sdk-java
- 0.8.2
+ 2.0.0
diff --git a/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/common/milvus/ConnectionPool.java b/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/common/milvus/ConnectionPool.java
new file mode 100644
index 00000000..b1567395
--- /dev/null
+++ b/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/common/milvus/ConnectionPool.java
@@ -0,0 +1,235 @@
+package me.aias.common.milvus;
+
+import io.milvus.client.MilvusClient;
+import io.milvus.client.MilvusServiceClient;
+import io.milvus.param.ConnectParam;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+public class ConnectionPool {
+ private String host = ""; // Milvus 主机
+ private int port; // Milvus 端口号
+ private static volatile ConnectionPool uniqueInstance;
+ private int initialConnections = 10; // 连接池的初始大小
+ private int incrementalConnections = 5; // 连接池自动增加的大小
+ private int maxConnections = 50; // 连接池最大的大小
+ private Vector connections = null; // 存放连接池中连接的向量, 存放的对象为 PooledConnection 型
+
+ private ConnectionPool(String host, int port) {
+ this.host = host;
+ this.port = port;
+ }
+
+ public static ConnectionPool getInstance(String host, String port, boolean refresh) {
+ if (uniqueInstance == null || refresh) {
+ synchronized (ConnectionPool.class) {
+ if (uniqueInstance == null || refresh) {
+ uniqueInstance = new ConnectionPool(host, Integer.parseInt(port));
+ try {
+ uniqueInstance.createPool();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+ return uniqueInstance;
+ }
+
+ private void createPool() { // synchronized
+ if (connections != null) {
+ return; // 假如己经创建,则返回
+ }
+ // 创建保存连接的向量 , 初始时有 0 个元素
+ connections = new Vector();
+ // 根据 initialConnections 中设置的值,创建连接。
+
+ createConnections(this.initialConnections);
+
+ System.out.println(" Milvus连接池创建成功!");
+ }
+
+ private void createConnections(int numConnections) {
+ // 循环创建指定数目的数据库连接
+ for (int x = 0; x < numConnections; x++) {
+ // 是否连接池中的Milvus连接数量己经达到最大?最大值由类成员 maxConnections
+ if (this.maxConnections > 0 && this.connections.size() >= this.maxConnections) {
+ break;
+ }
+ // 增加一个连接到连接池中(Vector connections)
+ connections.addElement(new PooledConnection(newConnection()));
+ System.out.println(" Milvus连接己创建 ......");
+ }
+ }
+
+ private MilvusClient newConnection() {
+ // 创建一个 Milvus 客户端
+ ConnectParam connectParam = ConnectParam.newBuilder()
+ .withHost(host)
+ .withPort(port)
+ .build();
+
+ MilvusServiceClient milvusClient = new MilvusServiceClient(connectParam);
+ // 返回创建的新的Milvus连接
+ return milvusClient;
+ }
+
+ public synchronized MilvusClient getConnection() {
+ // 确保连接池己被创建
+ if (connections == null) {
+ return null; // 连接池还没创建,则返回 null
+ }
+ MilvusClient client = getFreeConnection(); // 获得一个可用的数据库连接
+ // 假如目前没有可以使用的连接,即所有的连接都在使用中
+ while (client == null) {
+ // 等一会再试 250 ms
+ wait(250);
+ client = getFreeConnection(); // 重新再试,直到获得可用的连接,假如
+ // getFreeConnection() 返回的为 null
+ // 则表明创建一批连接后也不可获得可用连接
+ }
+ return client; // 返回获得的可用的连接
+ }
+
+ private MilvusClient getFreeConnection() {
+ // 从连接池中获得一个可用的Milvus连接
+ MilvusClient client = findFreeConnection();
+ if (client == null) {
+ // 假如目前连接池中没有可用的连接
+ // 创建一些连接
+ createConnections(incrementalConnections);
+ // 重新从池中查找是否有可用连接
+ client = findFreeConnection();
+ if (client == null) {
+ // 假如创建连接后仍获得不到可用的连接,则返回 null
+ return null;
+ }
+ }
+ return client;
+ }
+
+ private MilvusClient findFreeConnection() {
+ MilvusClient client = null;
+ PooledConnection pConn = null;
+ // 获得连接池中所有的对象
+ Enumeration enumerate = connections.elements();
+ // 遍历所有的对象,看是否有可用的连接
+ while (enumerate.hasMoreElements()) {
+ pConn = (PooledConnection) enumerate.nextElement();
+ if (!pConn.isBusy()) {
+ // 假如此对象不忙,则获得它的数据库连接并把它设为忙
+ client = pConn.getConnection();
+ pConn.setBusy(true);
+ break; // 己经找到一个可用的连接,退出
+ }
+ }
+ return client; // 返回找到到的可用连接
+ }
+
+ public void returnConnection(MilvusClient client) {
+ // 确保连接池存在,假如连接没有创建(不存在),直接返回
+ if (connections == null) {
+ System.out.println(" 连接池不存在,无法返回此连接到连接池中 !");
+ return;
+ }
+ PooledConnection pConn = null;
+ Enumeration enumerate = connections.elements();
+ // 遍历连接池中的所有连接,找到这个要返回的连接对象
+ while (enumerate.hasMoreElements()) {
+ pConn = (PooledConnection) enumerate.nextElement();
+ // 先找到连接池中的要返回的连接对象
+ if (client == pConn.getConnection()) {
+ // 找到了 , 设置此连接为空闲状态
+ pConn.setBusy(false);
+ break;
+ }
+ }
+ }
+
+ public synchronized void refreshConnections() {
+ // 确保连接池己创新存在
+ if (connections == null) {
+ System.out.println(" 连接池不存在,无法刷新 !");
+ return;
+ }
+ PooledConnection pConn = null;
+ Enumeration enumerate = connections.elements();
+ while (enumerate.hasMoreElements()) {
+ // 获得一个连接对象
+ pConn = (PooledConnection) enumerate.nextElement();
+ // 假如对象忙则等 5 秒 ,5 秒后直接刷新
+ if (pConn.isBusy()) {
+ wait(5000); // 等 5 秒
+ }
+ // 关闭此连接,用一个新的连接代替它。
+ closeConnection(pConn.getConnection());
+ pConn.setConnection(newConnection());
+ pConn.setBusy(false);
+ }
+ }
+
+ public synchronized void closeConnectionPool() {
+ // 确保连接池存在,假如不存在,返回
+ if (connections == null) {
+ System.out.println(" 连接池不存在,无法关闭 !");
+ return;
+ }
+ PooledConnection pConn = null;
+ Enumeration enumerate = connections.elements();
+ while (enumerate.hasMoreElements()) {
+ pConn = (PooledConnection) enumerate.nextElement();
+ // 假如忙,等 5 秒
+ if (pConn.isBusy()) {
+ wait(5000); // 等 5 秒
+ }
+ // 5 秒后直接关闭它
+ closeConnection(pConn.getConnection());
+ // 从连接池向量中删除它
+ connections.removeElement(pConn);
+ }
+ // 置连接池为空
+ connections = null;
+ }
+
+ private void closeConnection(MilvusClient client) {
+ client.close();
+ }
+
+ private void wait(int mSeconds) {
+ try {
+ Thread.sleep(mSeconds);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ class PooledConnection {
+ MilvusClient client = null; // Milvus连接
+ boolean busy = false; // 此连接是否正在使用的标志,默认没有正在使用
+
+ // 构造函数,根据一个 Connection 构告一个 PooledConnection 对象
+ public PooledConnection(MilvusClient client) {
+ this.client = client;
+ }
+
+ // 返回此对象中的连接
+ public MilvusClient getConnection() {
+ return client;
+ }
+
+ // 设置此对象的连接
+ public void setConnection(MilvusClient client) {
+ this.client = client;
+ }
+
+ // 获得对象连接是否忙
+ public boolean isBusy() {
+ return busy;
+ }
+
+ // 设置对象的连接正在忙
+ public void setBusy(boolean busy) {
+ this.busy = busy;
+ }
+ }
+}
diff --git a/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/common/milvus/MilvusConnector.java b/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/common/milvus/MilvusConnector.java
deleted file mode 100644
index 07d88349..00000000
--- a/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/common/milvus/MilvusConnector.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package me.aias.common.milvus;
-
-import io.milvus.client.*;
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * Milvus Client Connector
- *
- * @author Calvin
- * @date 2021-12-19
- **/
-@Slf4j
-public final class MilvusConnector {
-
- // 创建一个 Milvus 客户端
- private MilvusClient client = null;
-
- public void init(String host, int port) {
- client = new MilvusGrpcClient();
- // Connect to Milvus server
- ConnectParam connectParam = new ConnectParam.Builder().withHost(host).withPort(port).build();
- try {
- Response connectResponse = client.connect(connectParam);
- } catch (ConnectFailedException e) {
- log.error("Failed to connect to Milvus server: " + e.toString());
- }
-
- }
-
- public void close() throws InterruptedException {
- this.client.disconnect();
- }
-
- public MilvusClient getClient() {
- return client;
- }
-}
diff --git a/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/config/MilvusConfiguration.java b/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/config/MilvusConfiguration.java
deleted file mode 100644
index 833eb830..00000000
--- a/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/config/MilvusConfiguration.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package me.aias.config;
-
-import me.aias.common.milvus.MilvusConnector;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Milvus配置类
- * @author Calvin
- * @date 2021-12-12
- **/
-@Configuration
-public class MilvusConfiguration {
- @Value("${search.host}")
- private String host;
- @Value("${search.port}")
- private int port;
-
- @Bean
- public MilvusConnector milvusConnector() {
- MilvusConnector milvus = new MilvusConnector();
- milvus.init(host, port);
- return milvus;
- }
-}
\ No newline at end of file
diff --git a/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/config/ModelConfiguration.java b/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/config/ModelConfiguration.java
index 721dfd83..3adaf9ed 100644
--- a/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/config/ModelConfiguration.java
+++ b/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/config/ModelConfiguration.java
@@ -14,7 +14,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class ModelConfiguration {
// 设定词汇表的最大量为768
- @Value("${search.dimension}")
+ @Value("${search.size}")
private int size;
@Bean
diff --git a/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/controller/DNASeqController.java b/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/controller/DNASeqController.java
index 836fd65c..fdd61b0e 100644
--- a/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/controller/DNASeqController.java
+++ b/6_biomedicine/dna_sequence_search/dna_sequence_search/src/main/java/me/aias/controller/DNASeqController.java
@@ -1,7 +1,6 @@
package me.aias.controller;
-import io.milvus.client.ConnectFailedException;
-import io.milvus.client.HasCollectionResponse;
+import io.milvus.param.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@@ -10,13 +9,8 @@ import me.aias.common.sentence.VectorizerModel;
import me.aias.common.utils.DataUtils;
import me.aias.common.utils.FeatureUtils;
import me.aias.common.utils.FileUtils;
-import me.aias.config.FileProperties;
-import me.aias.domain.DNAInfoDto;
-import me.aias.domain.LocalStorage;
-import me.aias.domain.ResEnum;
-import me.aias.domain.ResultRes;
+import me.aias.domain.*;
import me.aias.service.DNAService;
-import me.aias.service.FeatureService;
import me.aias.service.LocalStorageService;
import me.aias.service.SearchService;
import org.apache.spark.ml.linalg.DenseVector;
@@ -52,7 +46,6 @@ import java.util.concurrent.ConcurrentHashMap;
@Api(tags = "DNA数据管理")
@RequestMapping("/api/text")
public class DNASeqController {
- private final FileProperties properties;
@Autowired
private VectorizerModel vectorizerModel;
@@ -62,18 +55,9 @@ public class DNASeqController {
@Autowired
private SearchService searchService;
- @Autowired
- private FeatureService featureService;
-
@Autowired
private LocalStorageService localStorageService;
- @Value("${search.dimension}")
- int dimension;
-
- @Value("${search.collectionName}")
- String collectionName;
-
@ApiOperation(value = "提取DNA特征值")
@GetMapping("/extractFeatures")
public ResponseEntity