forked from czimaginginstitute/MotionCor3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCGenStarFile.cpp
More file actions
executable file
·157 lines (146 loc) · 4.43 KB
/
CGenStarFile.cpp
File metadata and controls
executable file
·157 lines (146 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "CMainInc.h"
#include "Align/CAlignInc.h"
#include "Util/CUtilInc.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <memory.h>
#include <sys/types.h>
#include <errno.h>
#include <Util/Util_Time.h>
using namespace MotionCor2;
CGenStarFile* CGenStarFile::m_pInstance = 0L;
CGenStarFile* CGenStarFile::GetInstance(void)
{
if(m_pInstance != 0L) return m_pInstance;
m_pInstance = new CGenStarFile;
return m_pInstance;
}
void CGenStarFile::DeleteInstance(void)
{
if(m_pInstance == 0L) return;
delete m_pInstance;
m_pInstance = 0L;
}
CGenStarFile::CGenStarFile(void)
{
m_pFile = 0L;
pthread_mutex_init(&m_aMutex, NULL);
}
CGenStarFile::~CGenStarFile(void)
{
this->CloseFile();
pthread_mutex_destroy(&m_aMutex);
}
void CGenStarFile::CloseFile(void)
{
if(m_pFile == 0L) return;
fclose(m_pFile);
m_pFile = 0L;
pthread_mutex_unlock(&m_aMutex);
}
void CGenStarFile::OpenFile(char* pcInFile)
{
CInput* pInput = CInput::GetInstance();
if(pInput->m_iOutStarFile == 0) return;
//-------------------------------------
pthread_mutex_lock(&m_aMutex);
char acStarName[256] = {'\0'};
strcpy(acStarName, pInput->m_acOutMrcFile);
char* pcStarMain = strrchr(acStarName, '/');
if(pcStarMain == 0L) pcStarMain = acStarName;
else pcStarMain += 1;
//-------------------
char* pcInMain = strrchr(pcInFile, '/');
if(pcInMain == 0L) strcpy(m_acInMain, pcInFile);
else strcpy(m_acInMain, pcInMain+1);
//----------------------------------
strcpy(pcStarMain, m_acInMain);
char* pcDot = strrchr(pcStarMain, '.');
if(pcDot == 0L) strcat(pcStarMain, ".star");
else strcpy(pcDot, ".star");
//--------------------------
m_pFile = fopen(acStarName, "wt");
if(m_pFile == 0L) return;
//-----------------------
fprintf(m_pFile, "\n# version 30001\n\n");
fprintf(m_pFile, "data_general\n\n");
};
void CGenStarFile::SetStackSize(int* piStkSize)
{
if(m_pFile == 0L) return;
fprintf(m_pFile, "%40s %-16d\n", "_rlnImageSizeX", piStkSize[0]);
fprintf(m_pFile, "%40s %-16d\n", "_rlnImageSizeY", piStkSize[1]);
fprintf(m_pFile, "%40s %-16d\n", "_rlnImageSizeZ", piStkSize[2]);
fprintf(m_pFile, "%40s %s\n", "_rlnMicrographMovieName", m_acInMain);
//-------------------------------------------------------------------
CInput* pInput = CInput::GetInstance();
char* pcGainFile = 0L;
if(strlen(pInput->m_acGainMrc) != 0)
{ pcGainFile = strrchr(pInput->m_acGainMrc, '/');
if(pcGainFile != 0L) pcGainFile += 1;
else pcGainFile = pInput->m_acGainMrc;
}
if(pcGainFile == 0L)
{ fprintf(m_pFile, "%40s\n", "_rlnMicrographGainName");
}
else
{ fprintf(m_pFile, "%40s %s\n", "_rlnMicrographGainName",
pcGainFile);
}
//---------------------
fprintf(m_pFile, "%40s %-16.6f\n", "_rlnOriginalPixelSize",
pInput->m_fPixelSize);
fprintf(m_pFile, "%40s %-16.6f\n", "_rlnMicrographDoseRate",
pInput->m_fFmDose);
fprintf(m_pFile, "%40s %-16.6f\n", "_rlnMicrographPreExposure", 0.0f);
fprintf(m_pFile, "%40s %-16.6f\n", "_rlnVoltage",
(float)pInput->m_iKv);
fprintf(m_pFile, "%40s %-16d\n","_rlnMincrographStartFrame",
pInput->m_aiThrow[0] + 1);
fprintf(m_pFile, "%40s %-16d\n", "_rlnMotionModelVersion", 0);
fprintf(m_pFile, "\n");
}
void CGenStarFile::SetGlobalShifts(float* pfShifts, int iSize)
{
if(m_pFile == 0L) return;
fprintf(m_pFile, "# version 30001\n\n");
fprintf(m_pFile, "data_global_shift\n\n");
fprintf(m_pFile, "loop\n");
fprintf(m_pFile, "_rlnMicrographFrameNumber #1\n");
fprintf(m_pFile, "_rlnMicrographShiftX #2\n");
fprintf(m_pFile, "_rlnMicrographShiftY #3\n");
//--------------------------------------------
float* pfShiftYs = pfShifts + iSize;
float fRefX = pfShifts[0];
float fRefY = pfShiftYs[0];
//-------------------------
for(int i=0; i<iSize; i++)
{ float fSx = pfShifts[i] - pfShifts[0];
float fSy = pfShiftYs[i] - pfShiftYs[0];
fprintf(m_pFile, "%13d %13.6f %13.6f\n", i+1, fSx, fSy);
}
fprintf(m_pFile, "\n");
}
void CGenStarFile::SetHotPixels
( unsigned char* pucBadMap,
int* piMapSize,
bool bPadded
)
{ if(m_pFile == 0L) return;
fprintf(m_pFile, "data_hot_pixels\n\n");
fprintf(m_pFile, "loop\n");
fprintf(m_pFile, "_rlnCoordinateX #1\n");
fprintf(m_pFile, "_rlnCoordinateY #2\n");
int iSizeX = bPadded ? (piMapSize[0] / 2 - 1) * 2 : piMapSize[0];
for(int y=0; y<piMapSize[1]; y++)
{ int i = y * piMapSize[0];
int iY = piMapSize[1] - y; // Daniel
for(int x=0; x<iSizeX; x++)
{ if(pucBadMap[i+x] == 0) continue;
fprintf(m_pFile, "%13.6f %13.6f\n",
x + 1.0f, iY);
}
}
fprintf(m_pFile, "\n\n");
}