# For 使用者

您可以通过这部分了解数据的上传以及并成功运行工作流的方法。 该工作流程是一个文件格式转换，用于将基因组文件从一种格式 (CRAM) 转换为另一种格式 (BAM) 以进行下游分析。

<figure><img src="/files/mlHq3wZI7G9MVX3AXrg2" alt=""><figcaption></figcaption></figure>

### 1. 创建Workspace

* 名称：仅支持中文、数字、字母、“-”、“\_”且不能以“-”、“\_”开头
* 存储类型：目前开源版仅支持使用NAS存储，后续将支持S3协议
* 挂载目录：此处可以输入想要在当前nfs中新建的目录名称，以“/”开头

<figure><img src="/files/mAuwh29Rz4HKDta4d9j6" alt=""><figcaption></figcaption></figure>

### 2. 上传数据

通常上传所需要分析的数据是开启一个工作流的第一步，在这个实践中，我们需要先将所需要用到的数据集传到NAS目录中，并手动生成一个CSV的数据模型表格。你需要将数据模型表格中所需关联的数据文件上传到Bio-OS的存储桶中。您可以根据以下链接先下载样本数据集文件和参考数据集文件至本地，然后上传至NAS存储中（可通过scp命令从本地复制到NAS存储中）。

<table><thead><tr><th width="235">数据类型</th><th>数据地址</th></tr></thead><tbody><tr><td><strong>参考数据</strong><br>基因组序列的字典文件</td><td><a href="https://sample-data.tos-cn-beijing.volces.com/Homo_sapiens_assembly38.dict">https://sample-data.tos-cn-beijing.volces.com/Homo_sapiens_assembly38.dict</a></td></tr><tr><td><strong>参考数据</strong><br>基因组序列文件</td><td><a href="https://sample-data.tos-cn-beijing.volces.com/Homo_sapiens_assembly38.fasta">https://tutorials-data.tos-cn-guangzhou.volces.com/cram-to-bam/reference-data/Homo_sapiens_assembly38.fasta</a></td></tr><tr><td><strong>参考数据</strong><br>基因组索引文件</td><td><a href="https://sample-data.tos-cn-beijing.volces.com/Homo_sapiens_assembly38.fasta.fai">https://sample-data.tos-cn-beijing.volces.com/Homo_sapiens_assembly38.fasta.fai</a></td></tr><tr><td><strong>样本数据1</strong></td><td><a href="https://sample-data.tos-cn-beijing.volces.com/NA12878.cram">https://sample-data.tos-cn-beijing.volces.com/NA12878.cram</a></td></tr><tr><td><strong>样本数据2</strong></td><td><a href="https://sample-data.tos-cn-beijing.volces.com/my-sample-data.cram">https://sample-data.tos-cn-beijing.volces.com/my-sample-data.cram</a></td></tr></tbody></table>

### 3. 制作数据模型

点击实体数据模型旁的“+”号并下载数据模型csv模版，并修改csv后重新上传。

<figure><img src="/files/J9VC8MEffy4D4Peoq3ki" alt=""><figcaption></figcaption></figure>

在本示例中将每个样本所对应的输入或样本文件填写至样本参数列中，第一列的字段"sample\_id"不可修改

<figure><img src="/files/1F5VxMtYkX90iY0MqzOX" alt=""><figcaption></figcaption></figure>

上传完成后如图所示

<figure><img src="/files/X5ieZ9SAlXmXYPRJrZEs" alt=""><figcaption></figcaption></figure>

### 4. 导入工作流

Bio-OS使用工作流描述语言 (WDL) 中的工作流来批处理基因组学数据。一般处理样本数据的 GATK 工具普遍依赖 BAM 文件作为主要格式。有些支持CRAM格式，但我们观察到直接从 CRAM 文件工作时会出现性能问题，因此，我们首先将 CRAM 转换为 BAM。

{% hint style="info" %}
SAM、BAM 和 CRAM 都是原始 SAM 格式的不同形式，这些格式是为保存对齐（或更准确地说，*映射*）的高通量测序数据而定义的。SAM 代表序列比对图，并在[此处](http://samtools.github.io/hts-specs)的标准规范中进行了描述。BAM 和 CRAM 都是 SAM 的压缩形式；BAM（用于二进制对齐图）是一种无损压缩，而 CRAM 的范围可以从无损到有损，具体取决于您想要实现多少压缩（*实际上*最多）。BAM 和 CRAM 拥有与其 SAM 等价物相同的信息，结构方式相同；它们之间的不同之处在于文件本身的编码方式。
{% endhint %}

接下来我们需要将Cram-to-Bam 工作流导入到Workspace中，

1. 点击导入工作流
2. 输入对应的输入项
   1. 工作流名称：输入自定义的工作流名
   2. Git 地址： <https://gitee.com/joy_lee/seq-format-conversion01>
   3. Branch/Tag: v0.47
   4. Main path：CramToBam.wdl

<figure><img src="/files/Z66FBIcEgTqHhK7Tzm9M" alt=""><figcaption></figcaption></figure>

这样就完成了我们所需要的Cram to Bam的转换工作流导入。**此处附WDL源码** [**Gitee 源码**](https://gitee.com/joy_lee/seq-format-conversion01/blob/v0.47/CramToBam.wdl)

```Python
version 1.0 
#WORKFLOW DEFINITION
workflow CramToBamFlow {
    input {
        File ref_fasta
        File ref_fasta_index
        File ref_dict
        File input_cram
        String sample_name
        String gotc_docker = "biocontainers/samtools:v1.7.0_cv4"
    }

 #converts CRAM to SAM to BAM and makes BAI
    call CramToBamTask {
        input:
            ref_fasta = ref_fasta,
            ref_fasta_index = ref_fasta_index,
            ref_dict = ref_dict,
            input_cram = input_cram,
            sample_name = sample_name,
            docker_image = gotc_docker
    }
    #Outputs Bam, Bai, and validation report to the FireCloud data model
    output {
        File outputBam = CramToBamTask.outputBam
        File outputBai = CramToBamTask.outputBai
    }
}

#Task Definitions
task CramToBamTask{
    input{
        #Command parameters
        File ref_fasta
        File ref_fasta_index
        File ref_dict
        File input_cram
        String sample_name

        # Runtime parameters
        #Int addtional_disk_size = 20 
        Int machine_mem_size = 4 
        Int disk_size = 50
        String docker_image
    }
       # Float output_bam_size = size(input_cram, "GB") / 0.60
       # Float ref_size = size(ref_fasta, "GB") + size(ref_fasta_index, "GB") + size(ref_dict, "GB")
       # Int disk_size = ceil(size(input_cram, "GB") + output_bam_size + ref_size) + addtional_disk_size
#Calls samtools view to do the conversion
    command {
        set -eo pipefail

        samtools view -h -T ~{ref_fasta} ~{input_cram} |
        samtools view -b -o ~{sample_name}.bam -
        samtools index -b ~{sample_name}.bam
        mv ~{sample_name}.bam.bai ~{sample_name}.bai
    }

    runtime {
        docker: docker_image
        memory: machine_mem_size + " GB"
        disk: disk_size + " GB"
    }
    #Outputs a BAM and BAI with the same sample name
    output {
     File outputBam = "~{sample_name}.bam"
     File outputBai = "~{sample_name}.bai"
    }
}
```

### 5. 运行工作流

刚才我们已经完成了工作流的导入，那么接下来我们将对导入的工作流进行运行。

1. 选择我们刚才导入的Cram-to-Bam工作流
2. 在这里我们需要配置运行选项和运行参数，在运行选项中，选择刚才我们第一步中所上传的数据实体，并指定实体数据。

<figure><img src="/files/A2GN3ylLMgcyMrcKdKuy" alt=""><figcaption></figcaption></figure>

3. 配置输入参数，选中输入参数选项卡，并按照如下参数进行输入，当然当输入参数较多时，可以使用上传JSON文件的方式进行快速地导入。

{% hint style="info" %}
Note：工作流中使用的镜像需要支持当前的架构，如未arm64架构，则需要匹配的镜像
{% endhint %}

<figure><img src="/files/FdvfaUexn0MvajWi8qFy" alt=""><figcaption></figcaption></figure>

4. 配置输出参数，使用this.bai作为bai文件的输出属性，this.bam作为bam文件的属性列

{% hint style="info" %}
通过this.列名，定义输出的结果输出到所选择的数据表的指定列中；如果原表格中没有此列则按照列名新加列；如果原表格有对应的列，则会将直接将新结果进行填充或覆盖
{% endhint %}

<figure><img src="/files/AbWJtvUzcBsUvESNnAiZ" alt=""><figcaption></figcaption></figure>

5. 点击右上角【开始分析】，此时工作流会通过Cromwell工作流引擎进行分析，结果可在【分析历史】中进行查看

<br>

### 6. 查看分析结果

1. 点击分析历史，可查看过往的投递的历史，在Bio-OS中，投递意味着可以同时运行多样本的批量分析人物，点击右下角工作流配置，可查看当次投递时的工作流配置，也可从配置中发起再次投递

<figure><img src="/files/fvndwzyROHrGZmqnDDIL" alt=""><figcaption></figcaption></figure>

2. 点击某个样本的运行详情，可以查看输出文件所在目录，此时可进入对应的NAS存储中找到对应的文件

<figure><img src="/files/bkMCqGkzXSRET37E8MZe" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bio-os.gitbook.io/userguide/zui-jia-shi-jian/for-shi-yong-zhe.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
