<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: Insert the sequence at desire location in multi-fasta file with Perl]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/35044/insert-the-sequence-at-desire-location-in-multi-fasta-file-with-perl?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/35044/insert-the-sequence-at-desire-location-in-multi-fasta-file-with-perl?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/35044/insert-the-sequence-at-desire-location-in-multi-fasta-file-with-perl</guid>
	<pubDate>Wed, 03 Jan 2018 10:05:30 -0600</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/35044/insert-the-sequence-at-desire-location-in-multi-fasta-file-with-perl</link>
	<title><![CDATA[Insert the sequence at desire location in multi-fasta file with Perl]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl

use warnings;
use strict;
use Bio::SeqIO;
use Bio::Seq;
use File::Copy;

#ARGV[0] should be in following format --- Keep the coordinate sorted by name+location
#GenomechrName locationStart AlienGene AlienLength

# The coordinate should not overlaps --- next postition shold be bigger than firstpos+alienLen

open(my $fh, &#039;&lt;:encoding(UTF-8)&#039;, $ARGV[0])
or die &quot;Could not open file $ARGV[0] $!&quot;;
my $genome = $ARGV[1]; # input fasta file (genome file)
my $out = &#039;tmp.fa&#039;; # output fasta file

while (&lt;$fh&gt;) {
chomp;
my @tmpLine = split &#039;\t&#039;, $_;
my $chr=$tmpLine[0]; #insertion chromosome
my $pos=$tmpLine[1]; # position of the insertion
my $seqI = $tmpLine[2]; #sequence of the insertion
my $alienLen=$tmpLine[3];

my $seq_in  = Bio::SeqIO-&gt;new( -format =&gt; &#039;fasta&#039;,-file =&gt; $genome);
my $seq_out = Bio::SeqIO-&gt;new( -format =&gt; &#039;fasta&#039;,-file =&gt; &quot;&gt;&quot;.$out);
while( my $seq = $seq_in-&gt;next_seq() ) { 
 
    if($seq-&gt;primary_id eq $chr){
        my $length = length($seq-&gt;seq);    
        my $upstream=substr($seq-&gt;seq, 0, $pos);
        my $downstream=substr($seq-&gt;seq, $pos,$length);        
        my $seq_obj = Bio::Seq-&gt;new(-seq =&gt; $upstream.$seqI.$downstream,-display_id =&gt; $seq-&gt;primary_id,-alphabet =&gt; &quot;dna&quot; );
            $seq_out-&gt;write_seq($seq_obj);
    }
    else{
        $seq_out-&gt;write_seq($seq);
    }
}

my $newLoc = $pos+$alienLen;
print &quot;$_\t$pos\t$newLoc\n&quot;;
move(&quot;$out&quot;,&quot;$genome&quot;);

}</code>]]></description>
	<dc:creator>Jit</dc:creator>
</item>

</channel>
</rss>