SEQanswers

Go Back   SEQanswers > General



Similar Threads
Thread Thread Starter Forum Replies Last Post
Blosum50 average substitution score jyu429 Bioinformatics 0 01-19-2015 03:41 AM
looping sed commands tonybert General 2 11-06-2014 03:38 PM
awk/bash/perl/sed one-liners explained rhinoceros Bioinformatics 1 10-23-2013 03:38 AM
Extracting 22-mers ending in GG from FASTA using sed/awk? Genomics101 Bioinformatics 6 09-16-2013 06:39 AM
sed,head and tail dont work? very interesting. hanifk Bioinformatics 1 10-10-2011 07:58 AM

Reply
 
Thread Tools
Old 03-15-2015, 05:09 AM   #1
yao_licr
Junior Member
 
Location: sweden

Join Date: Jul 2014
Posts: 7
Default substitution using sed or awk

Hi all,
I just start to use sed and awk. I would like to change the following fastq file

@SRR391606.9.1 1 length=50
AGCACCGCGAGGGCGGAGCTGCGTTCTCCTCTGCACAGCTTTCGGTGGTA
+SRR391606.9.1 1 length=50
@9@?<<AA:3>7A/;@?B57@6;++4=4<,=6=+++17/)1?%%%%%%%%
@SRR391606.10.1 2 length=50
GTTGCGTTCTCCTCAGCACAGACCCGGAGAGCACCGCGAGGGCGGAGCTG
+SRR391606.10.1 2 length=50
?BB?BA?AABAB>->ABB=99<AAB++35)137<>:37=<735(2-9492

into following fastq file:

@SRR391606.9 1 length=50
AGCACCGCGAGGGCGGAGCTGCGTTCTCCTCTGCACAGCTTTCGGTGGTA
+SRR391606.9 1 length=50
@9@?<<AA:3>7A/;@?B57@6;++4=4<,=6=+++17/)1?%%%%%%%%
@SRR391606.10 2 length=50
GTTGCGTTCTCCTCAGCACAGACCCGGAGAGCACCGCGAGGGCGGAGCTG
+SRR391606.10 2 length=50
?BB?BA?AABAB>->ABB=99<AAB++35)137<>:37=<735(2-9492

Basically, it is a task to remove the ".1" on every other line. As I have a huge fastq file around 30 Gb, I only put the 9th and 10th reads out of it.

Does anyone know how to do it using sed or awk? Please also explain the script in detail as I am a beginner.

Thanks a lot!

Yao
yao_licr is offline   Reply With Quote
Old 03-15-2015, 06:11 AM   #2
dschika
Member
 
Location: Zurich

Join Date: Mar 2010
Posts: 56
Default

This command should do the job:

Code:
awk '{if ($1 ~ /SRR/) {split($0, T, ".1 "); print T[1], T[2]}  else print $0}' YOURINPUT.fastq
Since you mentioned sed and awk I assume you know that $1 = first field, $2 = second field (fields separated by whitespaces if not defined otherwise by FS) and $0 = whole line.

The command checks if in the first field SRR is present ("if ($1 ~ /SRR/)"). If yes, it splits the content of the first line by ".1 " and stores the result in T. In this case ".1 " can be found only once in each line with SRR. Therefore, printing of T[0] and T[1] results in the line without ".1 ".

If the line does not contain SRR (i.e., we are at a line with sequence or quality values) print the whole line.
dschika is offline   Reply With Quote
Old 03-15-2015, 07:36 AM   #3
yao_licr
Junior Member
 
Location: sweden

Join Date: Jul 2014
Posts: 7
Default

Thanks for the detailed explanation. It works well.
yao_licr is offline   Reply With Quote
Old 03-15-2015, 08:02 AM   #4
dschika
Member
 
Location: Zurich

Join Date: Mar 2010
Posts: 56
Default

No problem, I just realized, that I was thinking way to complicated:

sed 's/\.1 / /g' YOURINPUT.fastq > out.fastq

Just replace ".1 " with " " and escape the "." with a backslash.
dschika is offline   Reply With Quote
Old 03-15-2015, 08:11 AM   #5
yao_licr
Junior Member
 
Location: sweden

Join Date: Jul 2014
Posts: 7
Default

Sorry, ".1" is the pattern to be replace by " ", so why do you put an empty space after 1? I mean the empty space in "/\.1 /" .

Thanks!
yao_licr is offline   Reply With Quote
Old 03-15-2015, 08:17 AM   #6
yao_licr
Junior Member
 
Location: sweden

Join Date: Jul 2014
Posts: 7
Default

I got it now, as I have .1.1 in the first read; if there is no empty space after "\.1", both of them will be replaced. In your script, ".1 " is the pattern but not ".1" .

Thanks!
yao_licr is offline   Reply With Quote
Old 03-15-2015, 08:20 AM   #7
dschika
Member
 
Location: Zurich

Join Date: Mar 2010
Posts: 56
Default

Correct, you're welcome!
dschika is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 05:48 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO