使用jcvi绘制共线性时,调整整条染色体的方向

黑线是原来的共线性,绿线是染色体边界

在使用jcvi绘制共线性时,经常遇到整条染色体反了的情况,比如上图,非常痛苦。

这个时候其实是希望调整方向,把黑线调整为蓝线/绿线的情况。

这里提供了一个解决方法:
bash tac.sh EfonChr6.bed Efon.length > EfonChr6tac.bed
ln -s EfonChr6.cds > EfonChr6tac.cds
重新运行jcvi
python -m jcvi.compara.catalog ortholog --no_strip_names ErothChr6 EfonChr6tac

EfonChr6.bed/EfonChr6.cds是原来的输入文件,会得到上图黑线所示的共线性
Efon.length是基因组每条染色体的长度文件,第一列染色体名,第二列长度

EfonChr6tac.bed/EfonChr6tac.cds是处理后的输入文件,可以将染色体整个方向倒过来


cat tac.sh

#!/bin/bash

bed_file=$1
length_file=$2

# 读取染色体长度信息,存入 associative array
declare -A chr_lengths
while read -r chr len; do
    chr_lengths["$chr"]=$len
done < "$length_file"

# 处理 BED 文件
while read -r chr start end name score strand; do
    len=${chr_lengths["$chr"]}
    if [[ -z "$len" ]]; then
        echo "Error: Cannot find length for chromosome $chr" >&2
        continue
    fi
    new_start=$((len - end))
    new_end=$((len - start))

    # 翻转方向
    if [[ "$strand" == "+" ]]; then
        new_strand="-"
    elif [[ "$strand" == "-" ]]; then
        new_strand="+"
    else
        new_strand="$strand"
    fi

    echo -e "$chr\t$new_start\t$new_end\t$name\t$score\t$new_strand"
done < "$bed_file"

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容