This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How can i find longest sequence in fasta file on terminal

I have protein file in fasta format and I want to find the longest sequence. What should I do? The codes I found did not solve my problem, as they included the nomenclature in the length.

fasta sequence

Thank you for answer but your code is not solve my problem :/

so, show us what you tried, and what failed and why.

I thought I included the code but I'm unpublished, sorry.

The fasta file I have is as follows

>NP_000005.3 alpha-2-macroglobulin isoform a precursor [Homo sapiens] MGKNKLLHPSLVLLLLVLLPTDAS....
>NP_000010.1 acetyl-CoA acetyltransferase, mitochondrial isoform b precursor [Homo sapiens] MAVLAALLRSGARSRSPLLRLVQEI... . . .

I want to find the longest sequence in this file excluding naming. However, when I run the code you have given, it does not give an error and does not give any output.

the code(s) was/were an inspiration. You should understand it and adapt it to your needs.

1 answer

Here is one option using GNU tools only:

grep -v '>' seq.fasta | awk '{print $0"\t"length($0)}' | sort -n -k2 -r

Your code is work but not gives sequence properties. (ID etc)

Well, you need to specify what you want your output to look like. In general, if you want better control then I suggest you look into bioawk or biopython SeqIO.

Log in to answer this question.