Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def structure_from_file(path):
hasMore = True
with open(path) as infile:
name = infile.readline().strip()
res = int(infile.readline().strip())
res = int(float(infile.readline().strip()))
minPos = int(infile.readline().strip())
chrom = ChromParameters(minPos, None, res, name)
structure = Structure([], [], chrom, 0)
Expand Down Expand Up @@ -452,4 +452,4 @@ def size_from_bed(path):
with open(path) as in_file:
for i, line in enumerate(in_file):
pass
return i
return i
67 changes: 36 additions & 31 deletions minimds.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,40 +92,45 @@ def partitionedMDS(path, args):
infer_structure(low_contactMat, lowstructure, alpha, num_threads, weight)
print("Low-resolution MDS complete")

highSubstructures = pymp.shared.list(highstructure.structures)
lowSubstructures = pymp.shared.list(lowstructure.structures)
#highSubstructures = pymp.shared.list(highstructure.structures)
#lowSubstructures = pymp.shared.list(lowstructure.structures)
highSubstructures = highstructure.structures
lowSubstructures = lowstructure.structures

numSubstructures = len(highstructure.structures)
num_threads = min((num_threads, mp.cpu_count(), numSubstructures)) #don't exceed number of requested threads, available threads, or structures
with pymp.Parallel(num_threads) as p:
for substructurenum in p.range(numSubstructures):
highSubstructure = highSubstructures[substructurenum]
if len(highSubstructure.getPoints()) > 0: #skip empty
trueLow = lowSubstructures[substructurenum]

#perform MDS individually
structure_contactMat = dt.matFromBed(path, structure1=highSubstructure) #contact matrix for this structure only
infer_structure(structure_contactMat, highSubstructure, alpha2, num_threads, weight)

#approximate as low resolution
inferredLow = dt.highToLow(highSubstructure, res_ratio)

#rescale
scaling_factor = la.radius_of_gyration(trueLow)/la.radius_of_gyration(inferredLow)
for i, point in enumerate(inferredLow.points):
if point != 0:
x, y, z = point.pos
inferredLow.points[i].pos = (x*scaling_factor, y*scaling_factor, z*scaling_factor)

#recover the transformation for inferred from true low structure
r, t = la.getTransformation(inferredLow, trueLow)
t /= scaling_factor

#transform high structure
highSubstructure.transform(r, t)
highSubstructures[substructurenum] = highSubstructure

print("MDS performed on structure {} of {}".format(substructurenum + 1, numSubstructures))

#with pymp.Parallel(num_threads) as p:
# for substructurenum in p.range(numSubstructures):
#TODO: fix parallelization
for substructurenum in range(numSubstructures):
highSubstructure = highSubstructures[substructurenum]
if len(highSubstructure.getPoints()) > 0: #skip empty
trueLow = lowSubstructures[substructurenum]

#perform MDS individually
structure_contactMat = dt.matFromBed(path, structure1=highSubstructure) #contact matrix for this structure only
infer_structure(structure_contactMat, highSubstructure, alpha2, num_threads, weight)

#approximate as low resolution
inferredLow = dt.highToLow(highSubstructure, res_ratio)

#rescale
scaling_factor = la.radius_of_gyration(trueLow)/la.radius_of_gyration(inferredLow)
for i, point in enumerate(inferredLow.points):
if point != 0:
x, y, z = point.pos
inferredLow.points[i].pos = (x*scaling_factor, y*scaling_factor, z*scaling_factor)

#recover the transformation for inferred from true low structure
r, t = la.getTransformation(inferredLow, trueLow)
t /= scaling_factor

#transform high structure
highSubstructure.transform(r, t)
highSubstructures[substructurenum] = highSubstructure

print("MDS performed on structure {} of {}".format(substructurenum + 1, numSubstructures))

highstructure.setstructures(highSubstructures)
highstructure.set_rel_indices()
Expand Down
2 changes: 1 addition & 1 deletion scripts/chrom_from_tar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ fi
OUT_DIR=$PREFIX/$RES_STRING"_resolution_intrachromosomal"/chr$CHROM
test ! -d $DATA_DIR/$OUT_DIR && (tar -C $DATA_DIR -xzf $TAR $OUT_DIR)

test ! -s $DATA_DIR/$PREFIX"_"$CHROM"_"$RES_KB$RES_STRING.bed && (python3 normalize.py $DATA_DIR/$PREFIX $RES $CHROM)
test ! -s $DATA_DIR/$PREFIX"_"$CHROM"_"$RES_KB$RES_STRING.bed && (python normalize.py $DATA_DIR/$PREFIX $RES $CHROM)