From 72452db028f03f319abfdf6ca2b1aeddd5832bef Mon Sep 17 00:00:00 2001 From: alisterburt Date: Tue, 16 Jan 2024 08:56:27 +0000 Subject: [PATCH] deploy: 8e1dc0583fe1eabce7f5a9b034eb5354caf3aefe --- examples/merging/index.html | 1 + examples/multi_block/index.html | 1 - examples/single_block/index.html | 1 + index.html | 1 + search/search_index.json | 2 +- sitemap.xml | 8 ++++---- sitemap.xml.gz | Bin 243 -> 243 bytes 7 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/merging/index.html b/examples/merging/index.html index 2d0ec80..bb2d5e4 100644 --- a/examples/merging/index.html +++ b/examples/merging/index.html @@ -464,6 +464,7 @@

merging data across tables

In pandas, this is implemented as DataFrame.merge().

import starfile
+
 star = starfile.read('particles.star')
 df = star['particles'].merge(star['optics'], on='rlnOpticsGroup')
 
diff --git a/examples/multi_block/index.html b/examples/multi_block/index.html index 22b15da..d7bc1fa 100644 --- a/examples/multi_block/index.html +++ b/examples/multi_block/index.html @@ -551,7 +551,6 @@

Writing

Writing a file containing multiple data blocks is similar, simply pass a dictionary of entries.

import starfile
 
-
 starfile.write(
     {'optics': optics_df, 'particles': particle_df}, 'new_file.star'
 )
diff --git a/examples/single_block/index.html b/examples/single_block/index.html
index 0b66cf6..e61bbf0 100644
--- a/examples/single_block/index.html
+++ b/examples/single_block/index.html
@@ -436,6 +436,7 @@ 

single data block example

Read the file

import starfile
+
 df = starfile.read('particles.star')
 

Interact with the data

diff --git a/index.html b/index.html index 9659a4a..6e58041 100644 --- a/index.html +++ b/index.html @@ -451,6 +451,7 @@

Quickstart

Read the file

import starfile
+
 df = starfile.read('particles.star')
 

Interact with the data

diff --git a/search/search_index.json b/search/search_index.json index 91a68b9..ec1978f 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Overview","text":"

starfile is a package for reading and writing STAR files in Python.

reading and writing a STAR file with a single data block

starfile can be used interactively to inspect/explore files or in scripts and larger software packages to provide basic STAR file I/O functions. Data is exposed as simple python dictionaries or pandas dataframes.

This package was designed principally for compatibility with files generated by RELION. For more information on working with pandas, please see the pandas docs.

"},{"location":"#quickstart","title":"Quickstart","text":"

For the following file particles.star with a single data block

data_particles\n\nloop_\n_rlnCoordinateX #1\n_rlnCoordinateY #2\n_rlnCoordinateZ #3\n_rlnAngleRot #4\n_rlnAngleTilt #5\n_rlnAnglePsi #6\n_rlnMicrographName #7\n91.798700   83.622600   203.341030  -51.740000  173.930000  32.971000   01_10.00Apx.mrc\n97.635800   80.437000   203.136160  141.500000  171.760000  -134.680000 01_10.00Apx.mrc\n92.415200   88.842700   210.663900  -78.750000  173.930000  87.263200   01_10.00Apx.mrc\n94.607830   93.135410   205.425960  -85.215000  167.170000  85.632200   01_10.00Apx.mrc\n86.187800   80.125400   204.558750  14.910000   163.260000  -16.030000  01_10.00Apx.mrc\n91.824240   76.738300   203.794280  39.740000   168.410000  -57.250000  01_10.00Apx.mrc\n98.253300   73.530100   203.856030  73.950000   166.380000  -84.640000  01_10.00Apx.mrc\n101.303500  80.290800   194.790400  -178.878000 166.090000  73.181000   01_10.00Apx.mrc\n

Read the file

import starfile\ndf = starfile.read('particles.star')\n

Interact with the data

df['rlnCoordinateX'] += 10\ndf.head()\n
   rlnCoordinateX  rlnCoordinateY  rlnCoordinateZ  rlnAngleRot  rlnAngleTilt  rlnAnglePsi rlnMicrographName\n0       101.79870        83.62260       203.34103      -51.740        173.93      32.9710   01_10.00Apx.mrc\n1       107.63580        80.43700       203.13616      141.500        171.76    -134.6800   01_10.00Apx.mrc\n2       102.41520        88.84270       210.66390      -78.750        173.93      87.2632   01_10.00Apx.mrc\n3       104.60783        93.13541       205.42596      -85.215        167.17      85.6322   01_10.00Apx.mrc\n4        96.18780        80.12540       204.55875       14.910        163.26     -16.0300   01_10.00Apx.mrc\n

Save the (modified) data to file

starfile.write(df, 'modified_particles.star')\n

For more advanced usage please check out the examples.

"},{"location":"#installation","title":"Installation","text":"
pip install starfile\n
"},{"location":"examples/merging/","title":"merging data across tables","text":"

In this example, we will use pandas to merge data from two blocks in a RELION particle STAR file particles.star.

In RELION (>=3.1) particle STAR files contain an optics table and a particles table. Data about optics common to many particles is stored in the optics table.

particles.star
data_optics\n\nloop_\n_rlnOpticsGroup #1\n_rlnOpticsGroupName #2\n_rlnSphericalAberration #3\n_rlnVoltage #4\n_rlnImagePixelSize #5\n_rlnImageSize #6\n_rlnImageDimensionality #7\n1   opticsGroup1    2.700000    300.000000  3.300000    160 3\n\ndata_particles\n\nloop_\n_rlnCoordinateX #1\n_rlnCoordinateY #2\n_rlnCoordinateZ #3\n_rlnAngleRot #4\n_rlnAngleTilt #5\n_rlnAnglePsi #6\n_rlnImageName #7\n_rlnCtfImage #8\n_rlnRandomSubset #9\n_rlnPixelSize #10\n_rlnMicrographName #11\n_rlnOpticsGroup #12\n_rlnGroupNumber #13\n_rlnOriginXAngst #14\n_rlnOriginYAngst #15\n_rlnOriginZAngst #16\n_rlnClassNumber #17\n_rlnNormCorrection #18\n_rlnLogLikeliContribution #19\n_rlnMaxValueProbDistribution #20\n_rlnNrOfSignificantSamples #21\n880.274000  895.057900  1107.245000 131.246000  106.820800  45.228430   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000000_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000000_ctf_3.30A.mrc 2   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    6   1.000000    4150981.000000  1.000000    1\n973.165500  958.641800  1115.101000 87.247110   109.236500  45.323810   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000001_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000001_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    4   1.000000    4150837.000000  1.000000    1\n955.949400  960.465100  629.459100  9.331370    99.309980   11.024810   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000002_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000002_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    3   1.000000    4150650.000000  1.000000    1\n1175.177000 1135.731000 882.605200  -147.261200 81.605380   77.325710   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000003_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000003_ctf_3.30A.mrc 2   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    1   1.000000    4151420.000000  1.000000    1\n1190.658000 1122.102000 1073.642000 40.404590   98.061770   42.563060   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000004_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000004_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    6   1.000000    4150168.000000  1.000000    1\n

The column rlnOpticsGroup is present in both tables.

Merging data from multiple dataframes is an example of a join in relational algebra. In pandas, this is implemented as DataFrame.merge().

import starfile\nstar = starfile.read('particles.star')\ndf = star['particles'].merge(star['optics'], on='rlnOpticsGroup')\n

The resulting dataframe contains columns with data from both the particles and optics dataframes.

df.head()\n
   rlnCoordinateX  rlnCoordinateY  rlnCoordinateZ  rlnAngleRot  rlnAngleTilt  ...  rlnSphericalAberration rlnVoltage rlnImagePixelSize  rlnImageSize  rlnImageDimensionality\n0        880.2740        895.0579       1107.2450    131.24600     106.82080  ...                     2.7      300.0               3.3           160                       3\n1        973.1655        958.6418       1115.1010     87.24711     109.23650  ...                     2.7      300.0               3.3           160                       3\n2        955.9494        960.4651        629.4591      9.33137      99.30998  ...                     2.7      300.0               3.3           160                       3\n3       1175.1770       1135.7310        882.6052   -147.26120      81.60538  ...                     2.7      300.0               3.3           160                       3\n4       1190.6580       1122.1020       1073.6420     40.40459      98.06177  ...                     2.7      300.0               3.3           160                       3\n\n[5 rows x 27 columns]\n

This table has the following properties - every column is a variable - every row is an observation - every cell contains a single value

Data in this form is sometimes referred to as tidy data. Tidy data is easier to manipulate.

"},{"location":"examples/multi_block/","title":"multiple data block example","text":"

In this example, we will use starfile to read and write files containing multiple data blocks.

particles.star
data_optics\n\nloop_\n_rlnOpticsGroup #1\n_rlnOpticsGroupName #2\n_rlnSphericalAberration #3\n_rlnVoltage #4\n_rlnImagePixelSize #5\n_rlnImageSize #6\n_rlnImageDimensionality #7\n1   opticsGroup1    2.700000    300.000000  3.300000    160 3\n\ndata_particles\n\nloop_\n_rlnCoordinateX #1\n_rlnCoordinateY #2\n_rlnCoordinateZ #3\n_rlnAngleRot #4\n_rlnAngleTilt #5\n_rlnAnglePsi #6\n_rlnImageName #7\n_rlnCtfImage #8\n_rlnRandomSubset #9\n_rlnPixelSize #10\n_rlnMicrographName #11\n_rlnOpticsGroup #12\n_rlnGroupNumber #13\n_rlnOriginXAngst #14\n_rlnOriginYAngst #15\n_rlnOriginZAngst #16\n_rlnClassNumber #17\n_rlnNormCorrection #18\n_rlnLogLikeliContribution #19\n_rlnMaxValueProbDistribution #20\n_rlnNrOfSignificantSamples #21\n880.274000  895.057900  1107.245000 131.246000  106.820800  45.228430   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000000_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000000_ctf_3.30A.mrc 2   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    6   1.000000    4150981.000000  1.000000    1\n973.165500  958.641800  1115.101000 87.247110   109.236500  45.323810   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000001_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000001_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    4   1.000000    4150837.000000  1.000000    1\n955.949400  960.465100  629.459100  9.331370    99.309980   11.024810   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000002_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000002_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    3   1.000000    4150650.000000  1.000000    1\n1175.177000 1135.731000 882.605200  -147.261200 81.605380   77.325710   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000003_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000003_ctf_3.30A.mrc 2   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    1   1.000000    4151420.000000  1.000000    1\n1190.658000 1122.102000 1073.642000 40.404590   98.061770   42.563060   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000004_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000004_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    6   1.000000    4150168.000000  1.000000    1\n
"},{"location":"examples/multi_block/#reading","title":"Reading","text":"

Reading a file with multiple data blocks is similar to reading a file with a single data block. In this case, a dictionary of dataframes or dictionaries is returned. The keys of this dictionary are the names of data blocks.

import starfile\n\nstar = starfile.read('particles.star')\noptics_df = star['optics']\nparticle_df = star['particles']\n

Tip

starfile.read can be forced to always return a dictionary of entries.

starfile.read('particles.star', force_dict=True)\n
"},{"location":"examples/multi_block/#writing","title":"Writing","text":"

Writing a file containing multiple data blocks is similar, simply pass a dictionary of entries.

import starfile\n\n\nstarfile.write(\n    {'optics': optics_df, 'particles': particle_df}, 'new_file.star'\n)\n
"},{"location":"examples/single_block/","title":"single data block example","text":"

In this example, we will use starfile to read and write a STAR file with a single data block.

particles.star
data_particles\n\nloop_\n_rlnCoordinateX #1\n_rlnCoordinateY #2\n_rlnCoordinateZ #3\n_rlnAngleRot #4\n_rlnAngleTilt #5\n_rlnAnglePsi #6\n_rlnMicrographName #7\n91.798700   83.622600   203.341030  -51.740000  173.930000  32.971000   01_10.00Apx.mrc\n97.635800   80.437000   203.136160  141.500000  171.760000  -134.680000 01_10.00Apx.mrc\n92.415200   88.842700   210.663900  -78.750000  173.930000  87.263200   01_10.00Apx.mrc\n94.607830   93.135410   205.425960  -85.215000  167.170000  85.632200   01_10.00Apx.mrc\n86.187800   80.125400   204.558750  14.910000   163.260000  -16.030000  01_10.00Apx.mrc\n91.824240   76.738300   203.794280  39.740000   168.410000  -57.250000  01_10.00Apx.mrc\n98.253300   73.530100   203.856030  73.950000   166.380000  -84.640000  01_10.00Apx.mrc\n101.303500  80.290800   194.790400  -178.878000 166.090000  73.181000   01_10.00Apx.mrc\n

Read the file

import starfile\ndf = starfile.read('particles.star')\n

Interact with the data

df['rlnCoordinateX'] += 10\ndf.head()\n
   rlnCoordinateX  rlnCoordinateY  rlnCoordinateZ  rlnAngleRot  rlnAngleTilt  rlnAnglePsi rlnMicrographName\n0       101.79870        83.62260       203.34103      -51.740        173.93      32.9710   01_10.00Apx.mrc\n1       107.63580        80.43700       203.13616      141.500        171.76    -134.6800   01_10.00Apx.mrc\n2       102.41520        88.84270       210.66390      -78.750        173.93      87.2632   01_10.00Apx.mrc\n3       104.60783        93.13541       205.42596      -85.215        167.17      85.6322   01_10.00Apx.mrc\n4        96.18780        80.12540       204.55875       14.910        163.26     -16.0300   01_10.00Apx.mrc\n

Note

Simple data blocks (unlike those using the loop_ notation) will return a python dictionary instead of a dataframe:

Save the (modified) data to file

starfile.write(df, 'modified_particles.star')\n

For files containing multiple data blocks, please see the multiple data block example.

"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Overview","text":"

starfile is a package for reading and writing STAR files in Python.

reading and writing a STAR file with a single data block

starfile can be used interactively to inspect/explore files or in scripts and larger software packages to provide basic STAR file I/O functions. Data is exposed as simple python dictionaries or pandas dataframes.

This package was designed principally for compatibility with files generated by RELION. For more information on working with pandas, please see the pandas docs.

"},{"location":"#quickstart","title":"Quickstart","text":"

For the following file particles.star with a single data block

data_particles\n\nloop_\n_rlnCoordinateX #1\n_rlnCoordinateY #2\n_rlnCoordinateZ #3\n_rlnAngleRot #4\n_rlnAngleTilt #5\n_rlnAnglePsi #6\n_rlnMicrographName #7\n91.798700   83.622600   203.341030  -51.740000  173.930000  32.971000   01_10.00Apx.mrc\n97.635800   80.437000   203.136160  141.500000  171.760000  -134.680000 01_10.00Apx.mrc\n92.415200   88.842700   210.663900  -78.750000  173.930000  87.263200   01_10.00Apx.mrc\n94.607830   93.135410   205.425960  -85.215000  167.170000  85.632200   01_10.00Apx.mrc\n86.187800   80.125400   204.558750  14.910000   163.260000  -16.030000  01_10.00Apx.mrc\n91.824240   76.738300   203.794280  39.740000   168.410000  -57.250000  01_10.00Apx.mrc\n98.253300   73.530100   203.856030  73.950000   166.380000  -84.640000  01_10.00Apx.mrc\n101.303500  80.290800   194.790400  -178.878000 166.090000  73.181000   01_10.00Apx.mrc\n

Read the file

import starfile\n\ndf = starfile.read('particles.star')\n

Interact with the data

df['rlnCoordinateX'] += 10\ndf.head()\n
   rlnCoordinateX  rlnCoordinateY  rlnCoordinateZ  rlnAngleRot  rlnAngleTilt  rlnAnglePsi rlnMicrographName\n0       101.79870        83.62260       203.34103      -51.740        173.93      32.9710   01_10.00Apx.mrc\n1       107.63580        80.43700       203.13616      141.500        171.76    -134.6800   01_10.00Apx.mrc\n2       102.41520        88.84270       210.66390      -78.750        173.93      87.2632   01_10.00Apx.mrc\n3       104.60783        93.13541       205.42596      -85.215        167.17      85.6322   01_10.00Apx.mrc\n4        96.18780        80.12540       204.55875       14.910        163.26     -16.0300   01_10.00Apx.mrc\n

Save the (modified) data to file

starfile.write(df, 'modified_particles.star')\n

For more advanced usage please check out the examples.

"},{"location":"#installation","title":"Installation","text":"
pip install starfile\n
"},{"location":"examples/merging/","title":"merging data across tables","text":"

In this example, we will use pandas to merge data from two blocks in a RELION particle STAR file particles.star.

In RELION (>=3.1) particle STAR files contain an optics table and a particles table. Data about optics common to many particles is stored in the optics table.

particles.star
data_optics\n\nloop_\n_rlnOpticsGroup #1\n_rlnOpticsGroupName #2\n_rlnSphericalAberration #3\n_rlnVoltage #4\n_rlnImagePixelSize #5\n_rlnImageSize #6\n_rlnImageDimensionality #7\n1   opticsGroup1    2.700000    300.000000  3.300000    160 3\n\ndata_particles\n\nloop_\n_rlnCoordinateX #1\n_rlnCoordinateY #2\n_rlnCoordinateZ #3\n_rlnAngleRot #4\n_rlnAngleTilt #5\n_rlnAnglePsi #6\n_rlnImageName #7\n_rlnCtfImage #8\n_rlnRandomSubset #9\n_rlnPixelSize #10\n_rlnMicrographName #11\n_rlnOpticsGroup #12\n_rlnGroupNumber #13\n_rlnOriginXAngst #14\n_rlnOriginYAngst #15\n_rlnOriginZAngst #16\n_rlnClassNumber #17\n_rlnNormCorrection #18\n_rlnLogLikeliContribution #19\n_rlnMaxValueProbDistribution #20\n_rlnNrOfSignificantSamples #21\n880.274000  895.057900  1107.245000 131.246000  106.820800  45.228430   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000000_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000000_ctf_3.30A.mrc 2   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    6   1.000000    4150981.000000  1.000000    1\n973.165500  958.641800  1115.101000 87.247110   109.236500  45.323810   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000001_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000001_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    4   1.000000    4150837.000000  1.000000    1\n955.949400  960.465100  629.459100  9.331370    99.309980   11.024810   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000002_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000002_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    3   1.000000    4150650.000000  1.000000    1\n1175.177000 1135.731000 882.605200  -147.261200 81.605380   77.325710   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000003_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000003_ctf_3.30A.mrc 2   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    1   1.000000    4151420.000000  1.000000    1\n1190.658000 1122.102000 1073.642000 40.404590   98.061770   42.563060   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000004_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000004_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    6   1.000000    4150168.000000  1.000000    1\n

The column rlnOpticsGroup is present in both tables.

Merging data from multiple dataframes is an example of a join in relational algebra. In pandas, this is implemented as DataFrame.merge().

import starfile\n\nstar = starfile.read('particles.star')\ndf = star['particles'].merge(star['optics'], on='rlnOpticsGroup')\n

The resulting dataframe contains columns with data from both the particles and optics dataframes.

df.head()\n
   rlnCoordinateX  rlnCoordinateY  rlnCoordinateZ  rlnAngleRot  rlnAngleTilt  ...  rlnSphericalAberration rlnVoltage rlnImagePixelSize  rlnImageSize  rlnImageDimensionality\n0        880.2740        895.0579       1107.2450    131.24600     106.82080  ...                     2.7      300.0               3.3           160                       3\n1        973.1655        958.6418       1115.1010     87.24711     109.23650  ...                     2.7      300.0               3.3           160                       3\n2        955.9494        960.4651        629.4591      9.33137      99.30998  ...                     2.7      300.0               3.3           160                       3\n3       1175.1770       1135.7310        882.6052   -147.26120      81.60538  ...                     2.7      300.0               3.3           160                       3\n4       1190.6580       1122.1020       1073.6420     40.40459      98.06177  ...                     2.7      300.0               3.3           160                       3\n\n[5 rows x 27 columns]\n

This table has the following properties - every column is a variable - every row is an observation - every cell contains a single value

Data in this form is sometimes referred to as tidy data. Tidy data is easier to manipulate.

"},{"location":"examples/multi_block/","title":"multiple data block example","text":"

In this example, we will use starfile to read and write files containing multiple data blocks.

particles.star
data_optics\n\nloop_\n_rlnOpticsGroup #1\n_rlnOpticsGroupName #2\n_rlnSphericalAberration #3\n_rlnVoltage #4\n_rlnImagePixelSize #5\n_rlnImageSize #6\n_rlnImageDimensionality #7\n1   opticsGroup1    2.700000    300.000000  3.300000    160 3\n\ndata_particles\n\nloop_\n_rlnCoordinateX #1\n_rlnCoordinateY #2\n_rlnCoordinateZ #3\n_rlnAngleRot #4\n_rlnAngleTilt #5\n_rlnAnglePsi #6\n_rlnImageName #7\n_rlnCtfImage #8\n_rlnRandomSubset #9\n_rlnPixelSize #10\n_rlnMicrographName #11\n_rlnOpticsGroup #12\n_rlnGroupNumber #13\n_rlnOriginXAngst #14\n_rlnOriginYAngst #15\n_rlnOriginZAngst #16\n_rlnClassNumber #17\n_rlnNormCorrection #18\n_rlnLogLikeliContribution #19\n_rlnMaxValueProbDistribution #20\n_rlnNrOfSignificantSamples #21\n880.274000  895.057900  1107.245000 131.246000  106.820800  45.228430   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000000_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000000_ctf_3.30A.mrc 2   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    6   1.000000    4150981.000000  1.000000    1\n973.165500  958.641800  1115.101000 87.247110   109.236500  45.323810   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000001_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000001_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    4   1.000000    4150837.000000  1.000000    1\n955.949400  960.465100  629.459100  9.331370    99.309980   11.024810   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000002_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000002_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    3   1.000000    4150650.000000  1.000000    1\n1175.177000 1135.731000 882.605200  -147.261200 81.605380   77.325710   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000003_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000003_ctf_3.30A.mrc 2   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    1   1.000000    4151420.000000  1.000000    1\n1190.658000 1122.102000 1073.642000 40.404590   98.061770   42.563060   subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000004_3.30A.mrc subtomo_05Feb21/TS.mrc/TS.mrc_22redo_combined_0000004_ctf_3.30A.mrc 1   3.300000    TS.mrc.tomostar 1   1   0.000000    0.000000    0.000000    6   1.000000    4150168.000000  1.000000    1\n
"},{"location":"examples/multi_block/#reading","title":"Reading","text":"

Reading a file with multiple data blocks is similar to reading a file with a single data block. In this case, a dictionary of dataframes or dictionaries is returned. The keys of this dictionary are the names of data blocks.

import starfile\n\nstar = starfile.read('particles.star')\noptics_df = star['optics']\nparticle_df = star['particles']\n

Tip

starfile.read can be forced to always return a dictionary of entries.

starfile.read('particles.star', force_dict=True)\n
"},{"location":"examples/multi_block/#writing","title":"Writing","text":"

Writing a file containing multiple data blocks is similar, simply pass a dictionary of entries.

import starfile\n\nstarfile.write(\n    {'optics': optics_df, 'particles': particle_df}, 'new_file.star'\n)\n
"},{"location":"examples/single_block/","title":"single data block example","text":"

In this example, we will use starfile to read and write a STAR file with a single data block.

particles.star
data_particles\n\nloop_\n_rlnCoordinateX #1\n_rlnCoordinateY #2\n_rlnCoordinateZ #3\n_rlnAngleRot #4\n_rlnAngleTilt #5\n_rlnAnglePsi #6\n_rlnMicrographName #7\n91.798700   83.622600   203.341030  -51.740000  173.930000  32.971000   01_10.00Apx.mrc\n97.635800   80.437000   203.136160  141.500000  171.760000  -134.680000 01_10.00Apx.mrc\n92.415200   88.842700   210.663900  -78.750000  173.930000  87.263200   01_10.00Apx.mrc\n94.607830   93.135410   205.425960  -85.215000  167.170000  85.632200   01_10.00Apx.mrc\n86.187800   80.125400   204.558750  14.910000   163.260000  -16.030000  01_10.00Apx.mrc\n91.824240   76.738300   203.794280  39.740000   168.410000  -57.250000  01_10.00Apx.mrc\n98.253300   73.530100   203.856030  73.950000   166.380000  -84.640000  01_10.00Apx.mrc\n101.303500  80.290800   194.790400  -178.878000 166.090000  73.181000   01_10.00Apx.mrc\n

Read the file

import starfile\n\ndf = starfile.read('particles.star')\n

Interact with the data

df['rlnCoordinateX'] += 10\ndf.head()\n
   rlnCoordinateX  rlnCoordinateY  rlnCoordinateZ  rlnAngleRot  rlnAngleTilt  rlnAnglePsi rlnMicrographName\n0       101.79870        83.62260       203.34103      -51.740        173.93      32.9710   01_10.00Apx.mrc\n1       107.63580        80.43700       203.13616      141.500        171.76    -134.6800   01_10.00Apx.mrc\n2       102.41520        88.84270       210.66390      -78.750        173.93      87.2632   01_10.00Apx.mrc\n3       104.60783        93.13541       205.42596      -85.215        167.17      85.6322   01_10.00Apx.mrc\n4        96.18780        80.12540       204.55875       14.910        163.26     -16.0300   01_10.00Apx.mrc\n

Note

Simple data blocks (unlike those using the loop_ notation) will return a python dictionary instead of a dataframe:

Save the (modified) data to file

starfile.write(df, 'modified_particles.star')\n

For files containing multiple data blocks, please see the multiple data block example.

"}]} \ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml index 2ac02d1..ab20e6a 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -2,22 +2,22 @@ https://teamtomo.org/starfile/ - 2024-01-15 + 2024-01-16 daily https://teamtomo.org/starfile/examples/merging/ - 2024-01-15 + 2024-01-16 daily https://teamtomo.org/starfile/examples/multi_block/ - 2024-01-15 + 2024-01-16 daily https://teamtomo.org/starfile/examples/single_block/ - 2024-01-15 + 2024-01-16 daily \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 25d2186cd5f24dace7d9847a33891a23402ed8e2..ce72e4a1773550aa545f8c734aa41f2d07cf6d7a 100644 GIT binary patch delta 30 mcmey&_?eMizMF$%x687L>~c&k0u$Aba6EVJWMyS$U;qG|8wlS3 delta 30 mcmey&_?eMizMF$1aO%>D>~c&jLKD@GaLiv