读取FASTA文件 [英] Reading an FASTA file
问题描述
我想将文件的以下行转换为JSON,我想将其保存为猫鼬模式.
I want to convert the following line of a file into JSON, I want to save that into an mongoose schema.
>HWI-ST700660_96:2:1101:1455:2154#5@0/1
GAA…..GAATG
应该是:
{">HWI-ST700660_96:2:1101:1455:2154#5@0/1": "GAA…..GAATG"}
我尝试了几种选择,下面是一个示例,但是没有成功,有什么建议吗?
I have tried several options, one sample below, but no success, any suggestion?
const parser = require("csv-parse/lib/sync");//import parser
const fs = require("fs");//import file reader
const path = require("path");//for join paths
const sourceData = fs.readFileSync(path.join(__dirname, "Reads.txt"), "utf8");//read the file, locally stored
console.log(sourceData);//print out for checking
const documents = parser(sourceData);//parsing, it works for other situations I have tested, in a column like data
console.log(documents);//printing out
这段代码为我提供了如下输出:
This code give me an output as following:
[ [ '>HWI-ST700660_96:2:1101:1455:2154#5@0/1' ],
[ 'GAATGGAATGAAATGGATAGGAATGGAATGGAATGGAATGGATTGGAATGGATTAGAATGGATTGGAATGGAATGAAATTAATTTGATTGGAATGGAATG' ],...
类似的问题: fasta文件读取python
推荐答案
由于您使用的是解析器的默认配置,因此它只会输出该配置中的数组数组. 如果要接收对象,则需要首先为解析器提供一些选项(列).看看文档.
Because you are using the default config of the parser, it does simply output arrays of arrays in that configuration. If you want to receive objects you will need to give the parser some options (columns) first. Take a look at the doc.
在使用同步解析模式时(如您所使用的),您可以提供以下选项:
When using the sync parsing mode (like you are using) you can provide options like this:
const documents = parse(sourceData, {columns: true})
columns:true
将从输入csv的第一行推断出列名.
columns:true
will infer the column names from the first line of the input csv.
这篇关于读取FASTA文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!