semvec/pypi-packages huggingface dataset:
nonebot-plugin-tempfile 0.2.0
适用于 NoneBot2 插件的临时文件/IO 依赖注入支持
License: MIT
Requires Python: >=3.8

<div align="center">

# nonebot-plugin-tempfile

_✨ 适用于 NoneBot2 插件的临时文件/IO 依赖注入支持 ✨_

<a href="./LICENSE">
    <img src="https://img.shields.io/github/license/NCBM/nonebot-plugin-tempfile.svg" alt="license">
</a>
<a href="https://pypi.python.org/pypi/nonebot-plugin-tempfile">
  <img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/nonebot-plugin-tempfile">
</a>
<a href="https://pypi.python.org/pypi/nonebot-plugin-tempfile">
    <img src="https://img.shields.io/pypi/v/nonebot-plugin-tempfile.svg" alt="pypi">
</a>
<img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="python">

</div>

## 介绍

`nonebot-plugin-tempfile` 是帮助**开发者**利用依赖注入特性辅助管理临时文件/IO 的库插件，支持结束会话时自动清理临时文件（夹）。

## 安装

通过 `nb-cli`:

```console
nb plugin install nonebot-plugin-tempfile
```

## 使用

### 加载模块

```python
from nonebot import require

require("nonebot_plugin_tempfile")
```

### 简单管理临时文件（夹）

```python
from nonebot_plugin_tempfile import SimpleTempFile, SimpleTempDir

@some_matcher.handle()
async def some_handler(tmpfile: SimpleTempFile):
    # tmp is a `pathlib.Path` in function
    ...

@some_matcher.handle()
async def some_handler(tmpdir: SimpleTempDir):
    # tmp is a `pathlib.Path` in function
    ...
```

> 注意：`Simple` 开头的依赖类型无法同时使用多个，注入值在同一上下文内相同。
>
> 如有管理多个临时文件的需求，请另行声明自有依赖。

### 自定义临时文件（夹）

```python
from nonebot_plugin_tempfile import TempFile, TempDir

@some_matcher.handle()
async def some_handler(tmp1: Path = TempFile(".png"), tmp2: Path = TempFile(".txt", "tmp-someplugin-")):
    ...

tmpdir = TempDir(prefix="tmp-kazoo-")
tmpdir2 = TempDir(dir=tmpdir)
# 支持目录嵌套

@some_matcher.handle()
async def some_handler(
    tmp1: Path = TempFile(".png", dir=tmpdir),
    tmp2: Path = TempFile(".txt", "tmp-someplugin-", dir=tmpdir2)
):
    ...
```

### 注入虚拟 IO

```python
from io import StringIO, BytesIO
from nonebot_plugin_tempfile import TempStringIO, TempBytesIO

@some_matcher.handle()
async def some_handler(tmp1: StringIO = TempStringIO(), tmp2: BytesIO = TempBytesIO()):
    ...

@some_matcher.handle()
async def some_handler(tmp1: BytesIO = TempBytesIO(), tmp2: BytesIO = TempBytesIO()):
    ...
```

## 配置

本插件增加了下列可选配置项，有需要的用户请自行在 `.env` 或选用的以 `.env` 开头的文件中配置：

```python
# 下列配置项请按需解除注释并配置

# 临时文件默认前缀（字符串）
# tempfile_default_prefix=tmpnonebot
```
blasttools 0.1.16
Commands for turning blast queries into pandas dataframes.
License: MIT
Requires Python: <3.13,>=3.9
Keywords: genomics, bioinformatics

# blasttools

Commands for turning blast queries into pandas dataframes.

Blast against any built blast databases

```sh
blasttools blast --out=my.pkl query.fasta my_blastdbs_dir/*.pot
```

## Install

Install with

```sh
python -m pip install -U blasttools
# *OR*
python -m pip install -U 'git+https://github.com/arabidopsis/blasttools.git'
```

Once installed you can update with `blasttools update`

## Common Usages:

Build some blast databases from Ensembl Plants.

```sh
blasttools plants --release=40 build triticum_aestivum zea_mays
```

Find out what species are available:

```sh
blasttools plants --release=40 species
```

Blast against `my.fasta` and save dataframe as a pickle file (the default is to
save as a csv file named `my.fasta.csv`).

```sh
blasttools plants blast --out=dataframe.pkl my.fasta triticum_aestivum zea_mays
```

Get your blast data!

```python
import pandas as pd
df = pd.read_pickle('dataframe.pkl')
```

## Parallelization

When blasting, you can specify `--num-threads` which is passed directly to the
underlying blast command. If you want to parallelize over species, databases or fasta files,
I suggest you use [GNU Parallel](https://www.gnu.org/software/parallel/) [[Tutorial](https://blog.ronin.cloud/gnu-parallel/)].

`parallel` has a much better set of options for controlling how the parallelization works
and is also quite simple for simple things.

e.g. build blast databases from a set of fasta files concurrently:

```sh
parallel blasttools build ::: *.fa.gz
```

Or blast _everything_!

```sh
species=$(blasttools plants species)
parallel blasttools plants build ::: $species
# must have different output files here...
parallel blasttools plants blast --out=my{}.pkl my.fasta ::: $species
# or in batches of 4 species at a time
parallel -N4 blasttools plants blast --out='my{#}.pkl' my.fasta ::: $species
```

Then gather them all together...

```sh
blasttools concat --out=alldone.xlsx my*.pkl && rm my*.pkl
```

or programmatically:

```python
from glob import glob
import pandas as pd
df = pd.concat([pd.read_pickle(f) for f in glob('my*.pkl')], ignore_index=True)
```

Remember: if you parallelize your blasts _and_ use `--num-threads > 1`
then you are probably going to be fighting for cpu time
amongst yourselves!

## Best matches

Usually if you want the top/best `--best=3` will select the _lowest_ evalue's for
each query sequence. However if you want say the best to, say, be the longest query match
then you can add `--expr='qstart - qend'`. (Remember we are looking for the lowest values).

## XML

Blast offers an xml (`--xml`) output format that adds `query`, `match`, `sbjct` strings. The other
fields are equivalent to adding `--columns='+score gaps nident positive qlen slen'`.

It also offers a way to display the blast match as a pairwise alignment.

```python
from blasttools.blastxml import hsp_match
df = pd.read_csv('results.csv')
df['alignment'] = df.apply(hsp_match, axis=1)
print(df.iloc[0].alignment)
```