<p>First of all, those are not fasta sequences. Fasta is a specific format, and requires a <code>&gt;</code> followed by a sequence identifier on one line and the one or more lines of sequence.</p>
<p>Assuming you really have two files in the format you show, you can do:</p>
<pre><code><span class="math-container">$ awk -F: '{ gsub(/ /,""); if(NR==FNR){bbone[$2]; next} for(b in bbone){print b$</span>2}}' file1 file2 
GTCATGCTACGTGCTACGTGCTCGTCGCGCCGCTAGTGTAGCTGCTACTCCG
ACTGCGTATGTCAGCATATAGACCGCCTCGCTAGTGTAGCTGCTACTCCG
CGTAGCTAGCTAGCTCGTGTCGTGATGCTACTCCGCTAGTGTAGCTGCTACTCCG
</code></pre>
<p>The <code>gsub(/ /,&quot;&quot;);</code> just removes the extra space you have in <code>file1</code> after each <code>:</code>. If you also want to have the sequence names as you show, use:</p>
<pre><code><span class="math-container">$ awk -F: '{ gsub(/ /,""); if(NR==FNR){bbone[$2]="Backbone"NR; next} for(b in bbone){print bbone[b]"+"$1":", b$</span>2}}' file1 file2 
Backbone3+sequence_1: GTCATGCTACGTGCTACGTGCTCGTCGCGCCGCTAGTGTAGCTGCTACTCCG
Backbone1+sequence_1: ACTGCGTATGTCAGCATATAGACCGCCTCGCTAGTGTAGCTGCTACTCCG
Backbone2+sequence_1: CGTAGCTAGCTAGCTCGTGTCGTGATGCTACTCCGCTAGTGTAGCTGCTACTCCG
</code></pre>
<p>If you really need to do this in python for some reason, please edit your question and show us your python script so we have something to work on and expand. I really don't want to write a whole python program for something so trivial.</p>

CC BY-SA 4.0
2020-11-20T10:58:13.010Z
2020-11-20T11:18:28.540Z
2020-11-20T11:18:28.540Z
terdon
<p>I have three backbone and i want to concatenate 70 sequence into these backbone.
such like:
fasta file 1:</p>
<pre><code>Backbone1: ACTGCGTATGTCAGCATATAGACCGCCT
Backbone2: CGTAGCTAGCTAGCTCGTGTCGTGATGCTACTC
Backbone3: GTCATGCTACGTGCTACGTGCTCGTCGCGC
</code></pre>
<p>fasta file 2:</p>
<pre><code>sequence_1:CGCTAGTGTAGCTGCTACTCCG
</code></pre>
<p>output sequence:</p>
<pre><code>Backbone1+sequence_1: ACTGCGTATGTCAGCATATAGACCGCCTCGCTAGTGTAGCTGCTACTCCG
Backbone2+sequence_1: CGTAGCTAGCTAGCTCGTGTCGTGATGCTACTCCGCTAGTGTAGCTGCTACTCCG
Backbone3+sequence_1: GTCATGCTACGTGCTACGTGCTCGTCGCGCCGCTAGTGTAGCTGCTACTCCGs
</code></pre>

CC BY-SA 4.0
2020-11-18T11:27:32.340Z
Use Biopython's seqio
M__
CC BY-SA 4.0
2020-11-18T12:19:54.423Z
Can you give me some tips for writing codes?
xuechun zhang
<python><sequence-analysis><phylogenetics>
How to concatenate two fasta sequences by py
# How to concatenate two fasta sequences by py

(Asked by: username_0 on 2020-11-18)

I have three backbone and i want to concatenate 70 sequence into these backbone.
such like:
fasta file 1:
Backbone1: ACTGCGTATGTCAGCATATAGACCGCCT
Backbone2: CGTAGCTAGCTAGCTCGTGTCGTGATGCTACTC
Backbone3: GTCATGCTACGTGCTACGTGCTCGTCGCGC

fasta file 2:
sequence_1:CGCTAGTGTAGCTGCTACTCCG

output sequence:
Backbone1+sequence_1: ACTGCGTATGTCAGCATATAGACCGCCTCGCTAGTGTAGCTGCTACTCCG
Backbone2+sequence_1: CGTAGCTAGCTAGCTCGTGTCGTGATGCTACTCCGCTAGTGTAGCTGCTACTCCG
Backbone3+sequence_1: GTCATGCTACGTGCTACGTGCTCGTCGCGCCGCTAGTGTAGCTGCTACTCCGs

**Tags:** python, sequence-analysis, phylogenetics
> **Comments:**
> **username_1**: Use Biopython's seqio  
> **username_0**: Can you give me some tips for writing codes?  

---

## 1 answers

### Answer by username_2 on 2020-11-20. Score: 1

First of all, those are not fasta sequences. Fasta is a specific format, and requires a > followed by a sequence identifier on one line and the one or more lines of sequence.
Assuming you really have two files in the format you show, you can do:
$ awk -F: '{ gsub(/ /,""); if(NR==FNR){bbone[$2]; next} for(b in bbone){print b$2}}' file1 file2 
GTCATGCTACGTGCTACGTGCTCGTCGCGCCGCTAGTGTAGCTGCTACTCCG
ACTGCGTATGTCAGCATATAGACCGCCTCGCTAGTGTAGCTGCTACTCCG
CGTAGCTAGCTAGCTCGTGTCGTGATGCTACTCCGCTAGTGTAGCTGCTACTCCG

The gsub(/ /,""); just removes the extra space you have in file1 after each :. If you also want to have the sequence names as you show, use:
$ awk -F: '{ gsub(/ /,""); if(NR==FNR){bbone[$2]="Backbone"NR; next} for(b in bbone){print bbone[b]"+"$1":", b$2}}' file1 file2 
Backbone3+sequence_1: GTCATGCTACGTGCTACGTGCTCGTCGCGCCGCTAGTGTAGCTGCTACTCCG
Backbone1+sequence_1: ACTGCGTATGTCAGCATATAGACCGCCTCGCTAGTGTAGCTGCTACTCCG
Backbone2+sequence_1: CGTAGCTAGCTAGCTCGTGTCGTGATGCTACTCCGCTAGTGTAGCTGCTACTCCG

If you really need to do this in python for some reason, please edit your question and show us your python script so we have something to work on and expand. I really don't want to write a whole python program for something so trivial.


---

