|
修改蛋白pdb文件链号时间:2025-04-28 #!/bin/bash shuru="before-mix.pdb" #输入文件,只能处理pdb格式,并且=两边不能有空格 shuchu="before-mix3.pdb" #输出文件,只能处理pdb格式,并且=两边不能有空格 # 检查源文件存在性及可读性 if [[ ! -f "$shuru" || ! -r "$shuru" ]]; then echo "错误:before-mix.pdb 文件不存在或不可读" >&2 exit 1 fi # 创建临时工作文件防止空输出 tmp_file=$(mktemp) trap 'rm -f "$tmp_file"' EXIT # 多阶段字符替换(含行长度校验),22字符为chain号,所以下面输入21,“5,5839s”表示需要替换的链号,根据实际需要手动负责增加 sed -E \ -e "5,5839s/^(.{21})./\1A/; t; " \ -e "5840,11644s/^(.{21})./\1B/; t;" \ -e "11645,17518s/^(.{21})./\1C/; t; " \ -e "17519,23353s/^(.{21})./\1D/; t; " \ -e "23354,23439s/^(.{21})./\1E/; t; " \ -e "23440,23525s/^(.{21})./\1F/; t; " \ -e "23526,23611s/^(.{21})./\1G/; t; " \ -e "23612,23697s/^(.{21})./\1H/; t; " \ "$shuru" > "$tmp_file" # 结果有效性检查 if [[ -s "$tmp_file" ]]; then mv "$tmp_file" "$shuchu" echo "生成成功:$shuchu" else echo "错误:输出文件为空,请检查输入文件格式" >&2 exit 2 fi |