Created
March 17, 2011 14:27
-
-
Save arq5x/874410 to your computer and use it in GitHub Desktop.
Grab random subset of FASTQ pairs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Staring FASTQ files | |
export FQ1=1.fq | |
export FQ2=2.fq | |
# The names of the random subsets | |
export FQ1SUBSET=1.rand.fq | |
export FQ2SUBSET=2.rand.fq | |
# How many random pairs do we want? | |
export N=100 | |
# (1) Use paste to merge the two into a single line | |
# (2) Use awk to "linearize" the two mates into a single record. | |
# Add a random number to the front of each line | |
# (3) Sort by the random number | |
# (4) Using head, grab the first N (randomly chosen, thanks to the awk above) records | |
# (5) Use awk to convert back to 2 separate FASTQ files. | |
paste $FQ1 $FQ2 | \ | |
awk 'BEGIN{srand()}; {OFS="\t"; \ | |
getline seqs; getline sep; getline quals; \ | |
print rand(),$0,seqs,sep,quals}' | \ | |
sort -k1,1 | \ | |
head -n $N | \ | |
awk '{OFS="\n"; \ | |
print $2,$4,$6,$8 >> ENVIRON["FQ1SUBSET"]; \ | |
print $3,$5,$7,$9 >> ENVIRON["FQ2SUBSET"]}' |
Ha! Good point. It's rote from experience in my "early days".
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why do you use export?
just do