With sed
:
$ sed 's/^>\(\([^.]*\).*\):/>\1\2:/' file
>IxoscaEVm2293881t1.p1 type:complete len:255 gc:Universal IxoscaEVm2293881t1:13-219(+)
MFLRQLGAPRFYYARLFLRFIAVTIGPFLKSFPEKMLFLTYFPFYFWQRFSNINKRRKLLPATFLTLG
>IxoscaEVm2798449t1.p1 type:partial5 len:345 gc:Universal IxoscaEVm2798449t1:1-183(+)
CEEREKLQFPTLVELFSTMKLLSCFPGLTLNIMGANIKRVRVSKLLNKYFAVEGRTWRVC
>IxoscaEVm3186316t1.p1 type:partial5 len:317 gc:Universal IxoscaEVm3186316t1:315-151(+)
NRIARLIGKNAEAGSVNYFFVSGSLLFGKPEQCALNLFLFLHSYYTLPFFIWCI
The sed
substitution replaces everything from the start of any line beginning with the standard Fasta header marker >
, up to and including the last :
on that line. While doing so, it captures the part between the >
up to (but not including) the first dot (this is the identifier), and also the whole start of the line, but not the final :
character. The replacement part of the substitution is the line up to where the identifier should be inserted, followed by the identifier and a :
.
A similar thing with an in-line Perl subsitution:
$ perl -pe 's/^>((.*?)\..*):/>$1$2:/' file
>IxoscaEVm2293881t1.p1 type:complete len:255 gc:Universal IxoscaEVm2293881t1:13-219(+)
MFLRQLGAPRFYYARLFLRFIAVTIGPFLKSFPEKMLFLTYFPFYFWQRFSNINKRRKLLPATFLTLG
>IxoscaEVm2798449t1.p1 type:partial5 len:345 gc:Universal IxoscaEVm2798449t1:1-183(+)
CEEREKLQFPTLVELFSTMKLLSCFPGLTLNIMGANIKRVRVSKLLNKYFAVEGRTWRVC
>IxoscaEVm3186316t1.p1 type:partial5 len:317 gc:Universal IxoscaEVm3186316t1:315-151(+)
NRIARLIGKNAEAGSVNYFFVSGSLLFGKPEQCALNLFLFLHSYYTLPFFIWCI
With Perl again, using named capture groups:
$ perl -pe 's/^>(?<partial_line>(?<id>.*?)\..*):/>$+{partial_line}$+{id}:/' file
>IxoscaEVm2293881t1.p1 type:complete len:255 gc:Universal IxoscaEVm2293881t1:13-219(+)
MFLRQLGAPRFYYARLFLRFIAVTIGPFLKSFPEKMLFLTYFPFYFWQRFSNINKRRKLLPATFLTLG
>IxoscaEVm2798449t1.p1 type:partial5 len:345 gc:Universal IxoscaEVm2798449t1:1-183(+)
CEEREKLQFPTLVELFSTMKLLSCFPGLTLNIMGANIKRVRVSKLLNKYFAVEGRTWRVC
>IxoscaEVm3186316t1.p1 type:partial5 len:317 gc:Universal IxoscaEVm3186316t1:315-151(+)
NRIARLIGKNAEAGSVNYFFVSGSLLFGKPEQCALNLFLFLHSYYTLPFFIWCI
>
) and the first whitespace? Can you have spaces in the first "part"?>
denotes a quote, you can't easily have>
in that. It's a pain, I know. Just stick to code and forget the bold, even though they help. So, can we be sure there will be no whitespace before the.p1
? And will it always be a.p1
, never.p2
or nothing at all?IxoscaEVm2293881t1
? I haven't seen that style before. What database does it refer to? Sorry. I'm just curious, I thought I knew most of the standard ones.