File size: 5,876 Bytes
523133d
 
 
bfa647c
 
523133d
 
 
 
 
 
91d446b
523133d
 
bfa647c
523133d
 
 
bfa647c
 
 
 
 
 
91d446b
 
 
523133d
 
 
 
 
 
91d446b
 
 
 
 
 
523133d
 
 
 
 
 
 
 
 
91d446b
523133d
91d446b
 
 
 
 
bfa647c
523133d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bfa647c
523133d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bfa647c
523133d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5aec4d0
523133d
bfa647c
523133d
bfa647c
 
 
 
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import { useState, useRef } from 'react';
import { Tooltip } from 'react-tooltip';
import 'bootstrap/dist/css/bootstrap.min.css';
import './UploadForm.css';

function UploadForm({
  selectedFile, setSelectedFile,
  formData, setFormData,
  statusText,
  handleSubmit
}) {
  const [isLoadingDemoData, setIsLoadingDemoData] = useState(false);
  const fileInputRef = useRef(null);
  const isDisabled = isLoadingDemoData || statusText != 'Start Analysis';

  const handleFileChange = (e) => {
    setSelectedFile(e.target.files[0]);
  }

  const handleInputChange = (e) => {
    const { name, value } = e.target;
    setFormData(prev => ({ ...prev, [name]: value }));
  };

  const handleLoadDemoData = async (e) => {
    e.preventDefault();
    setIsLoadingDemoData(true);
    setFormData({
      tilt: 20.0,
      num_threshold: 10,
      entropy_threshold: 0.01,
      n_plots: 10
    });

    try {
      const response = await fetch('/demo.cs');
      if (!response.ok) {
        alert('Failed to load demo data.');
      }
      const demoFileBlob = await response.blob();
      const demoFile = new File([demoFileBlob], 'demo.cs', {type: 'application/octet-stream'});

      if (fileInputRef.current) {
        const dataTransfer = new DataTransfer();
        dataTransfer.items.add(demoFile);
        fileInputRef.current.files = dataTransfer.files;
        fileInputRef.current.dispatchEvent(new Event('change', { bubbles: true }));
      }
    } catch (error) {
      alert(`Failed to load demo data: ${error}`);
    } finally {
      setIsLoadingDemoData(false);
    }
  }

  return (
    <>
      <form className="mb-4" onSubmit={handleSubmit}>
        <div className="formentry">
          <label className="form-label d-block">
            Upload <i>.cs</i> File of the Helical Refinement Job
          </label>
          <input
            id="FileInput"
            className="form-control d-block"
            ref={fileInputRef}
            type="file"
            accept=".cs"
            onChange={handleFileChange}
            required
            disabled={isDisabled}
          />
          {selectedFile &&
            <strong className="d-block" style={{color: "red"}}>
              File: {selectedFile.name} <br/>
              Size: {(selectedFile.size / 1024).toFixed(2)} KB
            </strong>
          }
        </div>
        <div className="formentry">
          <label htmlFor="TiltInput" className="form-label d-block">
            Micrograph Tilting (°)
          </label>
          <input
            id="TiltInput"
            className="form-control d-block"
            name="tilt"
            value={formData.tilt}
            onChange={handleInputChange}
            required
            placeholder="Ensure the sign of the tilt is correct."
            data-tooltip-id="TiltInputTooltip"
            disabled={isDisabled}
          />
          <Tooltip
            id="TiltInputTooltip"
            content="Please note that the sign of the tilt will be double-checked during analysis via defocus fitting. You may adjust the sign in the next run if needed."
            place="right"
            variant="dark"
          />
        </div>
        <div className="formentry">
          <label htmlFor="NumThresholdInput" className="form-label d-block">
            Fibril Minimum Particle Count Threshold
          </label>
          <input
            id="NumThresholdInput"
            className="form-control d-block"
            name="num_threshold"
            value={formData.num_threshold}
            onChange={handleInputChange}
            data-tooltip-id="NumThresholdInputTooltip"
            disabled={isDisabled}
          />
          <Tooltip
            id="NumThresholdInputTooltip"
            content="Fibrils containing fewer particles than this threshold will be ignored during analysis."
            place="right"
            variant="dark"
          />
        </div>
        <div className="formentry">
          <label htmlFor="EntropyThresholdInput" className="form-label d-block">
            Fibril Maximum Particle Entropy Threshold
          </label>
          <input
            id="EntropyThresholdInput"
            className="form-control d-block"
            name="entropy_threshold"
            value={formData.entropy_threshold}
            onChange={handleInputChange}
            data-tooltip-id="entropy_threshold_tooltip"
            disabled={isDisabled}
          />
          <Tooltip
            id="entropy_threshold_tooltip"
            content="Fibrils made up of particles whose polarity entropy exceeds this threshold will be excluded from the analysis."
            place="right"
            variant="dark"
          />
        </div>
        <div className="formentry mb-4">
          <label htmlFor="n_plots" className="form-label d-block">
            Number of Fibrils to Analyze
          </label>
          <input
            id="n_plots"
            className="form-control d-block"
            name="n_plots"
            value={formData.n_plots}
            onChange={handleInputChange}
            disabled={isDisabled}
          />
        </div>
        <button className="btn btn-primary w-100" type="submit" disabled={isDisabled}>
          {statusText}
        </button>
      </form>
      <button className="btn btn-primary w-100 mb-4" onClick={handleLoadDemoData} disabled={isDisabled}>
        {isLoadingDemoData ? 'Loading...' : 'Load Demo'}
      </button>
      <div className="d-flex justify-content-center gap-2">
        <a href="https://doi.org/10.1101/2025.09.30.679555" target="_blank" rel="noopener noreferrer" className="btn btn-secondary w-50">Read/Cite Paper</a>
        <a href="https://smart.org.cn/en" target="_blank" rel="noopener noreferrer" className="btn btn-secondary w-50">About Us</a>
      </div>
    </>
  );
}

export default UploadForm;