This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Editing of fasta header file

Hello Everyone

Can anyone you guide me editing of the fasta header file. My fasta header file shown as below

>NP_006556.1 transcriptional repressor CTCF isoform 1 [Homo sapiens]

And I want the output should have

>NP_006556.1 [Homo sapiens]

Thank you so much

gene

I used the following command

sed -E 's/>(.+)::(.+)/>\2_\1/' als.fasta > out.fasta

That pattern doesn't match your example header above in the way you need it to. Use [^ ]+ to capture the first part and \[.+\] to capture the second.

Could you please help with the command. I tried with the pattern you mentioned but it did not work

it did not work

Please be more specific. Show us an example of an input line, the exact command you ran and the result it yields, as well as how this result differs from your expected result.

Please find the command used for running it.

sed 's|\[^ ]+::\[.+\]' als.fasta > out.fasta

and it shows the error as

"s|\[^ ]+::\[.+\]": unterminated substitute pattern.

try to google "sed unterminated substitute pattern" ....

I need to use grep command to extract the pattern the organism name in brackets

I need to use grep command to extract the pattern the organism name in brackets

If you are sure that there are only two brackets per line and the species name is always between them, you can use this:

awk -F [ '{print $2}' als.fasta | awk -F ] '{print $1}' > out.fasta

0 answers

No answers yet.

Log in to answer this question.