Use vcf_predict.py strand convention for RC averaging
Browse files- modeling_mpac.py +13 -6
modeling_mpac.py
CHANGED
|
@@ -405,13 +405,20 @@ class MPACModel(
|
|
| 405 |
for start in range(0, len(sequences), batch_size):
|
| 406 |
chunk = sequences[start:start + batch_size]
|
| 407 |
batch = torch.stack([dna2tensor(s.upper()) for s in chunk]).to(device)
|
| 408 |
-
|
| 409 |
-
# construct, vector context included. Flipping the bare insert and
|
| 410 |
-
# then adding forward-orientation flanks is not a reverse complement.
|
| 411 |
-
prepped = self.add_flanks(batch)
|
| 412 |
-
preds = self(prepped)
|
| 413 |
if rc_average:
|
| 414 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
results.append(preds.cpu())
|
| 416 |
finally:
|
| 417 |
self.train(was_training)
|
|
|
|
| 405 |
for start in range(0, len(sequences), batch_size):
|
| 406 |
chunk = sequences[start:start + batch_size]
|
| 407 |
batch = torch.stack([dna2tensor(s.upper()) for s in chunk]).to(device)
|
| 408 |
+
preds = self(self.add_flanks(batch))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
if rc_average:
|
| 410 |
+
# The reverse strand is the reverse complement of the INSERT ONLY,
|
| 411 |
+
# re-flanked in the forward orientation -- not a flip of the
|
| 412 |
+
# assembled 600 bp tensor. This looks like a bug and is not: it
|
| 413 |
+
# matches `src/vcf_predict.py` in sjgosai/boda2, which produced the
|
| 414 |
+
# published MPAC predictions, and it models the real experiment
|
| 415 |
+
# (a fixed plasmid with the insert cloned backwards).
|
| 416 |
+
#
|
| 417 |
+
# Flipping the flanked tensor instead scores ~0.035 higher against
|
| 418 |
+
# Table S2, so the temptation to "fix" this is real. Don't: it would
|
| 419 |
+
# silently desynchronise this model from every published MPAC number.
|
| 420 |
+
rc = self.add_flanks(batch.flip(dims=[1, 2]))
|
| 421 |
+
preds = (preds + self(rc)).div(2.)
|
| 422 |
results.append(preds.cpu())
|
| 423 |
finally:
|
| 424 |
self.train(was_training)
|