View Single Post
Old 10-05-2018, 06:59 AM   #2
Richard Finney
Senior Member
 
Location: bethesda

Join Date: Feb 2009
Posts: 700
Default

This does not "add to both ends", I think I need a little more information to do that.

Here's a solution that appends "N"s.
It's not R, it's an awk "one liner" (a long one liner) :

cat yourseqfile | awk '{ a[count++] = $0; if (length($0)>l)l=length($0) } END { for (i=0; i<count; i++) { printf("%s",a[i]); for (j=length(a[i]); j<l; j++) printf "N"; printf("\n"); } }'

example:
bash-3.2$ cat yourseqfile
START

A
ACGTACGTACGTACGTACGTACGT
ACGTACGTACGTAC
ACGT
DONE

bash-3.2$ cat yourseqfile | awk '{ a[count++] = $0; if (length($0)>l)l=length($0) } END { for (i=0; i<count; i++) { printf("%s",a[i]); for (j=length(a[i]); j<l; j++) printf "N"; printf("\n"); } }'
STARTNNNNNNNNNNNNNNNNNNN
NNNNNNNNNNNNNNNNNNNNNNNN
ANNNNNNNNNNNNNNNNNNNNNNN
ACGTACGTACGTACGTACGTACGT
ACGTACGTACGTACNNNNNNNNNN
ACGTNNNNNNNNNNNNNNNNNNNN
DONENNNNNNNNNNNNNNNNNNNN

Last edited by Richard Finney; 10-05-2018 at 07:18 AM.
Richard Finney is offline   Reply With Quote