The two shell scripts (t1prog and t2prog) are given below they are working fine. The input for the first program is 't1.det' and for second program is 't1.rnaml'. These two input files are in 'dir1' folder. I am executing the shell like 'sh t1prog > t1out' and 'sh t2prog > t2out' from this directory only. Then I am executing a java program 'java RNA'; for this, t1out and t2out are input files used in the program and I am getting the final output on screen.
The input files 't1.det' and 't1.rnaml' are in different folders with same name and with different values. Each folder specifies one gene sequence input files.
In mfold directory there are 5 directors and each directory contains these input files as shown below
Code:
cd mfold
dir1 dir2 dir3 dir4 dir5
cd dir1
t1.det t1.rnaml
cd ..
------
cd dir5
t1.det t1.rnaml
I need a shell script to automate this process like t1prog and t2prog first take the inputs from dir1 folder, run the shell and redirect the output to t1out and t2out and after executing the java program with statment 'java RNA' the output will be redirected to a file like 'RNAout1'. Then takes the inputs from dir2 folder, same process again, and redirect the output to 'RNAout2'. Like this for all inputs values from 5 folders. Modify the two shell scripts given below, to accept the inputs in that way (i think last line of each script to be modified).
shell 1: t1prog
Code:
1. #!/bin/bash
2. PrintVal() { C=${C#*(}; C=${C%)*}; echo $C | sed 's/).*( /-/'; }
3. while IFS=':=' read A B C
4. do
5. case $(echo $A) in
6. Initial*)
7. ((NotFirst)) && { echo; echo; } || NotFirst=1
8. echo ${B#* }; echo
9. Hairpins=0
10. ;;
11.
12. Hairpin*)
13. ((Hairpins==0)) && echo "$A:"
14. PrintVal
15. ((Hairpins++))
16. ;;
17. Multi-loop)
18. echo "$A:"
19. PrintVal
20. ;;
21. esac
22. done <t1.det
shell 2: t2prog
Code:
#!/bin/sh
i=1
while read line
do
freecount=`echo "${line}" | grep -i "free" | wc -l`
poscount=`echo "${line}" | grep -i "position" | wc -l`
if [ $freecount -eq 1 ]
then
rangeoutput=0
else
rangeoutput=1
fi
if [ $rangeoutput -eq 0 ]
then
value=`echo "${line}" | sed -n 's/<.*>\(.*\)<.*>/\1/p'`
echo $value
else
if [ $poscount -eq 1 ]
then
pvalue[$i]=`echo "${line}" | sed -n 's/<.*>\(.*\)<.*>/\1/p'`
if [ $i -eq 2 ]
then
echo "${pvalue[1]} - ${pvalue[2]}"
i=0
fi
i=`expr $i + 1`
fi
fi
done <t1.rnaml
for one input set in 'dir1' i am executing like this
Code:
sh t1prog > t1out
sh t2prog > t2out
java RNA
for inputs in different directories and executing these and redirecting the final ouput after executing 'java RNA' statement to a file is needed.
WRITING A SHELL SCRIPT FOR THIS IS HIGHLY APPRCIATED. THANKS IN ADVANCE.
For the script that would wrap the whole process, that's my proposition:
Code:
#!/bin/bash
cd mfold
for Dir in Dir*
do
cd $Dir
t1.det >t1out && t1.rnaml>t2out
java RNA
cd ..
done
If You want just one script to perform that, use functions and the script would look like:
Code:
#!/bin/bash
ParseT1() {
# PASTE THE CODE OF FIRST SCRIPT
}
ParseT2() {
# PASTE THE CODE OF SECOND SCRIPT
}
cd mfold
for Dir in dir* # or just * if there are only subdirectories
do
cd $Dir
ParseT1 >t1out && ParseT2 >t2out
java RNA
cd ..
done
Last edited by frans; 11-07-2010 at 04:04 AM..
Reason: forgot java RNA
I used the second code using Parse T1 and Parse T2. After execution of that code output files 't1out' and 't2out' are generated in sub directories 'dir1' and 'dir2' but final output is not coming and giving the following errors. I am giving Java code also for information. . When executing t1prog, t2prog followed by JAVA, I am getting output for a single data set like 'sh t1prog > t1out; sh t2prog > t2out; java RNA'. For this, it is giving errors, I am in confusion.
Code:
Exception in thread "main" java.lang.NoClassDefFoundError: RNA
Caused by: java.lang.ClassNotFoundException: RNA
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
The above set of errors are coming for each 'dir'. If two direcotries are there 'dir1' and 'dir2'; two times the same set of errors coming and finally getting the $ prompt.
Code:
import java.io.*;
import java.util.*;
public class RNA
{
public static final String inputFile1 = "t1out";
public static final String inputFile2 = "t2out";
private Hashtable rangeTable = new Hashtable();
private ArrayList multiloopList = new ArrayList();
private ArrayList hairPinList = new ArrayList();
private int STARTRANGE = -1;
private int DEFAULTSTARTRANGE = 40;
private static final boolean DEBUG = false;
public RNA()
{
}
public RNA(int STARTRANGE)
{
this.STARTRANGE = STARTRANGE;
if(STARTRANGE == -1) this.STARTRANGE = DEFAULTSTARTRANGE;
}
private void init() throws IOException
{
FileReader fileReaderObj = new FileReader(inputFile2);
BufferedReader bufferReaderObj = new BufferedReader(fileReaderObj);
String line = null;
line = bufferReaderObj.readLine();
String saveLine = null;
boolean advanced = false;
while(line != null)
{
advanced = false;
if (line.trim().startsWith("-"))
{
saveLine = line.trim();
String multiloop = new String();
if(DEBUG) System.out.println(saveLine);
while (((line = bufferReaderObj.readLine()) != null) && !line.trim().startsWith("Hairpin loop:"))
{
if (line.trim().equals("Multi-loop:"))
{
multiloop = bufferReaderObj.readLine();
multiloopList = new ArrayList();
multiloopList.add("Multi-loop:");
multiloopList.add(multiloop);
if(DEBUG) System.out.println("multiloop--->"+multiloop);
}
}
if(line.trim().equals("Hairpin loop:"))
{
multiloopList.add("Hairpin loop:");
while (((line = bufferReaderObj.readLine()) != null) && !line.trim().startsWith("-"))
{
advanced = true;
if(line.trim().length() > 0)multiloopList.add(line);
if(DEBUG) System.out.println("Hairpin loop--->"+line);
}
if(DEBUG) System.out.println("Hairpin loop size--->"+multiloopList.size());
}
}
rangeTable.put(saveLine,multiloopList);
if(!advanced )
{
line = bufferReaderObj.readLine();
//System.out.println("advance-->"+line);
}
}
}
public void compare() throws IOException
{
FileReader fileReaderObj = new FileReader(inputFile1);
BufferedReader bufferReaderObj = new BufferedReader(fileReaderObj);
boolean advanced = false;
String line = null;
line = bufferReaderObj.readLine();
while(line != null)
{
advanced = false;
System.out.println(line);
if(line.trim().startsWith("-"))
{
List list = (ArrayList)rangeTable.get(line.trim());
while(((line = bufferReaderObj.readLine()) != null) && !line.trim().startsWith("-"))
{
String []result = line.trim().split("-");
int left = Integer.parseInt(result[0].trim());
int right = Integer.parseInt(result[1].trim());
if(left > STARTRANGE && (right - left) > 20)
{
String multiLoopRange = (String)list.get(1);
String []result1 = multiLoopRange.trim().split("-");
int multiLoopLeft = Integer.parseInt(result1[0].trim());
int multiLoopRight = Integer.parseInt(result1[1].trim());
if(left > multiLoopLeft)
{
for(int i = 3; i < list.size(); i++)
{
String hairPinValue = (String)list.get(i);
String []hairPinresult = hairPinValue.trim().split("-");
int hairPinleft = Integer.parseInt(hairPinresult[0].trim());
int hairPinRight = Integer.parseInt(hairPinresult[1].trim());
if(left < hairPinleft && right > hairPinRight)
{
int microRNAleft = left + 21;
if (microRNAleft <= hairPinleft)
{
System.out.println("MIRNA--"+ left +":"+microRNAleft);
}
int microRNAright = hairPinRight + 1 + 21;
if(microRNAright <= right)
{
System.out.println("MIRNA--"+ (hairPinRight+1)+":"+microRNAright);
}
}
}
}
}
advanced = true;
}
}
if(!advanced) line = bufferReaderObj.readLine();
}
}
public static void main(String []r) throws Exception
{
System.out.println("Enter the Starting Micro RNA range to be computed...");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String sInputRange = in.readLine();
int inputRange = -1;
try
{
inputRange = Integer.parseInt(sInputRange);
}
catch(Exception e)
{
System.out.println("Invalid input...computing with DEFAULT Micro RNA Range 40.");
inputRange = -1;
}
RNA rna = new RNA(inputRange);
rna.init();
rna.compare();
}
}
[/CODE]
Quote:
Originally Posted by frans
Please, use code tags to make the code more readable.
Howto:
Select the text corresponding to code
Click on the 'code' button in the editor's toolbar
The t2prog can really be optimized. Here is my proposition for the same functionality:
For the script that would wrap the whole process, that's my proposition:
Code:
#!/bin/bash
cd mfold
for Dir in Dir*
do
cd $Dir
t1.det >t1out && t1.rnaml>t2out
java RNA
cd ..
done
If You want just one script to perform that, use functions and the script would look like:
Code:
#!/bin/bash
ParseT1() {
# PASTE THE CODE OF FIRST SCRIPT
}
ParseT2() {
# PASTE THE CODE OF SECOND SCRIPT
}
cd mfold
for Dir in dir* # or just * if there are only subdirectories
do
cd $Dir
ParseT1 >t1out && ParseT2 >t2out
java RNA
cd ..
done
Last edited by kswapnadevi; 11-08-2010 at 09:48 PM..
Reason: modified
The optimized code t2prog is executed. When I am working with real datasets it consists of additional data values in the tag like <secondary-structure-display> .....</secondary-structure-dispaly> that are also coming in output. For each sequence of data, these secondary structure is also there. This secondary structure not taking into the consideration for output sir. I am giving the additional part of the data part in input file that is to be ommitted. The given shell script 't2prog' to be modified sir.
For the script that would wrap the whole process, that's my proposition:
Code:
#!/bin/bash
cd mfold
for Dir in Dir*
do
cd $Dir
t1.det >t1out && t1.rnaml>t2out
java RNA
cd ..
done
If You want just one script to perform that, use functions and the script would look like:
Code:
#!/bin/bash
ParseT1() {
# PASTE THE CODE OF FIRST SCRIPT
}
ParseT2() {
# PASTE THE CODE OF SECOND SCRIPT
}
cd mfold
for Dir in dir* # or just * if there are only subdirectories
do
cd $Dir
ParseT1 >t1out && ParseT2 >t2out
java RNA
cd ..
done
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)
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)
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)
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)
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)
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)
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)