Skip to content

Grep error message crashes the script

This function also has a grep related error:


readBaseQualDist = function(statsFile){
    # statsFile="./fastqc/mouse_big_cyst_rep2_fastqc/fastqc_data.txt"
    # statsFile="./fastqc/mouse_liver_polar_stage3_rep2_fastqc/fastqc_data.txt"
    # grep -A30 -F '>>Per base sequence quality' /Volumes/projects/bioinfo/holger/projects/helin/mouse/fastqc/mouse_big_cyst_rep1_fastqc/fastqc_data.txt | grep -B100 -F '>>END_M' | head -n-1 | tail -n+2 | tr '#' ' '
#    echo("reading", statsFile)

    baseStats = read.delim(pipe(
        #http://stackoverflow.com/questions/1946363/how-do-i-display-data-from-the-beginning-of-a-file-until-the-first-occurence-of/1947950#1947950
        paste(get_zip_pipe(statsFile, "fastqc_data.txt"), " | grep -A200 -F '>>Per base sequence quality' |  perl -pe 'last if />>END_MODULE/' | head -n-2 | tail -n+2 | tr '#' ' '")
        )) %>% mutate(
            run=trim_ext(basename(statsFile), ".zip")
        )

    baseStats %>% mutate(base_order=1:n())
}
grep: write error: Broken pipe

In this line. Here the issue has detailed elsewhere:

grep is complaining because it has more output than 10 lines, and head is cutting it off before it finishes I suggest hiding grep's stderr output (this is where the broken pipe error is printed).

I will try this.