# Renaming IDs in a GFF3

**URL:** https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687
**Category:** Biology, Health, and Medicine
**Created:** [January 23, 2020, 8:15am UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687 "2020-01-23T08:15:13Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![mictadlo](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@mictadlo](https://discourse.julialang.org/u/mictadlo)
#### Post date: [January 24, 2020, 1:46pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/21 "2020-01-24T13:46:25Z")

</div>

Thank you. How is it possible to replace the current ID (g4510) with NbV1Ch08004510, NbV1Ch08004510.t1, NbV1Ch08004510t1.3UTR1, …?

```julia
NbV1Ch08_g4510_004510
NbV1Ch08_g4510.t1_004510
NbV1Ch08_g4510.t1.3UTR1_004510
NbV1Ch08_g4510.t1.exon1_004510
NbV1Ch08_g4510.t1.CDS1_004510
NbV1Ch08_g4510.t1.CDS2_004510
NbV1Ch08_g4510.t1.exon2_004510
NbV1Ch08_g4510.t1.5UTR1_004510

```

Thank you in advance,

---

<div class="post-metadata">

### Author: ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)
#### Post date: [January 24, 2020, 1:48pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/22 "2020-01-24T13:48:46Z")

</div>

Remove `_$(gene.ID)_` from the `println` line.

---

<div class="post-metadata">

### Author: ![mictadlo](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@mictadlo](https://discourse.julialang.org/u/mictadlo)
#### Post date: [January 24, 2020, 1:53pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/23 "2020-01-24T13:53:00Z")

</div>

Sorry, I have forgotten to mention that I would like to write the new ID into a new Gff3 file. Could you please show me how to replace the old ID with the new one and write the changes to a new GFF3 file?  
Thank you in advance,

---

<div class="post-metadata">

### Author: ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)
#### Post date: [January 24, 2020, 1:58pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/24 "2020-01-24T13:58:27Z")

</div>

```julia
using GenomicAnnotations
chrs = readgff("/Users/lorencm/projects/bioinf-scripts/data/NbV1Ch08-augustus.hints_utr.gff3")
currentID = 0
for gene in @genes(chrs, !ismissing(:ID))
    if feature(gene) == :gene
        global currentID += 1
    end
    newID = lpad(currentID, 6, '0')
    gene.ID = "$(parent(gene).name)$newID"
end
printgff("newIDs.gff", chrs)

```

---

<div class="post-metadata">

### Author: ![mictadlo](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@mictadlo](https://discourse.julialang.org/u/mictadlo)
#### Post date: [January 24, 2020, 2:03pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/25 "2020-01-24T14:03:43Z")

</div>

Thank you but `newIDs.gff` still contain the old IDs.

What could cause it?

Thank you in advance,

---

<div class="post-metadata">

### Author: ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)
#### Post date: [January 24, 2020, 2:10pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/26 "2020-01-24T14:10:02Z")

</div>

Not when I run it exactly as I wrote it in my last post. The important part is this line:

```julia
    gene.ID = "$(parent(gene).name)$newID"

```

Are you sure that you ran it?

---

<div class="post-metadata">

### Author: ![mictadlo](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@mictadlo](https://discourse.julialang.org/u/mictadlo)
#### Post date: [January 24, 2020, 2:14pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/27 "2020-01-24T14:14:08Z")

</div>

I copied your code from your previous post and it appears it did not change the IDs. I am not quite sure what could go wrong?

---

<div class="post-metadata">

### Author: ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)
#### Post date: [January 24, 2020, 2:41pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/28 "2020-01-24T14:41:26Z")

</div>

When I run the code I posted, newIDs.gff contains this (first 5 lines):

```julia
##gff-version 3
NbV1Ch08	AUGUSTUS	gene	7015	29794	0.01	-	.	ID=NbV1Ch08000001
NbV1Ch08	AUGUSTUS	mRNA	7015	29794	0.01	-	.	ID=NbV1Ch08000001;Parent=g1
NbV1Ch08	AUGUSTUS	transcription_end_site	7015	7015	.	-	.	Parent=g1.t1
NbV1Ch08	AUGUSTUS	three_prime_utr	7015	8531	0.2	-	.	ID=NbV1Ch08000001;Parent=g1.t1

```

If you don’t get this my best guess is that you aren’t running the previous version where it said `println(...)` instead of `gene.ID = ...`.

---

<div class="post-metadata">

### Author: ![mictadlo](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@mictadlo](https://discourse.julialang.org/u/mictadlo)
#### Post date: [January 24, 2020, 2:56pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/29 "2020-01-24T14:56:55Z")

</div>

Thank you, I closed everything and reopen and new IDs appeared in the new GFF3 file. However, I noticed that e.g. `Parent=g1` has not been updated to `Parent=NbV1Ch08000001`. How is it possible to change Parent ID?

Thank you in advance,

---

<div class="post-metadata">

### Author: ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)
#### Post date: [January 24, 2020, 3:01pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/30 "2020-01-24T15:01:35Z")

</div>

Same way as ID:

```julia
for ...
    ...
    gene.Parent = "$(parent(gene).name)$newID"
end

```

---

<div class="post-metadata">

### Author: ![mictadlo](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@mictadlo](https://discourse.julialang.org/u/mictadlo)
#### Post date: [January 24, 2020, 3:09pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/31 "2020-01-24T15:09:18Z")

</div>

Unfortunately, it adds a Parent ID to gene feature which did not contain a Parent before. The other problem is that it missed to change it for the below features:

- transcription\_end\_site
- transcription\_start\_site
- stop\_codon
- start\_codon
- intron

How would it possible to fix it?

Thank you in advance,

---

<div class="post-metadata">

### Author: ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)
#### Post date: [January 24, 2020, 4:16pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/32 "2020-01-24T16:16:05Z")

</div>

The features you mention don’t have IDs, so they were skipped in the for loop. Try this instead:

```julia
using GenomicAnnotations
chrs = readgff("/Users/lorencm/projects/bioinf-scripts/data/NbV1Ch08-augustus.hints_utr.gff3")
currentID = 0
for gene in @genes(chrs)
    if feature(gene) == :gene
        global currentID += 1
    end
    newID = lpad(currentID, 6, '0')
    if !ismissing(gene.ID)
        gene.ID = "$(parent(gene).name)$newID"
    end
    if !ismissing(gene.Parent)
        gene.Parent = "$(parent(gene).name)$newID"
    end
end
printgff("newIDs.gff", chrs)

```

---

<div class="post-metadata">

### Author: ![mictadlo](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@mictadlo](https://discourse.julialang.org/u/mictadlo)
#### Post date: [January 24, 2020, 10:27pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/33 "2020-01-24T22:27:21Z")

</div>

Thank you. Unfortunately,`println("$(parent(gene).ID)")` did not work to change chromosome name to a single digit in the following way:

```julia
NbV1Ch01 change to 1
NbV1Ch02 change to 2
NbV1Ch03 change to 3
NbV1Ch04 change to 4
NbV1Ch05 change to 5
NbV1Ch06 change to 6
NbV1Ch07 change to 7
NbV1Ch08 change to 8
NbV1Ch09 change to 9
NbV1Ch10 change to 10

```

Does `GenomicAnnotations` keep an index count of all available chromosomes?

**Update**  
How is it possible to reset `currentID` when for each new chromosome?

Thank you in advance,

---

<div class="post-metadata">

### Author: ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)
#### Post date: [January 25, 2020, 3:22pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/34 "2020-01-25T15:22:55Z")

</div>

Chromosome names are accessed with `chr.name`. You can change the names separately for each chromosome.

---

<div class="post-metadata">

### Author: ![mictadlo](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@mictadlo](https://discourse.julialang.org/u/mictadlo)
#### Post date: [January 25, 2020, 8:34pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/35 "2020-01-25T20:34:56Z")

</div>

Thank you, How is it possible to reset `currentID` when for each new chromosome?

```julia
NbV1Ch01 AUGUSTUS gene 126794454 126798741 0.63 - . ID=NbV1Ch01000001
...
NbV1Ch02 AUGUSTUS gene 20516 31934 0.15 + . ID=NbV1Ch02000001
...
NbV1Ch02 AUGUSTUS gene 39413 43534 0.02 - . ID=NbV1Ch02000002
...

```

Thank you in advance,

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [January 25, 2020, 9:37pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/36 "2020-01-25T21:37:18Z")

</div>

@mictadlo while I’m sure your inquiries are will meant, this thread now has 15 or so separate questions - from the outside, it looks a lot like you’re asking @kdyrhage to do your project for you. They’ve gamely responded to all of your questions, but I’m not seeing any evidence that you’re attempting to solve your problems in your own before asking for the next thing.

Perhaps it’s none of my business, but open source communities depend on people volunteering their time, and the longevity of a community being willing to help users with problems depends on those users making a good faith effort to solve their own problems first.

I’m all for asking for help - I’m here and on slack all the time asking for help, and I encourage you to continue to use this forum when you run into a problem you can’t figure out, but this thread is getting a bit out of hand. At the very least, please mark your original question as answered and start a new thread if you have an additional problem, show what you’ve done to try to solve it on your own, and where else you’ve looked. If you don’t know where to look or how to approach solving problems on your own, that’s work asking too - that’s a skill that we’ve all had to learn at some point!

---

<div class="post-metadata">

### Author: ![mictadlo](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@mictadlo](https://discourse.julialang.org/u/mictadlo)
#### Post date: [January 25, 2020, 11:12pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/37 "2020-01-25T23:12:53Z")

</div>

To receiving so quick and awesome help I am very thankful. Furthermore, I understand @kevbonham’s view, and I’m sorry not to post my fail attempts to get a particular code running. For example, I tried to reset `currentID` variable in the following way:

```julia
currentID = 0
for gene in @genes(chrs)
    if feature(gene) == :gene
        global currentID += 1
    else
        global currentID = 0
    end

```

Unfortunately, the above code reset `currentID` variable for each gene rather than when a new chromosome starts:

```julia
NbV1Ch01 AUGUSTUS gene 126794454 126798741 0.63 - . ID=NbV1Ch01000001
NbV1Ch01 AUGUSTUS mRNA 126794454 126798741 0.33 - . ID=NbV1Ch01000000;Parent=NbV1Ch01000000
NbV1Ch01 AUGUSTUS transcription_end_site 126794454 126794454 . - . Parent=NbV1Ch01000000
NbV1Ch01 AUGUSTUS three_prime_utr 126794454 126795005 0.37 - . ID=NbV1Ch01000000;Parent=NbV1Ch01000000
NbV1Ch01 AUGUSTUS exon 126794454 126795005 . - . ID=NbV1Ch01000000;Parent=NbV1Ch01000000
...
NbV1Ch02 AUGUSTUS gene 20516 31934 0.15 + . ID=NbV1Ch02000001
NbV1Ch02 AUGUSTUS mRNA 20516 31934 0.15 + . ID=NbV1Ch02000000;Parent=NbV1Ch02000000
NbV1Ch02 AUGUSTUS transcription_start_site 20516 20516 . + . Parent=NbV1Ch02000000
NbV1Ch02 AUGUSTUS five_prime_utr 20516 20532 0.39 + . ID=NbV1Ch02000000;Parent=NbV1Ch02000000
NbV1Ch02 AUGUSTUS exon 20516 20574 . + . ID=NbV1Ch02000000;Parent=NbV1Ch02000000
...
NbV1Ch02 AUGUSTUS gene 39413 43534 0.02 - . ID=NbV1Ch02000001
NbV1Ch02 AUGUSTUS mRNA 39413 43534 0.02 - . ID=NbV1Ch02000000;Parent=NbV1Ch02000000
NbV1Ch02 AUGUSTUS transcription_end_site 39413 39413 . - . Parent=NbV1Ch02000000
NbV1Ch02 AUGUSTUS three_prime_utr 39413 39477 0.57 - . ID=NbV1Ch02000000;Parent=NbV1Ch02000000
NbV1Ch02 AUGUSTUS exon 39413 40064 . - . ID=NbV1Ch02000000;Parent=NbV1Ch02000000
...

```

Maybe, the awesome solutions which I recieved could be used to add to `GenomicAnnotations.jl`’s documentation?

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [January 26, 2020, 1:59pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/38 "2020-01-26T13:59:25Z")

</div>

> [@mictadlo](#):
>
> Maybe, the awesome solutions which I recieved could be used to add to `GenomicAnnotations.jl` 's documentation

I’m guessing that that if you’re up to making a PR to add them, it would be welcome.

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [January 26, 2020, 5:10pm UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/39 "2020-01-26T17:10:32Z")

</div>

> [@mictadlo](#):
>
> Unfortunately, the above code reset `currentID` variable for each gene rather than when a new chromosome starts:

What have you tried to solve or get more info about the problem? Have you used print statements to check what the values of `gene`, `feature(gene)`, and `currentID` are on each loop? Often when you have these kinds of problems, stepping through a couple runs of your loop and checking the values will reveal the problem.

---

<div class="post-metadata">

### Author: ![Ward9250](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ward9250/32/42768_2.png) [@Ward9250](https://discourse.julialang.org/u/Ward9250)
#### Post date: [January 27, 2020, 1:32am UTC](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687/40 "2020-01-27T01:32:44Z")

</div>

> I see you didn’t use the FSM approach that other BioJulia parsers use.

To be fair it is difficult at first. I haven’t bothered framing my GFA parsing and stuff using Automa yet since it’s not a priority for me. But I know how to do this with Automa if a FSM adaptation of GenomicAnnotations parser is desirable.

[Previous page](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687.md?page=1)

[Next page](https://discourse.julialang.org/t/renaming-ids-in-a-gff3/33687.md?page=3)
