Previous changeset 19:2e9f7ea7ae93 (2018-10-08) Next changeset 21:9919024d7778 (2018-12-14) |
Commit message:
planemo upload for repository https://github.com/monikaheinzl/duplexanalysis_galaxy/tree/master/tools/hd commit e76960d95c059a78d880ed5ecd6202f54b091025 |
modified:
hd.py hd.xml |
removed:
test-data/Test_data2.tabular test-data/output_file2.pdf test-data/output_file2.tabular |
b |
diff -r 2e9f7ea7ae93 -r b084b6a8e3ac hd.py --- a/hd.py Mon Oct 08 05:56:04 2018 -0400 +++ b/hd.py Fri Dec 14 04:31:21 2018 -0500 |
[ |
b'@@ -13,8 +13,8 @@\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 hd.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 --minFS int --maxFS int --nr_above_bars True/False --output_tabular outptufile_name_tabular --output_pdf outputfile_name_pdf\n+# USAGE: python hd.py --inputFile filename --inputName1 filename --sample_size int/0 --sep "characterWhichSeparatesCSVFile" /\n+# --only_DCS True --FamilySize3 True --subset_tag True --nproc int --minFS int --maxFS int --nr_above_bars True/False --output_tabular outptufile_name_tabular\n \n import argparse\n import itertools\n@@ -174,7 +174,7 @@\n plt.xticks(numpy.arange(0, maximumX + 1, 1.0))\n # plt.ylim(0, maximumY * 1.2)\n \n- legend = "sample size= {:,} against {:,}".format(sum(ham_partial[4]), lenTags)\n+ legend = "sample size= {:,} against {:,}".format(len(numpy.concatenate(ham_partial)), lenTags)\n plt.text(0.14, -0.01, legend, size=12, transform=plt.gcf().transFigure)\n pdf.savefig(fig, bbox_inches="tight")\n plt.close("all")\n@@ -634,9 +634,9 @@\n parser.add_argument(\'--inputFile\',\n help=\'Tabular File with three columns: ab or ba, tag and family size.\')\n parser.add_argument(\'--inputName1\')\n- parser.add_argument(\'--inputFile2\', default=None,\n- help=\'Tabular File with three columns: ab or ba, tag and family size.\')\n- parser.add_argument(\'--inputName2\')\n+ # parser.add_argument(\'--inputFile2\', default=None,\n+ # help=\'Tabular File with three columns: ab or ba, tag and family size.\')\n+ # parser.add_argument(\'--inputName2\')\n parser.add_argument(\'--sample_size\', default=1000, type=int,\n help=\'Sample size of Hamming distance analysis.\')\n parser.add_argument(\'--subset_tag\', default=0, type=int,\n@@ -657,10 +657,10 @@\n help=\'Name of the tabular file.\')\n parser.add_argument(\'--output_pdf\', default="data.pdf", type=str,\n help=\'Name of the pdf file.\')\n- parser.add_argument(\'--output_pdf2\', default="data2.pdf", type=str,\n- help=\'Name of the pdf file.\')\n- parser.add_argument(\'--output_tabular2\', default="data2.tabular", type=str,\n- help=\'Name of the tabular file.\')\n+ # parser.add_argument(\'--output_pdf2\', default="data2.pdf", type=str,\n+ # help=\'Name of the pdf file.\')\n+ # parser.add_argument(\'--output_tabular2\', default="data2.tabular", type=str,\n+ # help=\'Name of the tabular file.\')\n \n return parser\n \n@@ -672,15 +672,15 @@\n file1 = args.inputFile\n name1 = args.inputName1\n \n- file2 = args.inputFile2\n- name2 = args.inputName2\n+ # file2 = args.inputFile2\n+ # name2 = args.inputName2\n \n index_size = args.sample_size\n title_savedFile_pdf = args.output_pdf\n- title_savedFile_pdf2 = args.output_pdf2\n+ # title_savedFile_pdf2 = args.output_pdf2\n \n title_savedFile_csv = args.output_tabular\n- title_savedFile_csv2 = args.output_tabular2\n+ # title_savedFile_csv2 = args.output_tabular2\n \n sep = "\\t"\n onlyDuplicates = args.only_DCS\n@@ -711,276 +711,284 @@\n plt.rcParams[\'patch.edgecolor\'] = "#000000"\n plt.rc(\'figure\', figsize=(11.69, 8.27)) # A4 format\n \n- if file2 != str(None):\n- files = [file1, file2]\n- name1 = name1.split(".tabular")[0]\n- name2 = name2.split(".tabular")[0]\n- names = [name1, name2]\n- pdf_files = [title_savedFile_pdf, title_savedFile_pdf2]\n- csv_files = [title_savedFile_csv, title_savedFile_csv2]\n- else:\n- files = [file1]\n- name1 = name1.split(".t'..b'nce separated by family size", sep)\n+ # FSD\n+ createFileFSD2(summary5, sumCol5, overallSum5, output_file,\n+ "Family size distribution separated by Hamming distance", sep,\n+ diff=False)\n \n- # HD within tags\n+ count = numpy.bincount(quant)\n+ # output_file.write("{}{}\\n".format(sep, name1))\n+ output_file.write("\\n")\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+ "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", sep)\n+ createFileHD(summary11, sumCol11, overallSum11, output_file,\n+ "Absolute delta Hamming distances within the tag", sep)\n+ createFileHD(summary13, sumCol13, overallSum13, output_file,\n+ "Chimera analysis: relative delta Hamming distances", sep)\n+\n+ if len(minHD_tags_zeros) != 0:\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- "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", sep)\n- createFileHD(summary11, sumCol11, overallSum11, output_file,\n- "Absolute delta Hamming distances within the tag", sep)\n- createFileHD(summary13, sumCol13, overallSum13, output_file,\n- "Chimera analysis: relative delta Hamming distances", sep)\n-\n- if len(minHD_tags_zeros) != 0:\n- output_file.write(\n- "Chimeras:\\nAll 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", sep)\n- output_file.write("\\n")\n+ "Chimeras:\\nAll 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", sep)\n+ output_file.write("\\n")\n \n \n if __name__ == \'__main__\':\n' |
b |
diff -r 2e9f7ea7ae93 -r b084b6a8e3ac hd.xml --- a/hd.xml Mon Oct 08 05:56:04 2018 -0400 +++ b/hd.xml Fri Dec 14 04:31:21 2018 -0500 |
[ |
@@ -1,20 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> -<tool id="hd" name="Duplex Sequencing Analysis: hd" version="1.0.0"> - <description>Hamming distance (HD) analysis of tags</description> +<tool id="hd" name="HD:" version="1.0.0"> + <description>hamming distance analysis of duplex tags</description> <requirements> <requirement type="package" version="2.7">python</requirement> <requirement type="package" version="1.4.0">matplotlib</requirement> </requirements> <command> - python2 '$__tool_directory__/hd.py' --inputFile '$inputFile' --inputName1 '$inputFile.name' --inputFile2 '$inputFile2' --inputName2 '$inputFile2.name' --sample_size $sampleSize --subset_tag $subsetTag --nproc $nproc $onlyDCS --minFS $minFS --maxFS $maxFS - $nr_above_bars --output_pdf $output_pdf --output_tabular $output_tabular - #if $inputFile2: - --output_pdf2 $output_pdf2 --output_tabular2 $output_tabular2 - #end if + python2 '$__tool_directory__/hd.py' --inputFile '$inputFile' --inputName1 '$inputFile.name' --sample_size $sampleSize --subset_tag $subsetTag --nproc $nproc $onlyDCS --minFS $minFS --maxFS $maxFS + $nr_above_bars --output_pdf $output_pdf --output_tabular $output_tabular </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, tag and the direction of the strand ('ab' or 'ba') for each family."/> + <param name="inputFile" type="data" format="tabular" label="Dataset 1: input tags" optional="false" help="Input in tabular format with the family size, tag 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 a 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 a 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."/> @@ -26,51 +22,65 @@ </inputs> <outputs> <data name="output_tabular" format="tabular"/> - <data name="output_tabular2" format="tabular"> - <filter>inputFile2</filter> - </data> <data name="output_pdf" format="pdf" /> - <data name="output_pdf2" format="pdf" > - <filter>inputFile2</filter> - </data> </outputs> <tests> <test> <param name="inputFile" value="Test_data.tabular"/> - <param name="inputFile2" value="Test_data2.tabular"/> <param name="sampleSize" value="0"/> <output name="output_pdf" file="output_file.pdf" lines_diff="6"/> <output name="output_tabular" file="output_file.tabular"/> - <output name="output_pdf2" file="output_file2.pdf" lines_diff="6"/> - <output name="output_tabular2" file="output_file2.tabular"/> </test> </tests> <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 (ab and ba) in the dataset (DCSs) or to filter the dataset after the tag's family size. +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 (ab and ba) 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. It is possible to upload two files which allows the performance of two analyses at the same time. +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 | - +-----+----------------------------+----+ + 1 AAAAAAAAAAAATGTTGGAATCTT ba + 10 AAAAAAAAAAAGGCGGTCCACCCC ab + 28 AAAAAAAAAAATGGTATGGACCGA ab + +**How to generate the input** + +The first step of the `Du Novo Analysis Pipeline <https://doi.org/10.1186/s13059-016-1039-4>`_ is the **Make Families** tool that produces output in this form:: + + 1 2 3 4 + ------------------------------------------------------ + AAAAAAAAAAAAAAATAGCTCGAT ba read1 CGCTACGTGACTGGGTCATG + AAAAAAAAAAAAAAATAGCTCGAT ba read2 CGCTACGTGACTGGGTCATG + AAAAAAAAAAAAAAATAGCTCGAT ba read3 CGCTACGTGACTGGGTCATG + + we only need columns 1 and 2. These two columns can be extracted from this dataset using **Cut** tool:: + + 1 2 + --------------------------- + AAAAAAAAAAAAAAATAGCTCGAT ba + AAAAAAAAAAAAAAATAGCTCGAT ba + AAAAAAAAAAAAAAATAGCTCGAT ba + + now one needs to count the number of unique occurencies of each tag. This is done using **Unique lines** tool, which would add an additional column containg counts (column 1):: + + + 1 2 3 + ----------------------------- + 3 AAAAAAAAAAAAAAATAGCTCGAT ba + + these data can now be used in this tool. **Output** - The output is one PDF file with the plots of the Hamming distance and a tabular file with the data of the plot for each dataset. +The output is one PDF file with the plots of the Hamming distance and a tabular file with the data of the plot for each dataset. **About Author** |
b |
diff -r 2e9f7ea7ae93 -r b084b6a8e3ac test-data/Test_data2.tabular --- a/test-data/Test_data2.tabular Mon Oct 08 05:56:04 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,20 +0,0 @@ -1 AAAAAAAACCGCCCAACTGCCGGT ab -5 AAAAAAAACCTCTCAACCCCAAAT ba -7 AAAAAAAACCTCTTGCGATGTTGT ab -1 AAAAAAAACCTCTTGCGCTGTTGT ab -1 AAAAAAAACCTCTTGTGATGTTGT ab -12 AAAAAAAACCTGAGCAATGGTTCC ab -3 AAAAAAAACCTTGACCCTCACATG ba -6 AAAAAAAACCTTGCACTCGTCCTA ba -9 AAAAAAAACGAAATAAAAAAACCT ba -1 AAAAAAAACGACCGGCCTTAGACA ba -4 AAAAAAAACGCCACCACCCCCTTT ab -12 AAAAAAAACGCCACGGGCACTATT ba -13 AAAAAAAACGTATCAGTAGATCCT ab -1 AAAAAAAACTAGTAGGATTTCATG ba -3 AAAAAAAACTATAGAAAATCCATT ba -1 AAAAAAAACTATTCTATTTCCGAT ba -13 AAAAAAAACTGATCTGCTTGGCGG ba -8 AAAAAAAACTTGCGAATAGCATCG ba -4 AAAAAAAACTTGTTATCAAAACGT ab -1 AAAAAAAAGAAAAGTTCAACACGC ba \ No newline at end of file |
b |
diff -r 2e9f7ea7ae93 -r b084b6a8e3ac test-data/output_file2.pdf |
b |
Binary file test-data/output_file2.pdf has changed |
b |
diff -r 2e9f7ea7ae93 -r b084b6a8e3ac test-data/output_file2.tabular --- a/test-data/output_file2.tabular Mon Oct 08 05:56:04 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
b |
@@ -1,97 +0,0 @@ -Test_data2 -number of tags per file 20 (from 20) against 20 - -Hamming distance separated by family size - FS=1 FS=2 FS=3 FS=4 FS=5-10 FS>10 sum -HD=1 2 0 0 0 1 0 3 -HD=6 0 0 0 1 0 1 2 -HD=7 2 0 1 1 2 1 7 -HD=8 1 0 1 0 2 1 5 -HD=9 1 0 0 0 0 1 2 -HD=10 1 0 0 0 0 0 1 -sum 7 0 2 2 5 4 20 - -Family size distribution separated by Hamming distance - HD=1 HD=2 HD=3 HD=4 HD=5-8 HD>8 sum -FS=1 2 0 0 0 3 2 7 -FS=3 0 0 0 0 2 0 2 -FS=4 0 0 0 0 2 0 2 -FS=5 0 0 0 0 1 0 1 -FS=6 0 0 0 0 1 0 1 -FS=7 1 0 0 0 0 0 1 -FS=8 0 0 0 0 1 0 1 -FS=9 0 0 0 0 1 0 1 -FS=12 0 0 0 0 2 0 2 -FS=13 0 0 0 0 1 1 2 -sum 3 0 0 0 14 3 20 - - -max. family size: 13 -absolute frequency: 2 -relative frequency: 0.1 - -The hamming distances were calculated by comparing each half of all tags against the tag(s) with the minimum Hamming distance per half. -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. -actual number of tags with min HD = 79 (sample size by user = 20) -length of one part of the tag = 12 - -Hamming distance of each half in the tag - HD a HD b' HD b HD a' HD a+b sum -HD=0 20 0 0 5 0 25 -HD=1 22 4 4 3 8 41 -HD=2 9 2 0 9 2 22 -HD=3 0 0 0 10 0 10 -HD=4 0 0 2 1 0 3 -HD=5 0 0 5 0 0 5 -HD=6 0 5 7 0 3 15 -HD=7 0 7 10 0 10 27 -HD=8 0 6 0 0 10 16 -HD=9 0 7 0 0 17 24 -HD=10 0 11 0 0 13 24 -HD=11 0 8 0 0 7 15 -HD=12 0 1 0 0 5 6 -HD=13 0 0 0 0 4 4 -sum 51 51 28 28 79 237 - -Absolute delta Hamming distances within the tag - FS=1 FS=2 FS=3 FS=4 FS=5-10 FS>10 sum -diff=1 5 0 0 1 5 0 11 -diff=2 4 0 0 0 0 0 4 -diff=3 1 0 2 1 1 0 5 -diff=4 1 0 1 0 2 1 5 -diff=5 2 0 0 0 4 6 12 -diff=6 1 0 0 1 1 7 10 -diff=7 2 0 1 0 0 0 3 -diff=8 0 0 1 0 1 3 5 -diff=9 6 0 0 1 3 4 14 -diff=10 4 0 0 0 3 2 9 -diff=11 0 0 0 0 0 1 1 -sum 26 0 5 4 20 24 79 - -Chimera analysis: relative delta Hamming distances - FS=1 FS=2 FS=3 FS=4 FS=5-10 FS>10 sum -diff=0.1 1 0 0 1 1 0 3 -diff=0.3 3 0 2 0 0 0 5 -diff=0.4 1 0 0 1 3 0 5 -diff=0.5 0 0 1 0 0 1 2 -diff=0.6 1 0 0 0 3 7 11 -diff=0.7 1 0 0 0 1 5 7 -diff=0.8 10 0 0 0 2 9 21 -diff=1.0 9 0 2 2 10 2 25 -sum 26 0 5 4 20 24 79 - -Chimeras: -All tags were filtered: only those tags where at least one half is identical with the half of the min. tag are kept. -So the hamming distance of the non-identical half is compared. -Hamming distances of non-zero half - FS=1 FS=2 FS=3 FS=4 FS=5-10 FS>10 sum -HD=1 4 0 0 0 4 0 8 -HD=2 2 0 0 0 0 0 2 -HD=6 0 0 0 1 0 2 3 -HD=7 1 0 1 0 0 0 2 -HD=8 0 0 1 0 1 0 2 -HD=9 1 0 0 1 2 0 4 -HD=10 1 0 0 0 3 0 4 -sum 9 0 2 2 10 2 25 - - |