def test_pdd_rounding_down(self): points = [[0, 0, 2], [0, 0, 2.4]] x, y = ftuv.pair_distance_distribution(points, 0.3) nptest.assert_array_equal(x, np.array([0, 0.3])) nptest.assert_array_equal(y, np.array([0, 1])) x, y = ftuv.pair_distance_distribution(points, 0.06) nptest.assert_array_equal( x, np.array([0, 0.06, 0.12, 0.18, 0.24, 0.3, 0.36])) nptest.assert_array_equal(y, np.array([0, 0, 0, 0, 0, 0, 1]))
def test_pdd_rounding_down(self): points = [[0, 0, 2], [0, 0, 2.4]] x, y = ftuv.pair_distance_distribution(points, 0.3) nptest.assert_array_equal(x, np.array([0, 0.3])) nptest.assert_array_equal(y, np.array([0, 1])) x, y = ftuv.pair_distance_distribution(points, 0.06) nptest.assert_array_equal(x, np.array( [0, 0.06, 0.12, 0.18, 0.24, 0.3, 0.36])) nptest.assert_array_equal(y, np.array( [0, 0, 0, 0, 0, 0, 1]))
def test_pdd_smaller_step(self): points = [[0, 0, 4], [0, 0, -4], [3, 0, 0]] x, y = ftuv.pair_distance_distribution(points, 0.5) nptest.assert_array_equal(x, np.array( [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8])) nptest.assert_array_equal(y, np.array( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1]))
def get_allatom_pdd(filename, stepsize): chains = ftup.get_all_chains(filename)[0] atoms = [] for chain in chains: for res in chain: for atom in res: atoms.append(atom.coord) x, y = ftuv.pair_distance_distribution(atoms, stepsize) df = pd.DataFrame({"step": x, "count": y}) return df
def test_pdd_smaller_step(self): points = [[0, 0, 4], [0, 0, -4], [3, 0, 0]] x, y = ftuv.pair_distance_distribution(points, 0.5) nptest.assert_array_equal( x, np.array([ 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8 ])) nptest.assert_array_equal( y, np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1]))
def load(self, pattern): num_loaded = 0 num_selected = 0 if not isinstance(pattern, list): pattern = [pattern] fns = [] for pat in pattern: fns.extend(glob(pat)) if len(fns) > 1000: lev = logging.WARNING else: lev = logging.INFO log.log(lev, "Loading %s files", len(fns)) with _LoggingContext(logging.getLogger(), logging.CRITICAL): for fn in fns: num_selected += 1 if fn not in self.cgs: cgs = forgi.load_rna(fn) if len(cgs) != 1: raise ValueError( "Expected 1 RNA component in file {}, found {}:{}". format(fn, len(cgs)), [cg.name for cg in cgs]) cg, = cgs cg.infos["filename"] = fn self.cgs[fn] = cg num_loaded += 1 if fn not in self.pdds: points = [] try: pd_pdd = pd.read_csv(fn + ".pdd.csv") except: for i in range(1, cg.seq_length + 1): points.append( cg.get_virtual_residue( i, allow_single_stranded=True)) x, y = ftuv.pair_distance_distribution( points, stepsize=self.stepsize) df = pd.DataFrame({"step": x, "count": y}) df.to_csv(fn + ".pdd.csv") else: x = pd_pdd["step"] y = pd_pdd["count"] self.pdds[fn] = (x, y) scores = self.get_scores(pattern) if scores: minsc = scores[0] maxsc = scores[-1] else: minsc = None maxsc = None return num_selected, num_loaded, minsc, maxsc
def test_pdd(self): points = [[0, 0, 4], [0, 0, -4], [3, 0, 0]] x, y = ftuv.pair_distance_distribution(points) nptest.assert_array_equal(x, np.array([0, 1, 2, 3, 4, 5, 6, 7, 8])) nptest.assert_array_equal(y, np.array([0, 0, 0, 0, 0, 2, 0, 0, 1]))