From 4f1a6fe60fcd5d73e1dae8ae6e71c114f3860ffc Mon Sep 17 00:00:00 2001 From: Guruprasad Anada Date: Tue, 5 May 2009 22:44:30 -0400 Subject: [PATCH] Added SOLiD tool section with QC tools. --- tool_conf.xml.sample | 4 + tools/solid_tools/solid_qual_boxplot.xml | 36 ++++++ tools/solid_tools/solid_qual_stats.py | 140 +++++++++++++++++++++++ tools/solid_tools/solid_qual_stats.xml | 65 +++++++++++ 4 files changed, 245 insertions(+) create mode 100644 tools/solid_tools/solid_qual_boxplot.xml create mode 100644 tools/solid_tools/solid_qual_stats.py create mode 100644 tools/solid_tools/solid_qual_stats.xml diff --git a/tool_conf.xml.sample b/tool_conf.xml.sample index 6aef7521ab1..e9772b19593 100644 --- a/tool_conf.xml.sample +++ b/tool_conf.xml.sample @@ -281,6 +281,10 @@ --> +
+ + +
diff --git a/tools/solid_tools/solid_qual_boxplot.xml b/tools/solid_tools/solid_qual_boxplot.xml new file mode 100644 index 00000000000..b72e4890241 --- /dev/null +++ b/tools/solid_tools/solid_qual_boxplot.xml @@ -0,0 +1,36 @@ + + for SOLiD data + + qualsolid_boxplot_graph.sh -t '$input.name' -i $input -o $output + + + + + + + + + + +**What it does** + +Creates a boxplot graph for the quality scores in the library. + +.. class:: infomark + +**TIP:** Use the **Quality Statistics for SOLiD data** tool to generate the report file needed for this tool. + +----- + +**Output Example** + +* Black horizontal lines are medians +* Rectangular red boxes show the Inter-quartile Range (IQR) (top value is Q3, bottom value is Q1) +* Whiskers show outlier at max. 1.5*IQR + + +.. image:: ../static/images/solid_qual.png + + + + diff --git a/tools/solid_tools/solid_qual_stats.py b/tools/solid_tools/solid_qual_stats.py new file mode 100644 index 00000000000..8ec8e932f74 --- /dev/null +++ b/tools/solid_tools/solid_qual_stats.py @@ -0,0 +1,140 @@ +#! /usr/bin/python +#Guruprasad Ananda + +import sys, os, zipfile, tempfile + +QUAL_UPPER_BOUND = 41 +QUAL_LOWER_BOUND = 1 + +def stop_err( msg ): + sys.stderr.write( "%s\n" % msg ) + sys.exit() + +def unzip( filename ): + zip_file = zipfile.ZipFile( filename, 'r' ) + tmpfilename = tempfile.NamedTemporaryFile().name + for name in zip_file.namelist(): + file( tmpfilename, 'a' ).write( zip_file.read( name ) ) + zip_file.close() + return tmpfilename + +def __main__(): + + infile_score_name = sys.argv[1].strip() + fout = open(sys.argv[2].strip(),'r+w') + + infile_is_zipped = False + if zipfile.is_zipfile( infile_score_name ): + infile_is_zipped = True + infile_name = unzip( infile_score_name ) + else: + infile_name = infile_score_name + + readlen = None + j = 0 + for line in file( infile_name ): + line = line.strip() + if not(line) or line.startswith("#") or line.startswith(">"): + continue + elems = line.split() + try: + for item in elems: + assert int(item) + if not(readlen): + readlen = len(elems) + if len(elems) != readlen: + print "Note: Reads in the input dataset are of variable lengths." + j += 1 + except: + invalid_lines += 1 + if j > 10: + break + + invalid_lines = 0 + position_dict = {} + print >>fout, "column\tcount\tmin\tmax\tsum\tmean\tQ1\tmed\tQ3\tIQR\tlW\trW" + for k,line in enumerate(file( infile_name )): + line = line.strip() + if not(line) or line.startswith("#") or line.startswith(">"): + continue + elems = line.split() + if position_dict == {}: + for pos in range(readlen): + position_dict[pos] = [0]*QUAL_UPPER_BOUND + if len(elems) != readlen: + invalid_lines += 1 + continue + for ind,item in enumerate(elems): + try: + item = int(item) + position_dict[ind][item]+=1 + except: + pass + + invalid_positions = 0 + for pos in position_dict: + carr = position_dict[pos] #count array for position pos + total = sum(carr) #number of bases found in this column. + med_elem = int(round(total/2.0)) + lowest = None #Lowest quality score value found in this column. + highest = None #Highest quality score value found in this column. + median = None #Median quality score value found in this column. + qsum = 0.0 #Sum of quality score values for this column. + q1 = None #1st quartile quality score. + q3 = None #3rd quartile quality score. + q1_elem = int(round((total+1)/4.0)) + q3_elem = int(round((total+1)*3/4.0)) + + try: + for ind,cnt in enumerate(carr): + qsum += ind*cnt + + if cnt!=0: + highest = ind + + if lowest==None and cnt!=0: #first non-zero count + lowest = ind + + if q1==None: + if sum(carr[:ind+1]) >= q1_elem: + q1 = ind + + if median==None: + if sum(carr[:ind+1]) < med_elem: + continue + median = ind + if total%2 == 0: #even number of elements + median2 = median + if sum(carr[:ind+1]) < med_elem+1: + for ind2,elem in enumerate(carr[ind+1:]): + if elem != 0: + median2 = ind+ind2+1 + break + median = (median + median2)/2.0 + + + if q3==None: + if sum(carr[:ind+1]) >= q3_elem: + q3 = ind + + + mean = qsum/total #Mean quality score value for this column. + iqr = q3-q1 + left_whisker = max(q1 - 1.5*iqr,lowest) + right_whisker = min(q3 + 1.5*iqr,highest) + + print >>fout,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" %(pos+1,total,lowest,highest,qsum,mean,q1,median,q3,iqr,left_whisker,right_whisker) + except: + invalid_positions += 1 + nullvals = ['NA']*11 + print >>fout,"%s\t%s" %(pos+1,'\t'.join(nullvals)) + + if invalid_lines: + print "Skipped %d reads as invalid." %invalid_lines + if invalid_positions: + print "Skipped stats computation for %d read postions." %invalid_positions + +if __name__=="__main__": + __main__() + + diff --git a/tools/solid_tools/solid_qual_stats.xml b/tools/solid_tools/solid_qual_stats.xml new file mode 100644 index 00000000000..50d952055a1 --- /dev/null +++ b/tools/solid_tools/solid_qual_stats.xml @@ -0,0 +1,65 @@ + + for SOLiD data + solid_qual_stats.py $input $output1 + + + + + + + + + + + + + + + + +**What it does** + +Creates quality statistics report for the given SOLiD quality score file. + +.. class:: infomark + +**TIP:** This statistics report can be used as input for **Quality Boxplot for SOLiD data** tool. + +----- + +**The output file will contain the following fields:** + +* column = column number (position on the read) +* count = number of bases found in this column. +* min = Lowest quality score value found in this column. +* max = Highest quality score value found in this column. +* sum = Sum of quality score values for this column. +* mean = Mean quality score value for this column. +* Q1 = 1st quartile quality score. +* med = Median quality score. +* Q3 = 3rd quartile quality score. +* IQR = Inter-Quartile range (Q3-Q1). +* lW = 'Left-Whisker' value (for boxplotting). +* rW = 'Right-Whisker' value (for boxplotting). + + + + + +**Output Example**:: + + column count min max sum mean Q1 med Q3 IQR lW rW + 1 6362991 2 32 250734117 20.41 5 9 28 23 2 31 + 2 6362991 2 32 250531036 21.37 10 26 30 20 5 31 + 3 6362991 2 34 248722469 19.09 10 26 30 20 5 31 + 4 6362991 2 34 247654797 18.92 10 26 30 20 5 31 + . + . + 32 6362991 2 31 143436943 16.54 3 10 25 22 2 31 + 33 6362991 2 32 114269843 16.96 3 10 25 22 2 31 + 34 6362991 2 29 140638447 12.10 3 10 25 22 2 29 + 35 6362991 2 29 138910532 11.83 3 10 25 22 2 29 + + + +