Execution problem with repeat the same program with two set of same data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution problem with repeat the same program with two set of same data
# 1  
Old 10-09-2009
Execution problem with repeat the same program with two set of same data

I got a program named as "fastq_to_fasta".
I got a long list of file all named as AB1 and AB2.

My input file is :
Code:
071022_L1_AB1.fq
012121_L1_AB1.fq
021213_L1_AB1.fq
012153_L1_AB1.fq
071022_L1_AB2.fq
012121_L1_AB2.fq
021213_L1_AB2.fq
012153_L1_AB2.fq
.
.
.
.
.
.

My desired output is write a work script or a text file look like this:
Code:
fastq_to_fasta 071022_L1_AB1.fq 071022_L1_AB2.fq
fastq_to_fasta 012121_L1_AB1.fq 012121_L1_AB2.fq
fastq_to_fasta 021213_L1_AB1.fq 021213_L1_AB2.fq
fastq_to_fasta 012153_L1_AB1.fq 012153_L1_AB2.fq
.
.
.
.
.
.

Actually all the long list of file need to do the same program like:
Code:
fastq_to_fasta <XXXXAB1.fq> <XXXXAB2.fq>
Same XXXXAB1 must work with same XXXXAB2

Does anybody know by using awk command or any other programming language can easy for me to get my desired output result.

Thanks a lot.

Last edited by Franklin52; 10-09-2009 at 08:18 AM.. Reason: Please use code tags!
# 2  
Old 10-09-2009
Something like this?

Code:
awk -F_ 'a[$1]{print "fastq_to_fasta "a[$1]" "$0; next} {a[$1]=$0}' file

# 3  
Old 10-09-2009
Hi Franklin52
I try your code just now.
Unfortunately, It can't work Smilie
Do you have any other idea?
Actually I just want to produce a long list of below (based on same XXX_AB1 with XXX_AB2):
Code:
fastq_to_fasta 071022_L1_AB1.fq 071022_L1_AB2.fq
fastq_to_fasta 012121_L1_AB1.fq 012121_L1_AB2.fq
fastq_to_fasta 021213_L1_AB1.fq 021213_L1_AB2.fq
fastq_to_fasta 012153_L1_AB1.fq 012153_L1_AB2.fq
.
.
.

.
.
.

Thanks a lot for your help.

Last edited by Franklin52; 10-09-2009 at 08:58 AM.. Reason: Use code tags please!!!!!!
# 4  
Old 10-09-2009
Quote:
Originally Posted by patrick87
Hi Franklin52
I try your code just now.
Unfortunately, It can't work Smilie
Do you have any other idea?
Your comment doesn't make any sense, I can't guess what's wrong.

This is my output with your input file:

Code:
$ cat file
071022_L1_AB1.fq
012121_L1_AB1.fq
021213_L1_AB1.fq
012153_L1_AB1.fq
071022_L1_AB2.fq
012121_L1_AB2.fq
021213_L1_AB2.fq
012153_L1_AB2.fq
$ awk -F_ 'a[$1]{print "fastq_to_fasta "a[$1]" "$0; next} {a[$1]=$0}' file
fastq_to_fasta 071022_L1_AB1.fq 071022_L1_AB2.fq
fastq_to_fasta 012121_L1_AB1.fq 012121_L1_AB2.fq
fastq_to_fasta 021213_L1_AB1.fq 021213_L1_AB2.fq
fastq_to_fasta 012153_L1_AB1.fq 012153_L1_AB2.fq
$

# 5  
Old 10-09-2009
Thanks a lot Frankin52 Smilie
I think I understand what you mean now.
Maybe I type some error and let you misunderstanding it.
Actually all the *_AB1.fq and *_AB2.fq all are long list of "file" not the list of "contents" in a file.
But it should be not a problem.
I just do
[code]
ls *.fq > file
cat file
awk -F_ 'a[$1]{print "fastq_to_fasta "a[$1]" "$0; next} {a[$1]=$0}' file
[code]

I believe it should be work nice.
Thanks a lot and again, Frankin52 Smilie
Code:
$ cat file
071022_L1_AB1.fq
012121_L1_AB1.fq
021213_L1_AB1.fq
012153_L1_AB1.fq
071022_L1_AB2.fq
012121_L1_AB2.fq
021213_L1_AB2.fq
012153_L1_AB2.fq
$ awk -F_ 'a[$1]{print "fastq_to_fasta "a[$1]" "$0; next} {a[$1]=$0}' file
fastq_to_fasta 071022_L1_AB1.fq 071022_L1_AB2.fq
fastq_to_fasta 012121_L1_AB1.fq 012121_L1_AB2.fq
fastq_to_fasta 021213_L1_AB1.fq 021213_L1_AB2.fq
fastq_to_fasta 012153_L1_AB1.fq 012153_L1_AB2.fq
$

[/quote]

---------- Post updated at 08:33 PM ---------- Previous update was at 07:35 PM ----------

Thanks again Franklin52.
Your suggestion code look cool Smilie
I will go and find out the reason why you write this code.
Thus able to edit it next time to solve another similar problem.
In between, can I roughly know the explanation of your code written?
Sorry if bring you any inconvenience.
Quote:
Originally Posted by Franklin52
Code:

awk -F_ 'a[$1]{print "fastq_to_fasta "a[$1]" "$0; next} {a[$1]=$0}' file

Your code is fantastic and work fastSmilie
# 6  
Old 10-10-2009
Code:
awk -F_ 'a[$1]{print "fastq_to_fasta "a[$1]" "$0; next} {a[$1]=$0}' file

Explanation:

Code:
awk -F_

Change the default field separator

Code:
a[$1]{print "fastq_to_fasta "a[$1]" "$0; next}

If element a[$1] of array a has a value, print a[$1], a space and the current line. Read the next line

Code:
{a[$1]=$0}

a[$1] is empty on this line. Here the element is filled with the value of the current line
# 7  
Old 10-10-2009
Thanks a lot for your explanation, Franklin52Smilie
I feel more comfortable and understanding about the reason of your code now.
I really appreciate for your explanation.
Thanks again Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execution of compressed program

I need UNIX scripts for polling, Uncompressing files and moving files between directory. Also trying to save file paths and any other variables in an independent file (.env) and use these at runtime by executing this file in the main script. (3 Replies)
Discussion started by: new2script
3 Replies

2. Programming

Help with C++ program execution.

//Find the root of the equation (x^2)-2 by bisection method. #include<iostream> using namespace std; double a,x; double f(double x) { return ((x*x)-2); } //Suppose the function is (x*x)-2. void calcx(double a1,double b1) { x =... (2 Replies)
Discussion started by: poonam.gaigole
2 Replies

3. Programming

Debugging Program during execution

I have made use of 'valgrind' and -finstrument-functions compiler option for debugging / analyzing code. Both the options lets us know the line / file being executed to some extent. Is there a generic way that lets program dump the file:line it is getting executed dumped to a log file during... (3 Replies)
Discussion started by: uunniixx
3 Replies

4. Programming

A program to trace execution of another program

Hi, I wanted to know if i can write a program using switches and signals, etc to trace execution of other unix program which calls c program internally. If yes how? If not with signals and switches then are there any other methods apart from debugging with gdb/dbx. (3 Replies)
Discussion started by: jiten_hegde
3 Replies

5. Shell Programming and Scripting

Problem while execution of second set of commands

Hi, I have a shell script with code . perf.env cd $QRY_DIR for SHELL_FILE in sql1 do export SNAME=$SHELL_FILE ${SCRIPT_DIR}/perf_qry.sh ${SPOOL_DIR} ${DB_ENVNAME} ${NAME} & RC=$(expr ${RC:-0} + $? ) sleep 60 if then echo sysdate>test1 echo query1.txt>>test1 grep -i... (6 Replies)
Discussion started by: ran16
6 Replies

6. Shell Programming and Scripting

Problem while execution of second set of commands

Hi, I have a shell script with code . perf.env cd $QRY_DIR for SHELL_FILE in sql1 do export SNAME=$SHELL_FILE ${SCRIPT_DIR}/perf_qry.sh ${SPOOL_DIR} ${DB_ENVNAME} ${NAME} & RC=$(expr ${RC:-0} + $? ) sleep 60 if then echo sysdate>test1 echo query1.txt>>test1 grep -i... (0 Replies)
Discussion started by: ran16
0 Replies

7. UNIX for Dummies Questions & Answers

multifile c program compilation and execution

i am using unix os and my program is divided in two text files .:):) how to compile and make one executable file, using unix command. (1 Reply)
Discussion started by: alokmishra8
1 Replies

8. Shell Programming and Scripting

echo just 1 line before execution/set +-x

Suppose that you want to mostly not echo commands inside your script during execution (e.g. to not bog the user down with details that they do not care about) but that there is the occaisional script line that you would like to echo before you execute it. Is there an elegant way to achieve this?... (3 Replies)
Discussion started by: fabulous2
3 Replies

9. UNIX for Dummies Questions & Answers

Set User ID on execution mode.

I have a directory. To this directory, for Group bits combination, it is showing as 's'. Which I found out, it means "Set User ID on execution mode". Within this directory I am not able to create subfolder. Does it mean, only the Owner of this directory will be able to create subdirectories &... (5 Replies)
Discussion started by: videsh77
5 Replies

10. UNIX for Dummies Questions & Answers

Question on Set User ID on Execution

I want group to run one of my unix script as me . I when the script is run it should have my permission's not the group . I tried this : 1.Have a file called y.ksh cat y.ksh echo $LOGNAME >ak_test 2.Output file has this permission -rwx------ ak_test 3.Then I chnaged... (7 Replies)
Discussion started by: akrathi
7 Replies
Login or Register to Ask a Question