Poly character into mono character


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Poly character into mono character
# 1  
Old 02-10-2010
Bug Poly character into mono character

Hi,

Can anyone teach me by using perl.

let say i have an input file that content like below:

->line_01
aaabbbDDDTTTUSSy
->line_02
cccdddEEESSSGTTT
->line_03
xxxxyyyyzzzzzzzzzz

want the above input file content to become output file like below (every 2nd line after ->... become mono alphabet):

->line_01
abDTUSy
->line_02
cdESGTTT
->line_03
xyz

Thks..

Last edited by eisya10; 02-17-2010 at 11:57 PM..
# 2  
Old 02-11-2010
Try:

Code:
#!/usr/bin/perl 
$var=reverse ("AAAACCCTGGATTTCCCCAATTTTTTTTTTTTT");
while($v=chop($var)) {  print $v if($v ne $prev); $prev=$v; }

# 3  
Old 02-11-2010
Hi ,

I have written the below script. Hope this will help you.

Code:
#!/bin/ksh

echo "Enter your string containing poly character :"
read input_string

prev_char=`echo $input_string | cut -c1`

string_length=`echo $input_string | wc -c`

i=1
monostring=$prev_char

while [ $i -le $string_length ]
do
curr_char=`echo $input_string | cut -c$i`
if [ "$curr_char" != "$prev_char" ]
then
    monostring=`echo ${monostring}${curr_char}`
fi
prev_char=$curr_char
i=$(($i+1))
done

echo "\nThe mono character output is :\n $monostring"

~ Jash

Last edited by pludi; 02-11-2010 at 04:02 PM.. Reason: code tags, please...
# 4  
Old 02-11-2010
Code:
$ echo AAAACCCTGGATTTCCCCAATTTTTTTTTTTTT | tr -s [A-Z]
ACTGATCAT

Code:
$ echo AAAACCCTGGATTTCCCCAATTTTTTTTTTTTT | sed "s/\(.\)\1\{1,\}/\1/g"
ACTGATCAT

# 5  
Old 02-11-2010
Rats... anbu23 posted essentially the exact answer that came to mind...

Just out of curiosity, does this relate to nucleobase analysis?
# 6  
Old 02-11-2010
I have no idea about nucleobase analysis
# 7  
Old 02-15-2010
Quote:
Originally Posted by anbu23
I have no idea about nucleobase analysis
Sorry, I meant my question for the OP.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

2. UNIX for Advanced & Expert Users

Replace certain character at specific place with related character

hello i have file with 100k records and each one has certain value that starts at 28th column and certain value that starts at 88th column e.g. 1st file <25>1234567 ..... <88> 8573785485 i have aditional file with values which are related to value that starts at 88th column of the... (1 Reply)
Discussion started by: dell1520
1 Replies

3. Shell Programming and Scripting

Finding a certain character in a filename and count the characters up to the certain character

Hello, I do have folders containing having funny strings in their names and one space. First, I do remove the funny strings and replace the space by an underscore. find . -name '* *' | while read file; do target=`echo "$file" | sed 's/... (2 Replies)
Discussion started by: tempestas
2 Replies

4. Shell Programming and Scripting

File character adjustment based on specific character

i have a reqirement to adjust the data in a file based on a perticular character the sample data is as below 483PDEAN CORRIGAN 52304037528955WAGES 50000 89BP ABCD MASTER352 5434604223735428 4200 58BP SOUTHERN WA848 ... (1 Reply)
Discussion started by: pema.yozer
1 Replies

5. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

6. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

7. UNIX for Dummies Questions & Answers

poly to mono alphabet for every 2nd line

Hi, Can anyone teach me by using perl. let say i have an input file that content like below: ->line_01 aaabbbDDDTTTUSSy ->line_02 cccdddEEESSSGTTT ->line_03 xxxxyyyyzzzzzzzzzz want the above input file content to become output file like below (every 2nd line after ->... become mono... (0 Replies)
Discussion started by: eisya10
0 Replies

8. UNIX for Advanced & Expert Users

if 4th and 5th character of sting -ge 45 then add 1 to 3rd character

I want to know how to, given a string like W87151WR71C, if the 4th and 5th character (in this case 15) are greater than 45, then to add 1 to the 3rd character (in this case 7) and assign the revised string the variable name MODSTRING. Thanks in advance. This is ultimately to grab info from... (6 Replies)
Discussion started by: glev2005
6 Replies

9. Shell Programming and Scripting

Deleting all characters from 350th character to 450th character from the log file

Hi All, I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position. please advice or sample code. (6 Replies)
Discussion started by: rajeshorpu
6 Replies

10. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies
Login or Register to Ask a Question