text: user180: 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?
  
  user180: 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.
  
original_text: 180: <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>
   180: <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>
  