Java 将PubMed GEO DataSets中dataset类型的检索结果转化为Excel

2024-04-28 16:38

本文主要是介绍Java 将PubMed GEO DataSets中dataset类型的检索结果转化为Excel,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

检索结果举例
为进行生信分析,需要对检索结果转化为Excel并且以标签作为列。首先将检索结果Send to File转化成TXT格式,如下:
在这里插入图片描述
在这里插入图片描述
通过下面的程序进一步转为Excel(使用jxl包):
在这里插入图片描述
源代码:

/** To change this license header, choose License Headers in Project Properties.* To change this template file, choose Tools | Templates* and open the template in the editor.*/
package ncbi;import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;/**** @author wgyklh*/
public class NCBI {/*** @param args the command line arguments* @throws java.lang.Exception*/public static void main(String[] args) throws Exception {// TODO code application logic hereFile in = new File("C:\\Users\\Lenovo\\Desktop\\gds_result.txt");File out = new File("C:\\Users\\Lenovo\\Desktop\\gds.result.xls");WritableWorkbook wwb = Workbook.createWorkbook(out);WritableSheet dataset = wwb.createSheet("DataSet", 0);WritableSheet series = wwb.createSheet("Series", 1);WritableSheet platform= wwb.createSheet("Platform", 2);WritableSheet sample= wwb.createSheet("Sample", 3);dataset.addCell(new Label(0, 0, "Number"));dataset.addCell(new Label(1, 0, "Title"));dataset.addCell(new Label(2, 0, "Introduction"));dataset.addCell(new Label(3, 0, "Organism"));dataset.addCell(new Label(4, 0, "Type"));dataset.addCell(new Label(5, 0, "Platform"));dataset.addCell(new Label(6, 0, "Series"));dataset.addCell(new Label(7, 0, "Sample"));dataset.addCell(new Label(8, 0, "FTP download"));dataset.addCell(new Label(9, 0, "Accession"));dataset.addCell(new Label(10, 0, "ID"));series.addCell(new Label(0, 0, "Number"));series.addCell(new Label(1, 0, "Title"));series.addCell(new Label(2, 0, "Introduction"));series.addCell(new Label(3, 0, "Organism"));series.addCell(new Label(4, 0, "Type"));series.addCell(new Label(5, 0, "Platform"));series.addCell(new Label(6, 0, "Sample"));series.addCell(new Label(7, 0, "FTP download"));series.addCell(new Label(8, 0, "Accession"));series.addCell(new Label(9, 0, "ID"));BufferedReader reader = null;String tempString = null;int number = 1;int index1 = 0;int index2 = 0;int index3 = 0;try {reader = new BufferedReader(new FileReader(in));for (int n = 1; n <= 32; n++) {tempString = reader.readLine();tempString = reader.readLine();System.out.println(tempString);dataset.addCell(new Label(0, number, String.valueOf(number)));dataset.addCell(new Label(1, number, tempString.substring(3)));tempString = reader.readLine();dataset.addCell(new Label(2, number, tempString));tempString = reader.readLine();dataset.addCell(new Label(3, number, tempString.substring(10)));tempString = reader.readLine();dataset.addCell(new Label(4, number, tempString.substring(6)));tempString = reader.readLine();index1 = tempString.indexOf("Series");index2 = tempString.indexOf("Sample");System.out.println(index1 + "   " + index2);dataset.addCell(new Label(5, number, tempString.substring(10, index1 - 1)));dataset.addCell(new Label(6, number, tempString.substring(index1 + 8, index1 + 16)));dataset.addCell(new Label(7, number, tempString.substring(index1 + 16, index2 - 1).trim()));tempString = reader.readLine();dataset.addCell(new Label(8, number, tempString.substring(14)));tempString = reader.readLine();index3 = tempString.indexOf("ID");dataset.addCell(new Label(9, number, tempString.substring(20, 27)));dataset.addCell(new Label(10, number, tempString.substring(index3 + 4)));number++;}reader.close();wwb.write();wwb.close();} catch (FileNotFoundException e) {} catch (IOException e) {} finally {if (reader != null) {try {reader.close();} catch (IOException e) {}}}}
}

这篇关于Java 将PubMed GEO DataSets中dataset类型的检索结果转化为Excel的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/943734

相关文章

java中pdf模版填充表单踩坑实战记录(itextPdf、openPdf、pdfbox)

《java中pdf模版填充表单踩坑实战记录(itextPdf、openPdf、pdfbox)》:本文主要介绍java中pdf模版填充表单踩坑的相关资料,OpenPDF、iText、PDFBox是三... 目录准备Pdf模版方法1:itextpdf7填充表单(1)加入依赖(2)代码(3)遇到的问题方法2:pd

Java Stream流之GroupBy的用法及应用场景

《JavaStream流之GroupBy的用法及应用场景》本教程将详细介绍如何在Java中使用Stream流的groupby方法,包括基本用法和一些常见的实际应用场景,感兴趣的朋友一起看看吧... 目录Java Stream流之GroupBy的用法1. 前言2. 基础概念什么是 GroupBy?Stream

SpringBoot监控API请求耗时的6中解决解决方案

《SpringBoot监控API请求耗时的6中解决解决方案》本文介绍SpringBoot中记录API请求耗时的6种方案,包括手动埋点、AOP切面、拦截器、Filter、事件监听、Micrometer+... 目录1. 简介2.实战案例2.1 手动记录2.2 自定义AOP记录2.3 拦截器技术2.4 使用Fi

最新Spring Security的基于内存用户认证方式

《最新SpringSecurity的基于内存用户认证方式》本文讲解SpringSecurity内存认证配置,适用于开发、测试等场景,通过代码创建用户及权限管理,支持密码加密,虽简单但不持久化,生产环... 目录1. 前言2. 因何选择内存认证?3. 基础配置实战❶ 创建Spring Security配置文件

Spring Security 单点登录与自动登录机制的实现原理

《SpringSecurity单点登录与自动登录机制的实现原理》本文探讨SpringSecurity实现单点登录(SSO)与自动登录机制,涵盖JWT跨系统认证、RememberMe持久化Token... 目录一、核心概念解析1.1 单点登录(SSO)1.2 自动登录(Remember Me)二、代码分析三、

springboot自定义注解RateLimiter限流注解技术文档详解

《springboot自定义注解RateLimiter限流注解技术文档详解》文章介绍了限流技术的概念、作用及实现方式,通过SpringAOP拦截方法、缓存存储计数器,结合注解、枚举、异常类等核心组件,... 目录什么是限流系统架构核心组件详解1. 限流注解 (@RateLimiter)2. 限流类型枚举 (

Java Thread中join方法使用举例详解

《JavaThread中join方法使用举例详解》JavaThread中join()方法主要是让调用改方法的thread完成run方法里面的东西后,在执行join()方法后面的代码,这篇文章主要介绍... 目录前言1.join()方法的定义和作用2.join()方法的三个重载版本3.join()方法的工作原

Spring AI使用tool Calling和MCP的示例详解

《SpringAI使用toolCalling和MCP的示例详解》SpringAI1.0.0.M6引入ToolCalling与MCP协议,提升AI与工具交互的扩展性与标准化,支持信息检索、行动执行等... 目录深入探索 Spring AI聊天接口示例Function CallingMCPSTDIOSSE结束语

Java获取当前时间String类型和Date类型方式

《Java获取当前时间String类型和Date类型方式》:本文主要介绍Java获取当前时间String类型和Date类型方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录Java获取当前时间String和Date类型String类型和Date类型输出结果总结Java获取

Spring Boot Actuator应用监控与管理的详细步骤

《SpringBootActuator应用监控与管理的详细步骤》SpringBootActuator是SpringBoot的监控工具,提供健康检查、性能指标、日志管理等核心功能,支持自定义和扩展端... 目录一、 Spring Boot Actuator 概述二、 集成 Spring Boot Actuat