Mercurial > repos > mvdbeek > size_distribution
changeset 4:f1eeaf42144b draft default tip
planemo upload for repository https://github.com/bardin-lab/smallRNA_tools commit c8e0a703fcdff580ba0a0c5806a37c088c03ab7b-dirty
author | mvdbeek |
---|---|
date | Mon, 20 Aug 2018 14:46:57 -0400 |
parents | 21b5a9170b90 |
children | |
files | size_distributions.py |
diffstat | 1 files changed, 5 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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)