Skip to content

Commit

Permalink
Merge pull request #110 from scipion-em/jj_fix_extract_from_ts_order
Browse files Browse the repository at this point in the history
Jj fix extract from ts order
  • Loading branch information
JorMaister authored Mar 26, 2024
2 parents 9e927b5 + 9626dbb commit 507000f
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 264 deletions.
15 changes: 14 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
v3.3.1:
Users:
- Small fixes regarding the register of the tilt series acquisition attributes.
- Fixes the template matching output register reported by Ricardo Righetto (thanks!).
- Fix the template matching output register reported by Ricardo Righetto (thanks!).
- Fix the classic subtomo refine transformation matrices assignment when generating the output.
- Fix the particles order in the registered output of protocol extract particles from TS.
- Protocol 'extract particles from TS' is now semi-streamified.
- Protocol 'tilt series alignment and tomo reconstruction':
* Fix the sampling rate of the set of tilt series interpolated.
* Fix the generation of tomograms when not requested.
* The interpolated tilt series is now generated applying the transformation matrix in Scipion convention to the
non-interpolated tilt series.
* Input and output convert steps improved.
* Remove form parameter 'Step between tilts' as it can now be read from the acquisition.
* Add param to correct the XDrift.
* Some other changes in the protocol form.
- Protocol 'average subtomograms' adapted to work with EMAN 3D particles generated from 3D particles (the ones
resulting when using the protocol 'extract particles from TS')
Developers:
- Test for TS alignment & tomo reconstruction updated to the new TCL.
v3.3.0:
Expand Down
13 changes: 13 additions & 0 deletions emantomo/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ def getProjsFrom2dStack(self, shrink=1):
(shrink * img.attrs['EMAN.ptcl_source_coord'][:-1]).tolist())
return projsList

def get3dCoordsFrom3dStack(self, scaleFactor=1, invertZ=False):
"""Generate a list of elements in which each element is a list containing the following data:
[xCoord, yCoord, zCoord] read from the HDF stack header.
"""
coordsList = []
for particleId in range(len(self._imgObjList)):
img = self._imgObjList[str(particleId)]
coords = (scaleFactor * img.attrs['EMAN.ptcl_source_coord']).tolist()
if invertZ:
coords[-1] = -1 * coords[-1]
coordsList.append(coords)
return coordsList

def getSamplingRate(self):
"""Reads the sampling rate from the HDF header"""
return self._imgObjList['0'].attrs['EMAN.apix_x']
Expand Down
13 changes: 10 additions & 3 deletions emantomo/protocols/protocol_average_subtomos.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@
import glob
import os
import shutil
from os.path import join, basename
from os.path import join, basename, abspath

from pyworkflow import BETA

from pwem.protocols import EMProtocol
from pyworkflow.protocol import PointerParam, FloatParam, StringParam, BooleanParam, LEVEL_ADVANCED
from pyworkflow.utils import Message, makePath, removeBaseExt, replaceExt
from pyworkflow.utils import Message, makePath, removeBaseExt, replaceExt, createLink
from ..constants import SPT_00_DIR, INPUT_PTCLS_LST, THREED_01, SYMMETRY_HELP_MSG, SUBTOMOGRAMS_DIR

from ..convert import writeSetOfSubTomograms, refinement2Json
import emantomo

from tomo.protocols import ProtTomoBase
from tomo.objects import AverageSubTomogram
from ..objects import EmanParticle, EmanSetOfParticles


class OutputsAverageSubtomos(enum.Enum):
Expand Down Expand Up @@ -118,7 +119,13 @@ def _initialize(self):

def convertInputStep(self):
inSubtomos = self.inputSetOfSubTomogram.get()
writeSetOfSubTomograms(inSubtomos, self.hdfSubtomosDir)
if type(inSubtomos) is EmanSetOfParticles:
# If True, the 3D particles HDF stacks will already exist because they have been extracted with EMAN pppt
hdfStacks = inSubtomos.getUniqueValues(EmanParticle.STACK_3D_HDF)
[createLink(abspath(hdfStack), self._getExtraPath(SUBTOMOGRAMS_DIR, basename(hdfStack))) for
hdfStack in hdfStacks]
else:
writeSetOfSubTomograms(inSubtomos, self.hdfSubtomosDir)
refinement2Json(self, inSubtomos)

# Generate a virtual stack of particle represented by a .lst file, as expected by EMAN
Expand Down
8 changes: 5 additions & 3 deletions emantomo/protocols/protocol_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# *
# **************************************************************************
import glob
import logging
import re
from os.path import join, abspath, basename

Expand All @@ -44,6 +45,9 @@
from tomo.protocols import ProtTomoBase
from tomo.utils import getNonInterpolatedTsFromRelations


logger = logging.getLogger(__name__)

IN_TS = 'inputTS'
IN_COORDS = 'inputCoordinates'
IN_CTF = 'inputCTF'
Expand All @@ -70,9 +74,7 @@ def convertTsStep(self, mdObj):
# The converted TS must be unbinned, because EMAN will read the sampling rate from its header. This is why
# the TS associated to the CTF is the one considered first. Later, when generating the json, the TS alignment
# parameters are read from the introduced TS and the shifts are scaled to at the unbinned scale
# if mdObj.ctf:
# inTsFName = mdObj.ctf.getTiltSeries().getFirstItem().getFileName()
# else:
logger.info(f'Converting TS {mdObj.tsId} into HDF...')
inTsFName = mdObj.ts.getFirstItem().getFileName()
sRate = mdObj.ts.getSamplingRate()
self.convertOrLink(inTsFName, mdObj.tsId, TS_DIR, sRate)
Expand Down
Loading

0 comments on commit 507000f

Please sign in to comment.