# HG changeset patch # User mvdbeek # Date 1534790817 14400 # Node ID f1eeaf42144b80094173abab9e097c77e5f4dd8b # Parent 21b5a9170b9008e98e1f939057a1c8e6daeca899 planemo upload for repository https://github.com/bardin-lab/smallRNA_tools commit c8e0a703fcdff580ba0a0c5806a37c088c03ab7b-dirty diff -r 21b5a9170b90 -r f1eeaf42144b size_distributions.py --- a/size_distributions.py Mon Aug 20 14:27:49 2018 -0400 +++ b/size_distributions.py Mon Aug 20 14:46:57 2018 -0400 @@ -29,13 +29,14 @@ reference_counters[reference]['sense'][readlength] += 1 df = pd.Panel(reference_counters).to_frame() df.index.names = ['readlength', 'orientation'] - return df + return i, df -def to_long(df): +def to_long(df, total_count): df = df.reset_index() df = df.melt(id_vars=('readlength', 'orientation')) df.columns = ['readlength', 'orientation', 'reference', 'count'] + df['TPM'] = df['count'] / total_count * 10 ** 6 return df @@ -52,9 +53,9 @@ def size_dist(alignment_path, minimum_size=18, maximum_size=30, output="/dev/stdout", wide=False): """Calculate size distribution and orientation""" with pysam.AlignmentFile(alignment_path) as alignment_file: - df = global_size_distribution(alignment_file, minimum_size, maximum_size) + total_count, df = global_size_distribution(alignment_file, minimum_size, maximum_size) if not wide: - df = to_long(df) + df = to_long(df, total_count) write_table(df, output)