|
a |
|
b/singlecellmultiomics/statistic/statistic.py |
|
|
1 |
#!/usr/bin/env python3 |
|
|
2 |
# -*- coding: utf-8 -*- |
|
|
3 |
|
|
|
4 |
import collections |
|
|
5 |
import pandas as pd |
|
|
6 |
import numpy as np |
|
|
7 |
import singlecellmultiomics.pyutils as pyutils |
|
|
8 |
|
|
|
9 |
|
|
|
10 |
class Statistic(object): |
|
|
11 |
|
|
|
12 |
""" |
|
|
13 |
Statistic object, initialised with arguments |
|
|
14 |
|
|
|
15 |
Parameters |
|
|
16 |
---------- |
|
|
17 |
args : argparse object |
|
|
18 |
|
|
|
19 |
""" |
|
|
20 |
|
|
|
21 |
def __init__(self, args): |
|
|
22 |
self.args = args |
|
|
23 |
|
|
|
24 |
def processRead(self, R1,R2=None): |
|
|
25 |
""" |
|
|
26 |
Update the statistic with information from READ |
|
|
27 |
|
|
|
28 |
Parameters |
|
|
29 |
---------- |
|
|
30 |
read : PySAM Aligned segment |
|
|
31 |
|
|
|
32 |
Returns |
|
|
33 |
---------- |
|
|
34 |
None |
|
|
35 |
""" |
|
|
36 |
pass |
|
|
37 |
|
|
|
38 |
def __repr__(self): |
|
|
39 |
return 'dummy' |
|
|
40 |
|
|
|
41 |
|
|
|
42 |
class StatisticHistogram(Statistic): |
|
|
43 |
def __init__(self, args): |
|
|
44 |
Statistic.__init__(self, args) |
|
|
45 |
self.histogram = collections.Counter() |
|
|
46 |
|
|
|
47 |
def __repr__(self): |
|
|
48 |
return f'Mean {pyutils.meanOfCounter(self.histogram)}, SD:{pyutils.varianceOfCounter(self.histogram)}' |
|
|
49 |
|
|
|
50 |
def __iter__(self): |
|
|
51 |
return iter(self.histogram.most_common()) |
|
|
52 |
|
|
|
53 |
def to_csv(self, path): |
|
|
54 |
pd.DataFrame({__class__.__name__: self.histogram}).to_csv(path) |