Next changeset 1:7414792e1cb8 (2018-05-12) |
Commit message:
planemo upload for repository https://github.com/monikaheinzl/galaxyProject/tree/master/tools/hd commit 6055f8c5c052f528ff85fb5e0d43b4500830637a |
added:
hd.py hd.xml |
b |
diff -r 000000000000 -r 239c4448a163 hd.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hd.py Thu May 10 07:30:27 2018 -0400 |
[ |
b'@@ -0,0 +1,624 @@\n+#!/usr/bin/env python\n+\n+# Hamming distance analysis of SSCSs\n+#\n+# Author: Monika Heinzl, Johannes-Kepler University Linz (Austria)\n+# Contact: monika.heinzl@edumail.at\n+#\n+# Takes at least one TABULAR file with tags before the alignment to the SSCS and optionally a second TABULAR file as input.\n+# The program produces a plot which shows a histogram of Hamming distances separated after family sizes,\n+# a family size distribution separated after Hamming distances for all (sample_size=0) or a given sample of SSCSs or SSCSs, which form a DCS.\n+# In additon, the tool produces HD and FSD plots for the difference between the HDs of both parts of the tags and for the chimeric reads\n+# and finally a CSV file with the data of the plots.\n+# It is also possible to perform the HD analysis with shortened tags with given sizes as input.\n+# The tool can run on a certain number of processors, which can be defined by the user.\n+\n+# USAGE: python HDnew6_1Plot_FINAL.py --inputFile filename --inputName1 filename --inputFile2 filename2 --inputName2 filename2 --sample_size int/0 --sep "characterWhichSeparatesCSVFile" /\n+# --only_DCS True --FamilySize3 True --subset_tag True --nproc int --output_csv outptufile_name_csv --output_pdf outptufile_name_pdf\n+\n+import numpy\n+import itertools\n+import operator\n+import matplotlib.pyplot as plt\n+import os.path\n+import cPickle as pickle\n+from multiprocessing.pool import Pool\n+from functools import partial\n+from HDAnalysis_plots.plot_HDwithFSD import plotHDwithFSD\n+from HDAnalysis_plots.plot_FSDwithHD2 import plotFSDwithHD2\n+from HDAnalysis_plots.plot_HDwithinSeq_Sum2 import plotHDwithinSeq_Sum2\n+from HDAnalysis_plots.table_HD import createTableHD, createFileHD, createTableHDwithTags, createFileHDwithinTag\n+from HDAnalysis_plots.table_FSD import createTableFSD2, createFileFSD2\n+import argparse\n+import sys\n+import os\n+from matplotlib.backends.backend_pdf import PdfPages\n+\n+def hamming(array1, array2):\n+ res = 99 * numpy.ones(len(array1))\n+ i = 0\n+ array2 = numpy.unique(array2) # remove duplicate sequences to decrease running time\n+ for a in array1:\n+ dist = numpy.array([sum(itertools.imap(operator.ne, a, b)) for b in array2]) # fastest\n+ res[i] = numpy.amin(dist[dist > 0]) # pick min distance greater than zero\n+ #print(i)\n+ i += 1\n+ return res\n+\n+def hamming_difference(array1, array2, mate_b):\n+ array2 = numpy.unique(array2) # remove duplicate sequences to decrease running time\n+ array1_half = numpy.array([i[0:(len(i)) / 2] for i in array1]) # mate1 part1\n+ array1_half2 = numpy.array([i[len(i) / 2:len(i)] for i in array1]) # mate1 part 2\n+\n+ array2_half = numpy.array([i[0:(len(i)) / 2] for i in array2]) # mate2 part1\n+ array2_half2 = numpy.array([i[len(i) / 2:len(i)] for i in array2]) # mate2 part2\n+\n+ diff11 = []\n+ relativeDiffList = []\n+ ham1 = []\n+ ham2 = []\n+ min_valueList = []\n+ min_tagsList = []\n+ diff11_zeros = []\n+ min_tagsList_zeros = []\n+ i = 0 # counter, only used to see how many HDs of tags were already calculated\n+ if mate_b is False: # HD calculation for all a\'s\n+ half1_mate1 = array1_half\n+ half2_mate1 = array1_half2\n+ half1_mate2 = array2_half\n+ half2_mate2 = array2_half2\n+ elif mate_b is True: # HD calculation for all b\'s\n+ half1_mate1 = array1_half2\n+ half2_mate1 = array1_half\n+ half1_mate2 = array2_half2\n+ half2_mate2 = array2_half\n+\n+ for a, b, tag in zip(half1_mate1, half2_mate1, array1):\n+ ## exclude identical tag from array2, to prevent comparison to itself\n+ sameTag = numpy.where(array2 == tag)\n+ indexArray2 = numpy.arange(0, len(array2), 1)\n+ index_withoutSame = numpy.delete(indexArray2, sameTag) # delete identical tag from the data\n+\n+ # all tags without identical tag\n+ array2_half_withoutSame = half1_mate2[index_withoutSame]\n+ array2_half2_withoutSame = half'..b'nd tags where at least one half has HD=0\n+ summary15, sumCol15 = createTableHD(listDifference1_zeros, "diff=")\n+ overallSum15 = sum(sumCol15)\n+ # absolute difference and tags where at least one half has HD=0\n+ summary23, sumCol23 = createTableFSD2(familySizeList1_diff_zeros, diff=False)\n+ overallSum23 = sum(sumCol23)\n+\n+ output_file.write("{}\\n".format(f))\n+ output_file.write("number of tags per file{}{:,} (from {:,}) against {:,}\\n\\n".format(sep, len(\n+ numpy.concatenate(list1)), lenTags, lenTags))\n+\n+ ### HD ###\n+ createFileHD(summary, sumCol, overallSum, output_file,\n+ "Hamming distance with separation after family size: file1", sep)\n+ ### FSD ###\n+ createFileFSD2(summary5, sumCol5, overallSum5, output_file,\n+ "Family size distribution with separation after hamming distances: file1", sep,\n+ diff=False)\n+\n+ count = numpy.bincount(quant)\n+ output_file.write("{}{}\\n".format(sep, f))\n+ output_file.write("max. family size:{}{}\\n".format(sep, max(quant)))\n+ output_file.write("absolute frequency:{}{}\\n".format(sep, count[len(count) - 1]))\n+ output_file.write(\n+ "relative frequency:{}{}\\n\\n".format(sep, float(count[len(count) - 1]) / sum(count)))\n+\n+ ### HD within tags ###\n+ output_file.write(\n+ "The hamming distances were calculated by comparing each half of all tags against the tag(s) with the minimum Hamming distance per half.\\n"\n+ "It is possible that one tag can have the minimum HD from multiple tags, so the sample size in this calculation differs from the sample size entered by the user.\\n")\n+ output_file.write(\n+ "file 1: actual number of tags with min HD = {:,} (sample size by user = {:,})\\n".format(\n+ len(numpy.concatenate(listDifference1)), len(numpy.concatenate(list1))))\n+ output_file.write("length of one part of the tag = {}\\n\\n".format(len(data_array[0, 1]) / 2))\n+\n+ createFileHDwithinTag(summary9, sumCol9, overallSum9, output_file,\n+ "Hamming distance of each half in the tag: file1", sep)\n+ createFileHD(summary11, sumCol11, overallSum11, output_file,\n+ "Absolute delta Hamming distances within the tag: file1", sep)\n+ createFileHD(summary13, sumCol13, overallSum13, output_file,\n+ "Relative delta Hamming distances within the tag: file1", sep)\n+\n+ createFileFSD2(summary19, sumCol19, overallSum19, output_file,\n+ "Family size distribution with separation after absolute delta Hamming distances: file1",\n+ sep)\n+ createFileFSD2(summary21, sumCol21, overallSum21, output_file,\n+ "Family size distribution with separation after relative delta Hamming distances: file1",\n+ sep, rel=True)\n+\n+ if len(minHD_tags_zeros) != 0:\n+ output_file.write(\n+ "All tags were filtered: only those tags where at least one half is identical with the half of the min. tag are kept.\\nSo the hamming distance of the non-identical half is compared.\\n")\n+ createFileHD(summary15, sumCol15, overallSum15, output_file,\n+ "Hamming distances of non-zero half: file1", sep)\n+ createFileFSD2(summary23, sumCol23, overallSum23, output_file,\n+ "Family size distribution with separation after Hamming distances of non-zero half: file1",\n+ sep, diff=False)\n+ output_file.write("\\n")\n+\n+\n+\n+if __name__ == \'__main__\':\n+ sys.exit(Hamming_Distance_Analysis(sys.argv))\n' |
b |
diff -r 000000000000 -r 239c4448a163 hd.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hd.xml Thu May 10 07:30:27 2018 -0400 |
[ |
@@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tool id="hd" name="Duplex Sequencing Analysis:" version="0.0.1"> + <requirements> + <requirement type="package" version="2.7">python</requirement> + <requirement type="package" version="1.4">matplotlib</requirement> + </requirements> + <description>Hamming distance (HD) analysis of tags</description> + <command> + python2 $__tool_directory__/hd.py --inputFile "$inputFile" --inputName1 "$inputFile.name" --inputFile2 "$inputFile2" --inputName2 "$inputFile2.name" --sample_size $sampleSize --sep $separator --subset_tag $subsetTag --nproc $nproc $onlyDCS --minFS $minFS --maxFS $maxFS --output_csv $output_csv --output_pdf $output_pdf + #if $inputFile2: + --output_pdf2 $output_pdf2 --output_csv2 $output_csv2 + #end if + </command> + <inputs> + <param name="inputFile" type="data" format="tabular" label="Dataset 1: input tags" optional="false"/> + <param name="inputFile2" type="data" format="tabular" label="Dataset 2: input tags" optional="true" help="Input in tabular format with the family size, tags and the direction of the strand ('ab' or 'ba') for each family."/> + <param name="sampleSize" type="integer" label="number of tags in the sample" value="1000" min="0" help="specifies the number of tags in one analysis. If sample size is 0, all tags of the dataset are compared against all tags."/> + <param name="minFS" type="integer" label="minimum family size of the tags" min="1" value="1" help="filters the tags after their family size: Families with smaller size are skipped. Default: min. family size = 1."/> + <param name="maxFS" type="integer" label="max family size of the tags" min="0" value="0" help="filters the tags after their family size: Families with larger size are skipped. If max. family size is 0, no upper bound is defined and the maximum family size in the analysis will be the maximum family size of the whole dataset. Default: max. family size = 0."/> + <param name="separator" type="text" label="Separator of the CSV file." help="can be a single character" value=","/> + <param name="onlyDCS" type="boolean" label="only DCS in the analysis?" truevalue="" falsevalue="--only_DCS" checked="False" help="Only tags, which have a partner tag in the dataset, are included in the analysis."/> + <param name="subsetTag" type="integer" label="shorten tag in the analysis?" value="0" help="An analysis with shorter tag length, which is specified by this parameter, is simulated. If this parameter is 0 (by default), the tag with its original length is used in the analysis."/> + <param name="nproc" type="integer" label="number of processors" value="8" help="Number of processor used for computing."/> + </inputs> + <outputs> + <data name="output_csv" format="csv"/> + <data name="output_csv2" format="csv"> + <filter>inputFile2</filter> + </data> + <data name="output_pdf" format="pdf" /> + <data name="output_pdf2" format="pdf" > + <filter>inputFile2</filter> + </data> + </outputs> + <help> <![CDATA[ +**What it does** + + This tool calculates the Hamming distance for the tags by comparing them to all tags in the dataset and finally searches for the minimum Hamming distance. + The Hamming distance is shown in a histogram separated by the family sizes or in a family size distribution separated by the Hamming distances. + This similarity measure was calculated for each tag to distinguish whether similar tags truly stem from different molecules or occured due to sequencing or PCR errros. + In addition the tags of chimeric reads can be identified by calculating the Hamming distance for each half of the tag. + This analysis can be performed on only a sample (by default: sample size=1000) or on the whole dataset (sample size=0). + It is also possible to select on only those tags, which have a partner tag in the dataset (DCSs) or to filter the dataset after the tag's family size. + +**Input** + + This tools expects a tabular file with the tags of all families, their sizes and information about forward (ab) and reverse (ba) strands. + + +-----+----------------------------+----+ + | 1 | AAAAAAAAAAAATGTTGGAATCTT | ba | + +-----+----------------------------+----+ + | 10 | AAAAAAAAAAAGGCGGTCCACCCC | ab | + +-----+----------------------------+----+ + | 28 | AAAAAAAAAAATGGTATGGACCGA | ab | + +-----+----------------------------+----+ + + +**Output** + + The output is one PDF file with the plots of the Hamming distance and a CSV with the data of the plot for each dataset. + + +**About Author** + + Author: Monika Heinzl + + Department: Institute of Bioinformatics, Johannes Kepler University Linz, Austria + + Contact: monika.heinzl@edumail.at + + ]]> + + </help> + <citations> + <citation type="bibtex"> + @misc{duplex, + author = {Heinzl, Monika}, + year = {2018}, + title = {Development of algorithms for the analysis of duplex sequencing data} + } + </citation> + </citations> +</tool> |