Shell Scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Scripting
# 1  
Old 10-24-2010
Shell Scripting

shell scripting
From the given input file i want the output (shown below) which is the values of statements starting with Haripin loop and Muti-loop in each structure with its dG no. In input file they are shown in bold case. (original input file is a big one consists of n structures with n statements in this form only)HELP FOR SHELL SCRIPTING IS APPRECIATED. THANKS IN ADVANCE.

General format of output:
Code:
Initial dG no.
Haripin loop:
Value1 - Value2
Value1 - Value2
---- ---- --------
Multi-loop
Value1 - Value2

Initial dG no.
Haripin loop:
Value1 - Value2
Value1 - Value2
Multi-loop
Value1 - Value2

Output
Code:
-25.40

Hairpin loop: 
102-110
65-71
Multi-loop: 
37 - 115

-25.10
Hairpin loop: 
79-85
Multi-loop: 
37 - 93

Input file
Code:
Structure 1
798 mmu-miR 879 
Initial dG = -25.40

External loop: ddG = -0.40 12 ss bases & 2 closing helices.
Helix: ddG = -4.20 4 base pairs.
Multi-loop: ddG = -0.70 External closing pair is C( 37)-G( 115)
Stack: ddG = -2.40 External closing pair is G( 101)-C( 111)
Helix: ddG = -6.90 4 base pairs.
Hairpin loop: ddG = 5.80 Closing pair is A( 102)-U( 110)
Interior loop: ddG = 1.10 External closing pair is A( 61)-U( 75)
Helix: ddG = -3.10 3 base pairs.
Hairpin loop: ddG = 5.00 Closing pair is U( 65)-A( 71)
Stack: ddG = -0.60 External closing pair is U( 11)-G( 18)

Structure 2

798 mmu-miR-879 
Initial dG = -25.10

Interior loop: ddG = 0.90 External closing pair is C( 29)-G( 101)
Multi-loop: ddG = 1.90 External closing pair is C( 37)-G( 93)
Stack: ddG = -2.10 External closing pair is C( 78)-G( 86)
Helix: ddG = -10.30 6 base pairs.
Hairpin loop: ddG = 5.30 Closing pair is U( 79)-A( 85)
Stack: ddG = -3.40 External closing pair is G( 41)-C( 73)


Last edited by Scott; 10-24-2010 at 10:57 AM.. Reason: Added code tags, removed formatting. Please use a descriptive subject
# 2  
Old 10-24-2010
Something approaching:
bash code:
  1. #!/bin/bash
  2. PrintVal()  { C=${C#*(}; C=${C%)*}; echo $C | sed 's/).*( /-/'; }
  3. INFILE=  # Put here the name of your file
  4. while IFS=':=' read A B C
  5. do
  6.    case "$A" in
  7.       "Initial dG ")
  8.          echo -e "\n\n$B\n"
  9.          Hairpins=0
  10.       ;;
  11.       "Hairpin loop")
  12.          ((Hairpins==0)) && echo "$A:"
  13.          PrintVal
  14.          ((Hairpins++))
  15.       ;;
  16.       "Multi-loop")
  17.          echo "$A:"
  18.          PrintVal
  19.       ;;
  20.    esac
  21. done <$INFILE
Result:
Code:
 -25.40

Multi-loop:
37-115
Hairpin loop:
102-110
65-71


 -25.10

Multi-loop:
37-93
Hairpin loop:
79-85

# 3  
Old 10-24-2010
In line3 of the program I placed the file name as

INFILE= sai (here sai is my input file)
and run the shell program with 'sh t1prog'

it is giving error as
line 21: $INFILE: ambiguous redirect
# 4  
Old 10-24-2010
try with ()
Code:
done <($INFILE)

... or back tick ``
# 5  
Old 10-24-2010
I modified as u suggested but it giving error like this
Code:
t2prog: line 21: syntax error near unexpected token `('
t2prog: line 21: `      done <($INFILE)'

Modified program is given here

Code:
#!/bin/bash
PrintVal()  { C=${C#*(}; C=${C%)*}; echo $C | sed 's/).*( /-/'; }
        INFILE=  sai
        while IFS=':=' read A B C
        do
           case "$A" in
              "Initial dG ")
                 echo -e "\n\n$B\n"
                 Hairpins=0
              ;;
              "Hairpin loop")
                 ((Hairpins==0)) && echo "$A:"
                 PrintVal
                 ((Hairpins++))
              ;;
              "Multi-loop")
                 echo "$A:"
                 PrintVal
              ;;
           esac
        done <($INFILE)



---------- Post updated at 04:48 PM ---------- Previous update was at 03:55 PM ----------




The code is working (given below) and executed with original data. A small correction is required. In origianl data file the dG number statement will be generated like this

b Initial dG = -25.10 (i.e. one space from the beginning of the statement; so it is not coming on the output. The input cant change because it is automatically generated. In program make modification to print dG number if it is starting after one space from the beginning. If this statement is from the beginning of the line, the dG value is printing)
In the output, after printing each sequence '-e' is printing. that has to be removed (shown below)

The modified code is like this
--------------------------------
Code:
#!/bin/bash
PrintVal() { C=${C#*(}; C=${C%)*}; echo $C | sed 's/).*( /-/'; }
while IFS=':=' read A B C
do
case "$A" in
"Initial dG ")
echo -e "\n\n$B\n"
Hairpins=0
;;
"Hairpin loop")
((Hairpins==0)) && echo "$A:"
PrintVal
((Hairpins++))
;;
"Multi-loop")
echo "$A:"
PrintVal
;;
esac
done < sai

----------------------------------------
Output after run the program (original data output partial)
Code:
Multi-loop:
37-115
Hairpin loop:
102-110
65-71
12-17
-e


Last edited by Scott; 10-24-2010 at 06:05 PM.. Reason: Please use code tags
# 6  
Old 10-24-2010
what can be tried is to remove all spaces in the A and check for string without spaces with following changes :

Remove the quotes around $A:

line 05: case "$A" in to be replaced by case $A in

and in the 3 case statements:

line 06: "Initial dG ") to be replaced by Initial*)

line 10: "Hairpin loop") to be replaced by Hairpin*)

line 15: "Multi-loop") to be replaced by Multi-loop)

Don't forget to put the * in the first two ones
# 7  
Old 10-24-2010
Quote:
Originally Posted by ctsgnb
try with ()
Code:
done <($INFILE)

... or back tick ``
This means the output of program $INFILE is presented as a file. Using backticks instead means the output of program $INFILE is presented as a variable.

Correct would be:
Code:
done < "$INFILE"



---------- Post updated at 01:42 ---------- Previous update was at 01:39 ----------




Quote:
Originally Posted by kswapnadevi
In line3 of the program I placed the file name as

INFILE= sai (here sai is my input file)
and run the shell program with 'sh t1prog'

it is giving error as
line 21: $INFILE: ambiguous redirect
You have a space between INFILE= and sai. There should be no space there.
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

2. Shell Programming and Scripting

help me in Shell Scripting

Hi there please have a look at the code..i want to create Using a named pipe. Run a find in the background starting in the working directory While this is happening wait for input from the user to ask him which file to find. If the user does not enter any data in 10 seconds ask the user again.... (1 Reply)
Discussion started by: kattak1511
1 Replies

3. Shell Programming and Scripting

Shell scripting

Hi, if in a network there are lots of PCs connected with either windows or linux as operating system.Then what will be the shell script for the same and also if the PC has linux in it then we have to find if it is occupied or unoccupied. If the PC has windows in it then we have to find if it is... (6 Replies)
Discussion started by: akansha singh
6 Replies

4. UNIX for Dummies Questions & Answers

Shell Scripting

Hey I have a data in the file named as outputFile.txt. The data is in the format 123456,12345678912345,400,09/09/09,INACTIVE. I want this output without commas ie 12345612345678912345400090909INACTIVE. Please tell me what to do and clear explain all the terms, as I am new to it. (6 Replies)
Discussion started by: sampandey31
6 Replies

5. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

6. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

7. Android

Android Scripting Environment: Shell Scripting and Android

I just upgraded to Android 2.2 from 2.1. The GPS issue that was troublesome in 2.1 seems to have been fixed. Some of web browsing seems faster, but it could just be my connection is better today ;) Flash works in some browsers but not very good and it is too slow for Flash apps designed for... (0 Replies)
Discussion started by: Neo
0 Replies

8. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

9. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question