Next changeset 1:6ed6dca9488f (2018-05-12) |
Commit message:
planemo upload for repository https://github.com/monikaheinzl/galaxyProject/tree/master/tools/fsd_beforevsafter commit 6055f8c5c052f528ff85fb5e0d43b4500830637a |
added:
fsd_beforevsafter.py fsd_beforevsafter.xml |
b |
diff -r 000000000000 -r 6716b1cddf3e fsd_beforevsafter.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fsd_beforevsafter.py Thu May 10 07:29:24 2018 -0400 |
[ |
b'@@ -0,0 +1,318 @@\n+#!/usr/bin/env python\n+\n+# Family size distribution of DCS from various steps of the Galaxy pipeline\n+#\n+# Author: Monika Heinzl, Johannes-Kepler University Linz (Austria)\n+# Contact: monika.heinzl@edumail.at\n+#\n+# Takes a TXT file with tags of reads that were aligned to certain regions of the reference genome (optional),\n+# a TABULAR file with tags before the alignment to the SSCS, a FASTA file with reads that were part of the DCS and\n+# a FASTA file with tags after trimming as input (optional).\n+# The program produces a plot which shows the distribution of family sizes of the DCS from the input files and\n+# a CSV file with the data of the plot.\n+\n+# USAGE: python FSD before vs after_no_refF1.3_FINAL.py --inputFile_SSCS filenameSSCS --makeDCS filenameMakeDCS --afterTrimming filenameAfterTrimming -- alignedTags filenameTagsRefGenome \n+# --sep "characterWhichSeparatesCSVFile" --output_csv outptufile_name_csv --output_pdf outptufile_name_pdf\n+\n+\n+import numpy\n+import matplotlib.pyplot as plt\n+from collections import Counter\n+from Bio import SeqIO\n+import argparse\n+import sys\n+import os\n+from matplotlib.backends.backend_pdf import PdfPages\n+\n+def readFileReferenceFree(file, delim):\n+ with open(file, \'r\') as dest_f:\n+ data_array = numpy.genfromtxt(dest_f, skip_header=0, delimiter=delim, comments=\'#\', dtype=\'string\')\n+ return(data_array)\n+\n+def readFasta(file):\n+ tag_consensus = []\n+ fs_consensus = []\n+ with open(file, "r") as consFile:\n+ for record in SeqIO.parse(consFile, "fasta"):\n+ tag_consensus.append(record.id)\n+ line = record.description\n+ a, b = line.split(" ")\n+ fs1, fs2 = b.split("-")\n+ fs_consensus.extend([fs1,fs2])\n+ fs_consensus = numpy.array(fs_consensus).astype(int)\n+ return(tag_consensus, fs_consensus)\n+\n+def make_argparser():\n+ parser = argparse.ArgumentParser(description=\'Analysis of read loss in duplex sequencing data\')\n+ parser.add_argument(\'--inputFile_SSCS\',\n+ help=\'Tabular File with three columns: ab or ba, tag and family size.\')\n+ parser.add_argument(\'--makeDCS\',\n+ help=\'FASTA File with information about tag and family size in the header.\')\n+ parser.add_argument(\'--afterTrimming\',default=None,\n+ help=\'FASTA File with information about tag and family size in the header.\')\n+ parser.add_argument(\'--alignedTags\',default=None,\n+ help=\' TXT file with tags aligned to the reference genome and family size.\')\n+ parser.add_argument(\'--output_csv\', default="data.csv", type=str,\n+ help=\'Name of the pdf and csv file.\')\n+ parser.add_argument(\'--output_pdf\', default="data.pdf", type=str,\n+ help=\'Name of the pdf and csv file.\')\n+ parser.add_argument(\'--sep\', default=",",\n+ help=\'Separator in the csv file.\')\n+ return parser\n+\n+def compare_read_families_read_loss(argv):\n+ parser = make_argparser()\n+ args = parser.parse_args(argv[1:])\n+\n+ SSCS_file = args.inputFile_SSCS\n+ makeConsensus = args.makeDCS\n+ afterTrimming = args.afterTrimming\n+ ref_genome = args.alignedTags\n+ title_file = args.output_csv\n+ title_file2 = args.output_pdf\n+ sep = args.sep\n+\n+ if type(sep) is not str or len(sep)>1:\n+ print("Error: --sep must be a single character.")\n+ exit(4)\n+\n+ with open(title_file, "w") as output_file, PdfPages(title_file2) as pdf:\n+ ### PLOT ###\n+ plt.rc(\'figure\', figsize=(11.69, 8.27)) # A4 format\n+ plt.rcParams[\'axes.facecolor\'] = "E0E0E0" # grey background color\n+ plt.rcParams[\'xtick.labelsize\'] = 12\n+ plt.rcParams[\'ytick.labelsize\'] = 12\n+ plt.rcParams[\'patch.edgecolor\'] = "black"\n+ fig = plt.figure()\n+ plt.subplots_adjust(bottom=0.3)\n+\n+ list1 = []\n+ colors = []\n+ labels = []\n+\n+### data with tags of SSCS\n+ '..b'make DCS\\n".format(sep, sep))\n+\n+ for fs, sscs, dcs in zip(counts[1][2:len(counts[1])], counts[0][0][2:len(counts[0][0])],\n+ counts[0][1][2:len(counts[0][1])]):\n+ if fs == 21:\n+ fs = ">20"\n+ else:\n+ fs = "={}".format(fs)\n+ output_file.write(\n+ "FS{}{}{}{}{}\\n".format(fs, sep, int(sscs), sep, int(dcs)))\n+ output_file.write(\n+ "sum{}{}{}{}\\n".format(sep, int(sum(counts[0][0])), sep, int(sum(counts[0][1]))))\n+\n+ elif afterTrimming == str(None) or ref_genome == str(None):\n+ if afterTrimming == str(None):\n+ output_file.write(\n+ "{}before alignment to SSCS{}make DCS{}after alignment to reference genome\\n".format(sep, sep, sep))\n+ elif ref_genome == str(None):\n+ output_file.write(\n+ "{}before alignment to SSCS{}make DCS{}after trimming\\n".format(sep, sep, sep))\n+\n+ for fs, sscs, dcs, reference in zip(counts[1][2:len(counts[1])], counts[0][0][2:len(counts[0][0])],\n+ counts[0][1][2:len(counts[0][1])],counts[0][2][2:len(counts[0][2])]):\n+ if fs == 21:\n+ fs = ">20"\n+ else:\n+ fs = "={}".format(fs)\n+ output_file.write(\n+ "FS{}{}{}{}{}{}{}\\n".format(fs, sep, int(sscs), sep, int(dcs), sep, int(reference)))\n+ output_file.write(\n+ "sum{}{}{}{}{}{}\\n".format(sep, int(sum(counts[0][0])), sep, int(sum(counts[0][1])), sep, int(sum(counts[0][2]))))\n+\n+ else:\n+ output_file.write(\n+ "{}before alignment to SSCS{}make DCS{}after trimming{}after alignment to reference genome\\n".format(\n+ sep, sep, sep, sep))\n+ for fs, sscs, dcs, trim, reference in zip(counts[1][2:len(counts[1])], counts[0][0][2:len(counts[0][0])],\n+ counts[0][1][2:len(counts[0][1])],\n+ counts[0][2][2:len(counts[0][2])],\n+ counts[0][3][2:len(counts[0][3])]):\n+ if fs == 21:\n+ fs = ">20"\n+ else:\n+ fs = "={}".format(fs)\n+ output_file.write(\n+ "FS{}{}{}{}{}{}{}{}{}\\n".format(fs, sep, int(sscs), sep, int(dcs), sep, int(trim), sep,\n+ int(reference)))\n+ output_file.write(\n+ "sum{}{}{}{}{}{}{}{}\\n".format(sep, int(sum(counts[0][0])), sep, int(sum(counts[0][1])), sep,\n+ int(sum(counts[0][2])), sep, int(sum(counts[0][3]))))\n+\n+ output_file.write("\\n\\nIn the plot, the family sizes of ab and ba strands and of both duplex tags were used.\\nWhereas the total numbers indicate only the single count of the formed duplex tags.\\n")\n+ output_file.write("total nr. of tags (unique, FS>=1){}{}\\n".format(sep, len(seq_unique_FS)))\n+ output_file.write("DCS (before alignment to SSCS, FS>=1){}{}\\n".format(sep, len(duplTags)))\n+ output_file.write("total nr. of tags (unique, FS>=3){}{}\\n".format(sep, len(seq_unique_FS3)))\n+ output_file.write("DCS (before alignment to SSCS, FS>=3){}{}\\n".format(sep, len(d2)))\n+ output_file.write("make DCS{}{}\\n".format(sep, len(tag_consensus)))\n+ if afterTrimming != str(None):\n+ output_file.write("after trimming{}{}\\n".format(sep, len(tag_trimming)))\n+ if ref_genome != str(None):\n+ output_file.write("after alignment to reference genome{}{}\\n".format(sep, length_DCS_ref))\n+\n+ print("Files successfully created!")\n+\n+if __name__ == \'__main__\':\n+ sys.exit(compare_read_families_read_loss(sys.argv))\n' |
b |
diff -r 000000000000 -r 6716b1cddf3e fsd_beforevsafter.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fsd_beforevsafter.xml Thu May 10 07:29:24 2018 -0400 |
[ |
@@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tool id="fsd_beforevsafter" name="Duplex Sequencing Analysis:" version="0.0.1"> + <requirements> + <!-- galaxy version 16.04 --> + <requirement type="package" version="2.7">python</requirement> + <requirement type="package" version="1.4">matplotlib</requirement> + <requirement type="package" version="1.70">biopython</requirement> + + </requirements> + <description>Family size distribution (FSD) of tags from various steps of the Du Novo pipeline</description> + <command> + python2 $__tool_directory__/fsd_beforevsafter.py --inputFile_SSCS "$file1" --makeDCS "$makeDCS" --afterTrimming "$afterTrimming" --alignedTags "$alignedTags" --sep $separator --output_csv $output_csv --output_pdf $output_pdf + </command> + <inputs> + <param name="file1" type="data" format="tabular" label="Dataset 1: input tags of whole dataset" optional="false" help="Input in tabular format with the family size, tags and the direction of the strand ('ab' or 'ba') for each family."/> + <param name="makeDCS" type="data" format="fasta" label="Dataset 2: tags after making DCSs" help="Input in fasta format with the tags of the reads, which were aligned to DCSs, and their family sizes of both strands (reverse and forward) in the header, as well as the read itself in the next line."/> + <param name="afterTrimming" type="data" format="fasta" optional="true" label="Dataset 3: tags after trimming" help="Input in fasta format with the tags of the reads, which were not filtered out after trimming, and their family sizes of both strands (reverse and forward) in the header, as well as the read itself in the next following line."/> + <param name="alignedTags" type="data" format="txt" optional="true" label="Dataset 4: input tags aligned to the reference genome" help="Input in txt format with the regions and the tags, which were aligned to the reference genome."/> + <param name="separator" type="text" label="Separator of the CSV file." help="can be a single character" value=","/> + </inputs> + <outputs> + <data name="output_pdf" format="pdf" /> + <data name="output_csv" format="csv"/> + </outputs> + <help> <![CDATA[ + +**What it does** + + This tool will create a distribution of family sizes of various datasets obtained from different steps of the Du Novo pipeline. + +**Input** + + **Dataset 1:** 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 | + +-----+----------------------------+----+ + + + + **Dataset 2:** And a fasta file with all tags and their family sizes of both strands (forward and reverse) in the header and the read itself in the next line is required. This input file can be obtained by Du Novo: make families. + + + **Dataset 3 (optional):** In addition, the fasta file with all tags, which were not filtered out after trimming, can be given. + For both input files, only one file from both tools are necessary (these tools give for both forward and reverse strands an output file), since both files have the same tags and family sizes, but different reads, which are not required in this tool. + + +-------------------------------------------+ + | >AAAAAAAAATAGATCATAGACTCT 7-10 | + | CTAGACTCACTGGCGTTACTGACTGCGAGACCCTCCACGTG | + +-------------------------------------------+ + | >AAAAAAAAGGCAGAAGATATACGC 11-3 | + | CNCNGGCCCCCCGCTCCGTGCACAGACGNNGCNACTGACAA | + +-------------------------------------------+ + + + + **Dataset 4 (optional):** Finally, a TXT file with the regions and all tags that were aligned to the reference genome can be given as input. This file can obtained from a different tool. + + +-----------+------------------------------+ + | 87_636 | AAATCAAAGTATGAATGAAGTTGCCT | + +-----------+------------------------------+ + | 87_636 | AAATTCATAGCATTAATTTCAACGGG | + +-----------+------------------------------+ + | 656_1143 | GGGGCAGCCATATTGGCAATTATCAT | + +-----------+------------------------------+ + +**Output** + + The output is a PDF file with the plot and a CSV with the data of the plot. + + +**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> |