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 :

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:

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:

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.

Something like this?

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

Hi Franklin52
I try your code just now.
Unfortunately, It can't work :frowning:
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):

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.

Your comment doesn't make any sense, I can't guess what's wrong.

This is my output with your input file:

$ 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
$

Thanks a lot Frankin52 :slight_smile:
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

 
ls *.fq > file
cat file
awk -F_ 'a[$1]{print "fastq_to_fasta "a[$1]" "$0; next} {a[$1]=$0}' file
 

I believe it should be work nice.
Thanks a lot and again, Frankin52 :)
$ 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 :slight_smile:
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.

Your code is fantastic and work fast:b:

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

Explanation:

awk -F_

Change the default field separator

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

{a[$1]=$0}

a[$1] is empty on this line. Here the element is filled with the value of the current line

Thanks a lot for your explanation, Franklin52:)
I feel more comfortable and understanding about the reason of your code now.
I really appreciate for your explanation.
Thanks again :b:

Hi, Franklin52.
The code that you suggestion:

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

[/quote]
It facing a problem if my input is look the following:
01234_ABC_L1_CDE_PE1.fq
01234_ABC_L1_CDE_PE2.fq
01234_ABC_L2_CDE_PE1.fq
01234_ABC_L2_CDE_PE2.fq
01234_ABC_L3_CDE_PE1.fq
01234_ABC_L3_CDE_PE2.fq
05512_ABC_L1_CDE_PE1.fq
05512_ABC_L1_CDE_PE2.fq
05512_ABC_L2_CDE_PE1.fq
05512_ABC_L2_CDE_PE2.fq
05512_ABC_L3_CDE_PE1.fq
05512_ABC_L3_CDE_PE2.fq

The code can't give the desired output like:
fastq_to_fasta 01234_ABC_L1_CDE_PE1.fq 01234_ABC_L1_CDE_PE2.fq
fastq_to_fasta 01234_ABC_L2_CDE_PE1.fq 01234_ABC_L2_CDE_PE2.fq
fastq_to_fasta 01234_ABC_L3_CDE_PE1.fq 01234_ABC_L3_CDE_PE2.fq
fastq_to_fasta 05512_ABC_L1_CDE_PE1.fq 01234_ABC_L1_CDE_PE2.fq
fastq_to_fasta 05512_ABC_L2_CDE_PE1.fq 01234_ABC_L2_CDE_PE2.fq
fastq_to_fasta 05512_ABC_L3_CDE_PE1.fq 01234_ABC_L3_CDE_PE2.fq

Unfortunately, the code give me another result :frowning:
Franklin52, do you have any better idea to get my desired output result?
Actually I got try a way like this:

awk '/PE1/{print $_}' file_name > file_name.txt
awk '/PE2/{print $_}' file_name > file_name2.txt
paste -d ' ' file_name.txt file_name2.txt > file_name.output.txt

At last, I vi and add the "fastq_to_fasta" inside file_name.output.txt one line by one line:(
It seem like quite troublesome and wasting time :frowning:
I think it should got faster way. Just I still can't get it:(
Franklin52, thanks again for your help and sorry if bring you any inconvenience.

awk '{a = $0; getline; print "fastq_to_fasta " a " " $0}' file

That's what you want ?

# cat file
01234_ABC_L1_CDE_PE1.fq
01234_ABC_L1_CDE_PE2.fq
01234_ABC_L2_CDE_PE1.fq
01234_ABC_L2_CDE_PE2.fq
01234_ABC_L3_CDE_PE1.fq
01234_ABC_L3_CDE_PE2.fq
05512_ABC_L1_CDE_PE1.fq
05512_ABC_L1_CDE_PE2.fq
05512_ABC_L2_CDE_PE1.fq
05512_ABC_L2_CDE_PE2.fq
05512_ABC_L3_CDE_PE1.fq
05512_ABC_L3_CDE_PE2.fq
# awk 'NR%2{printf "fastq_to_fasta" FS $0 FS;next}1' file
fastq_to_fasta 01234_ABC_L1_CDE_PE1.fq 01234_ABC_L1_CDE_PE2.fq
fastq_to_fasta 01234_ABC_L2_CDE_PE1.fq 01234_ABC_L2_CDE_PE2.fq
fastq_to_fasta 01234_ABC_L3_CDE_PE1.fq 01234_ABC_L3_CDE_PE2.fq
fastq_to_fasta 05512_ABC_L1_CDE_PE1.fq 05512_ABC_L1_CDE_PE2.fq
fastq_to_fasta 05512_ABC_L2_CDE_PE1.fq 05512_ABC_L2_CDE_PE2.fq
fastq_to_fasta 05512_ABC_L3_CDE_PE1.fq 05512_ABC_L3_CDE_PE2.fq

thanks a lot, danmero:)
Your code work excellent and solve my trouble nice.
Can you roughly explain the reason of your code?
Thanks again.