<p>I have no idea what do you want to do with fasta files reformatted like this, but I think something like this should do the job (untested):</p>
<pre><code>from Bio import SeqIO 
import sys 

for olig_fasta in SeqIO.parse(sys.argv[1], &quot;fasta&quot;):

  name = olig_fasta.name
  seq = str(olig_fasta.seq)
  seq_len = str(len(olig_fasta.seq))

  print(&quot;\t&quot;.join([name, seq_len, seq]))
</code></pre>

CC BY-SA 4.0
2020-11-15T17:04:57.273Z
Based on OP's desired order, it should be `print("\t".join([name, str(seq_len), seq])`.
Ram RS
CC BY-SA 4.0
2020-11-15T18:17:19.027Z
Yeah, you can prin `Seq`, but to manipulate it as a string one needs to convert it to string using `str` command (I edited the answer, now it should work)
Kamil S Jaron
CC BY-SA 4.0
2020-11-15T16:22:03.680Z
2020-11-15T18:16:27.293Z
2020-11-15T18:16:27.293Z
Kamil S Jaron
<p>I am working on a fasta file and am writing my command in nano within command-line and executing using python, also within a command line.</p>
<p>My objective is to get my command to provide me with a tab delimited file with three columns: first column should contain my <strong>sequence name</strong>, second column should provide me with my <strong>sequence length</strong>, and the third column should show the <strong>sequence itself</strong>.</p>
<p>I have written the following command so far within nano:</p>
<p>For example, I would like my command to provide me with the desired output and with the following order: Gene name ; Gene length ; Gene seq</p>
<pre><code>A06842X 45 GORHQRIHQEERHEUWOHRPPTRWFAWWEAKJNFWEJQEFQEPRT

Jb4329PC 21 LDHKQAJTYOWEPLKFREEQW
</code></pre>

CC BY-SA 4.0
2020-11-15T18:03:47.243Z
Hi @KamilSJaron, I appreciate the help! The reason why I am doing this is because it makes it easier for me to easily detect which genes I could disregard if they are over  a certain length. For the command below, I tried it, but I received a "TypeError: sequence item 2: expected str instance, Seq found". I tried googling this but was not able to find anything.
AlphaQueUp
CC BY-SA 4.0
2020-11-15T18:20:06.690Z
Yeah, I forgot to convert the `Seq` class to `str` class before creating the line, see the edit, it should work now. Regarding the utility of such table, I guess I would always get the gene length on the fly (every time you have the sequence of a gene is really easy to get the length too in any language).
Kamil S Jaron
<python><fasta><assembly><file-formats>
Is there a simple command for outputting a tab delimited columns?
# Is there a simple command for outputting a tab delimited columns?

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

I am working on a fasta file and am writing my command in nano within command-line and executing using python, also within a command line.
My objective is to get my command to provide me with a tab delimited file with three columns: first column should contain my sequence name, second column should provide me with my sequence length, and the third column should show the sequence itself.
I have written the following command so far within nano:
For example, I would like my command to provide me with the desired output and with the following order: Gene name ; Gene length ; Gene seq
A06842X 45 GORHQRIHQEERHEUWOHRPPTRWFAWWEAKJNFWEJQEFQEPRT

Jb4329PC 21 LDHKQAJTYOWEPLKFREEQW

**Tags:** python, fasta, assembly, file-formats
> **Comments:**
> **username_0**: Hi @KamilSJaron, I appreciate the help! The reason why I am doing this is because it makes it easier for me to easily detect which genes I could disregard if they are over  a certain length. For the command below, I tried it, but I received a "TypeError: sequence item 2: expected str instance, Seq found". I tried googling this but was not able to find anything.  
> **username_1**: Yeah, I forgot to convert the `Seq` class to `str` class before creating the line, see the edit, it should work now. Regarding the utility of such table, I guess I would always get the gene length on the fly (every time you have the sequence of a gene is really easy to get the length too in any language).  

---

## 1 answers

### Answer by username_1 on 2020-11-15. Score: 1 | Accepted answer

I have no idea what do you want to do with fasta files reformatted like this, but I think something like this should do the job (untested):
from Bio import SeqIO 
import sys 

for olig_fasta in SeqIO.parse(sys.argv[1], "fasta"):

  name = olig_fasta.name
  seq = str(olig_fasta.seq)
  seq_len = str(len(olig_fasta.seq))

  print("\t".join([name, seq_len, seq]))

> **Comments:**
> **username_2**: Based on OP's desired order, it should be `print("\t".join([name, str(seq_len), seq])`.  
> **username_1**: Yeah, you can prin `Seq`, but to manipulate it as a string one needs to convert it to string using `str` command (I edited the answer, now it should work)  

---

