Question: Dividing A Protein Sequence Into Equal Parts
0
gravatar for Nitish Mishra
6.1 years ago by
United States
Nitish Mishra30 wrote:

Dear All, I would be happy if anyone can suggest me command (Sed or AWK one line command) to divide each line of file in equal number of part. For example divide each line in 4 part.

Input:

ATGCATHLMNPHLNTPLML

Output:

ATGCA THLMN PHLNT PLML
command-line • 1.4k views
ADD COMMENTlink modified 9 months ago by Biostar ♦♦ 20 • written 6.1 years ago by Nitish Mishra30
4
gravatar for JC
6.1 years ago by
JC6.9k
Mexico
JC6.9k wrote:
echo ATGCATHLMNPHLNTPLML | perl -plane '$s = int((length $_) / 4) + 1; s/(.{$s})/$1 /g;'
ATGCA THLMN PHLNT PLML
ADD COMMENTlink written 6.1 years ago by JC6.9k

When I am giving 38 character as input it gives 4 part; 3 part with 10 charter and last with 8. While I am expecting 2 part with 10 characters and last 2 with 9 character

Input: TGCATHLMNPHLNTPLMLATGCATHLMNPHLNTPLML

Output: ATGCATHLMN PHLNTPLMLA TGCATHLMNP HLNTPLML 10 Char 10 char 10 char 8 char

ADD REPLYlink written 6.1 years ago by Nitish Mishra30

try my unpack below...

ADD REPLYlink written 6.1 years ago by Zev.Kronenberg11k
1
gravatar for Zev.Kronenberg
6.1 years ago by
United States
Zev.Kronenberg11k wrote:

More than one way to skin a cat in perl :-)

echo ATGCATHLMNPHLNTPLML | perl -lane '$lag = "a4" x((length $_)/4); @seqs = unpack $lag, $_; print join " ", @seqs'

Your second example works fine with my code.

input TGCATHLMNPHLNTPLMLATGCATHLMNPHLNTPLML

output TGCA THLM NPHL NTPL MLAT GCAT HLMN PHLN TPLM
ADD COMMENTlink modified 6.1 years ago • written 6.1 years ago by Zev.Kronenberg11k
0
gravatar for Nitish Mishra
6.1 years ago by
United States
Nitish Mishra30 wrote:

When I am giving 38 character as input it gives 4 part; 3 part with 10 charter and last with 8. While I am expecting 2 part with 10 characters and last 2 with 9 character

Input: TGCATHLMNPHLNTPLMLATGCATHLMNPHLNTPLML

Output: ATGCATHLMN PHLNTPLMLA TGCATHLMNP HLNTPLML 10 Char 10 char 10 char 8 char

ADD COMMENTlink written 6.1 years ago by Nitish Mishra30
2

Please do not post new queries as answers; use the comments area below answers from others. Also, what you state you want is different to what you then illustrate by example. Please be precise.

ADD REPLYlink written 6.1 years ago by Neilfws48k
1

Why do you want to do this? Could you please better state what are your preferences? It sounds like: "I want to break a sequence into 4 parts, not necessarily of equal length, being the shortest part the longest possible", is this right?

ADD REPLYlink written 6.1 years ago by miquelduranfrigola760
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 944 users visited in the last hour