<p>I have not received any answer to the question, so I created a small tool to fix the file myself.</p>

<p>I am assuming as per the question that there are perfect matches upstream and downstream to the new sequence, and that anything in between can be deleted/updated by the new sequence.</p>

<p>Given the first_n and last_n bases of the diagram in the question, and the entire patch sequence, we can create a single-line string of the reference with <code>seqtk seq -l9999999 -</code> and then edit it with the line below (in Perl regex):</p>

<pre><code><span class="math-container">$chromosome_str =~ s/$</span>first_n.+<span class="math-container">$last_n/$</span>patch/i
</code></pre>

<p>This creates the new string that can be used as the new fasta file.</p>

CC BY-SA 4.0
2019-10-21T08:53:51.513Z
2019-10-21T09:40:47.163Z
2019-10-21T09:40:47.163Z
719016
<p>You can give a try with <code>megamerger</code> from the <code>emboss</code> suite if you have (almost) perfect sequence match.</p>

<p>In case the gap within your <code>chr.fasta</code> complicates the sequence alignment and hence the resulting contig, you can generate a "tiling path" with: upstream of the gap from <code>chr.fasta</code> + <code>contig.fasta</code> + downstream of the gap from <code>chr.fasta</code> (there should be sequence overlaps of course)</p>

<p>In a (more realistic) scenario where there is no perfect sequence match between the overlapping regions, you can fall back to <code>emboss merger</code>, however, it is not designed to work on large sequences.</p>

CC BY-SA 4.0
2019-10-21T09:54:41.717Z
2019-10-21T09:54:41.717Z
haci
<p>I want to fix a chromosome of around 50-100Mb (<code>chr.fasta</code>) for a region that is missing a few kilobases of data. I have the missing sequence with a window upstream and downstream that matches perfectly to the reference (<code>contig.fasta</code>).</p>

<p>What's the best way to produce a new chromosome, <code>fixed.fasta</code> that contains the new data from <code>contig.fasta</code>?</p>

<p>See depiction below:</p>

<pre><code>chr.fasta    |---------------------------------------------------   -------------|
contig.fasta                                                   |-===-|
</code></pre>

<p>Final intended result:</p>

<pre><code>fixed.fasta  |---------------------------------------------------===-------------|
</code></pre>

<p>Any ideas?</p>

<assembly><chromosomes>
fixing chromosome with new contig
# fixing chromosome with new contig

(Asked by: username_0 on 2019-10-18)

I want to fix a chromosome of around 50-100Mb (chr.fasta) for a region that is missing a few kilobases of data. I have the missing sequence with a window upstream and downstream that matches perfectly to the reference (contig.fasta).
What's the best way to produce a new chromosome, fixed.fasta that contains the new data from contig.fasta?
See depiction below:
chr.fasta    |---------------------------------------------------   -------------|
contig.fasta                                                   |-===-|

Final intended result:
fixed.fasta  |---------------------------------------------------===-------------|

Any ideas?

**Tags:** assembly, chromosomes

---

## 2 answers

### Answer by username_0 on 2019-10-21. Score: 1

I have not received any answer to the question, so I created a small tool to fix the file myself.
I am assuming as per the question that there are perfect matches upstream and downstream to the new sequence, and that anything in between can be deleted/updated by the new sequence.
Given the first_n and last_n bases of the diagram in the question, and the entire patch sequence, we can create a single-line string of the reference with seqtk seq -l9999999 - and then edit it with the line below (in Perl regex):
$chromosome_str =~ s/$first_n.+$last_n/$patch/i

This creates the new string that can be used as the new fasta file.


---

### Answer by username_1 on 2019-10-21. Score: 0

You can give a try with `megamerger` from the `emboss` suite if you have (almost) perfect sequence match.

In case the gap within your `chr.fasta` complicates the sequence alignment and hence the resulting contig, you can generate a "tiling path" with: upstream of the gap from `chr.fasta` + `contig.fasta` + downstream of the gap from `chr.fasta` (there should be sequence overlaps of course)

In a (more realistic) scenario where there is no perfect sequence match between the overlapping regions, you can fall back to `emboss merger`, however, it is not designed to work on large sequences.


---

