# How can I set a Specific chain name for a Structure？(BioStrcuture Package)

**URL:** <https://discourse.julialang.org/t/how-can-i-set-a-specific-chain-name-for-a-structure-biostrcuture-package/50211>\
**Category:** Biology, Health, and Medicine\
**Tags:** package\
**Created:** [November 16, 2020, 5:49am UTC](https://discourse.julialang.org/t/how-can-i-set-a-specific-chain-name-for-a-structure-biostrcuture-package/50211 "2020-11-16T05:49:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wang-Lin-boop](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wang-lin-boop/32/19486_2.png) [@Wang-Lin-boop](https://discourse.julialang.org/u/Wang-Lin-boop)\
**Post date:** [November 16, 2020, 5:49am UTC](https://discourse.julialang.org/t/how-can-i-set-a-specific-chain-name-for-a-structure-biostrcuture-package/50211/1 "2020-11-16T05:49:54Z")

</div>

Recently, I was working on a project dealing with a large number of coordinate files, which required me to convert each chain in some coordinate files with MMCIF/PDBXML/MMTF/PDB format into PDB format. Some of the chains in MMCIF files have long chain names, which makes the writepdb function down due to chain name too long.

How can I set a Specific chain name for a Structure？

I have found a function in biopython to solve this problem:

`set_chain_info` ( _self_ , _chain\_id_ , _chain\_name_ , _num\_groups_ )

Set the chain information.

Parameters

- **chain\_id** – the asym chain id from mmCIF
- **chain\_name** – the auth chain id from mmCIF
- **num\_groups** – the number of groups this chain has.

[https://biopython.org/docs/latest/api/Bio.PDB.mmtf.DefaultParser.html?highlight=set\_chain\_info#Bio.PDB.mmtf.DefaultParser.StructureDecoder.set\_chain\_info](https://biopython.org/docs/latest/api/Bio.PDB.mmtf.DefaultParser.html?highlight=set_chain_info#Bio.PDB.mmtf.DefaultParser.StructureDecoder.set_chain_info)

But I want to solve this problem in Julia, my script is as follows. How can I solve this problem?

```julia
using BioStructures #BioStructures Module to read and write pdb files.

"Module to split a Structure to many single chain pdb file."
function splitStructure(Structure,pdbid::AbstractString,library::AbstractString,singlechainDB::AbstractString)
    for model in Structure
        modelname = modelnumber(model)
        for chain in model
            chainname = chainid(chain)
            try
                writepdb("$singlechainDB/$pdbid-$modelname-$chainname.pdb",chain)
            catch e0
                writemmtf("$singlechainDB/$pdbid-$modelname-$chainname.cif",chain)
                println("$pdbid-$modelname-$chainname has been saved as cif")
            end
        end
    end
end

"Module to split a pdb file to many single chain pdb file."
function getStructuretospilt(pdbid::AbstractString,library::AbstractString,singlechainDB::AbstractString)
    try
        Structure = retrievepdb(pdbid, dir=library)
    catch e1
        try    
            file = downloadpdb(pdbid,dir=library,format=MMCIF)
            Structure = read(file, MMCIF)
        catch e2
            file = downloadpdb(pdbid,dir=library,format=MMTF)
            Structure = read(file, MMTF)
        end
    end
    splitStructure(Structure,pdbid,library,singlechainDB)
    Structure = nothing
end

"Module to download a pdb."
function downloadastructure(pdbid::AbstractString,library::AbstractString)
    try
        downloadpdb(pdbid,dir=library,format=PDB)
    catch e1
        try
            downloadpdb(pdbid,dir=library,format=MMCIF)
        catch e2
            try
                downloadpdb(pdbid,dir=library,format=MMTF)
            catch e3    
                downloadpdb(pdbid,dir=library,format=PDBXML)
            end
        end
    end
end

function main()
    print("What's path of your pdb library?\n")
    library=readline(stdin)
    print("What's path of your pdb list file?\n")
    pdblist=readline(stdin)
    print("What's path of your output pdb library?\n")
    singlechainDB=readline(stdin)
    existpdblist = String[]
    for file in readdir(library)
        filename = split(basename(file),".")[1]
        push!(existpdblist,filename)
    end
    for pdbline in readlines(pdblist)
        Threads.@threads for pdbid in split(pdbline,",")
            findfirst(isequal(pdbid),existpdblist) == nothing || getStructuretospilt(pdbid,library,singlechainDB)
        end
    end
end

main()

```

Thank you for your reading~

---

<div class="post-metadata">

**Author:** ![jgreener64](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jgreener64/32/2483_2.png) [@jgreener64](https://discourse.julialang.org/u/jgreener64)\
**Post date:** [November 16, 2020, 2:10pm UTC](https://discourse.julialang.org/t/how-can-i-set-a-specific-chain-name-for-a-structure-biostrcuture-package/50211/2 "2020-11-16T14:10:31Z")

</div>

You cannot do this currently in BioStructures.jl, sorry, though I’ve had a few requests for it so I’ll try and get it implemented. Follow this issue for more: [https://github.com/BioJulia/BioStructures.jl/issues/22](https://github.com/BioJulia/BioStructures.jl/issues/22)

Just a quick note that `writemmtf("$singlechainDB/$pdbid-$modelname-$chainname.cif",chain)` saves to MMTF format, not mmCIF as stated.

---

<div class="post-metadata">

**Author:** ![Wang-Lin-boop](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wang-lin-boop/32/19486_2.png) [@Wang-Lin-boop](https://discourse.julialang.org/u/Wang-Lin-boop)\
**Post date:** [November 16, 2020, 3:33pm UTC](https://discourse.julialang.org/t/how-can-i-set-a-specific-chain-name-for-a-structure-biostrcuture-package/50211/3 "2020-11-16T15:33:55Z")

</div>

thank you for your reply, BioStructures help me a lot, thank you for your contribution for it!

Yes, it’s a bug in my script, thank you for pointing it out~

---

<div class="post-metadata">

**Author:** ![Wang-Lin-boop](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wang-lin-boop/32/19486_2.png) [@Wang-Lin-boop](https://discourse.julialang.org/u/Wang-Lin-boop)\
**Post date:** [November 18, 2020, 11:06am UTC](https://discourse.julialang.org/t/how-can-i-set-a-specific-chain-name-for-a-structure-biostrcuture-package/50211/4 "2020-11-18T11:06:41Z")

</div>

Hi, do you Remember my question about editing chain name for a Structure? I found a solution in PDBTools.jl, Hope this is useful for BioStructures.jl.

[https://m3g.github.io/PDBTools/stable/readwrite/#Edit-a-PDB-file](https://m3g.github.io/PDBTools/stable/readwrite/#Edit-a-PDB-file)

---

<div class="post-metadata">

**Author:** ![Wang-Lin-boop](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wang-lin-boop/32/19486_2.png) [@Wang-Lin-boop](https://discourse.julialang.org/u/Wang-Lin-boop)\
**Post date:** [November 18, 2020, 2:52pm UTC](https://discourse.julialang.org/t/how-can-i-set-a-specific-chain-name-for-a-structure-biostrcuture-package/50211/5 "2020-11-18T14:52:34Z")

</div>

but it still can’t solve the problem that some chain of MMCIF or MMTF has too long chain name to writing to pdb file…

---

<div class="post-metadata">

**Author:** ![jgreener64](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jgreener64/32/2483_2.png) [@jgreener64](https://discourse.julialang.org/u/jgreener64)\
**Post date:** [November 18, 2020, 3:01pm UTC](https://discourse.julialang.org/t/how-can-i-set-a-specific-chain-name-for-a-structure-biostrcuture-package/50211/6 "2020-11-18T15:01:59Z")

</div>

That was basically why they invented the mmCIF format, to make up for that deficiency in PDB files.

I guess in the 1970s they never considered they would run out of single letter chain IDs within a PDB entry. Structural biology has come on a long way!

---

<div class="post-metadata">

**Author:** ![Wang-Lin-boop](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wang-lin-boop/32/19486_2.png) [@Wang-Lin-boop](https://discourse.julialang.org/u/Wang-Lin-boop)\
**Post date:** [November 18, 2020, 3:26pm UTC](https://discourse.julialang.org/t/how-can-i-set-a-specific-chain-name-for-a-structure-biostrcuture-package/50211/7 "2020-11-18T15:26:13Z")

</div>

yeah, mmCIF is more suitable than PDB for storing huge complex structures, however, most of the computational biology software use PDB format as the first choice…
