CoreMS 4.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- corems/__init__.py +63 -0
- corems/chroma_peak/__init__.py +0 -0
- corems/chroma_peak/calc/ChromaPeakCalc.py +480 -0
- corems/chroma_peak/calc/__init__.py +0 -0
- corems/chroma_peak/calc/subset.py +196 -0
- corems/chroma_peak/factory/__init__.py +0 -0
- corems/chroma_peak/factory/chroma_peak_classes.py +1178 -0
- corems/encapsulation/__init__.py +0 -0
- corems/encapsulation/constant.py +1283 -0
- corems/encapsulation/factory/__init__.py +0 -0
- corems/encapsulation/factory/parameters.py +392 -0
- corems/encapsulation/factory/processingSetting.py +1244 -0
- corems/encapsulation/input/__init__.py +0 -0
- corems/encapsulation/input/parameter_from_json.py +579 -0
- corems/encapsulation/output/__init__.py +0 -0
- corems/encapsulation/output/parameter_to_dict.py +142 -0
- corems/encapsulation/output/parameter_to_json.py +332 -0
- corems/mass_spectra/__init__.py +0 -0
- corems/mass_spectra/calc/GC_Calc.py +84 -0
- corems/mass_spectra/calc/GC_Deconvolution.py +558 -0
- corems/mass_spectra/calc/GC_RI_Calibration.py +44 -0
- corems/mass_spectra/calc/MZSearch.py +249 -0
- corems/mass_spectra/calc/SignalProcessing.py +656 -0
- corems/mass_spectra/calc/__init__.py +0 -0
- corems/mass_spectra/calc/lc_calc.py +5790 -0
- corems/mass_spectra/calc/lc_calc_operations.py +1127 -0
- corems/mass_spectra/factory/GC_Class.py +791 -0
- corems/mass_spectra/factory/__init__.py +0 -0
- corems/mass_spectra/factory/chromat_data.py +51 -0
- corems/mass_spectra/factory/lc_class.py +2721 -0
- corems/mass_spectra/input/__init__.py +0 -0
- corems/mass_spectra/input/andiNetCDF.py +200 -0
- corems/mass_spectra/input/boosterHDF5.py +216 -0
- corems/mass_spectra/input/brukerSolarix.py +153 -0
- corems/mass_spectra/input/brukerSolarix_utils.py +73 -0
- corems/mass_spectra/input/corems_hdf5.py +1710 -0
- corems/mass_spectra/input/massList.py +133 -0
- corems/mass_spectra/input/mzml.py +668 -0
- corems/mass_spectra/input/parserbase.py +239 -0
- corems/mass_spectra/input/rawFileReader.py +1839 -0
- corems/mass_spectra/output/__init__.py +0 -0
- corems/mass_spectra/output/export.py +2800 -0
- corems/mass_spectrum/__init__.py +0 -0
- corems/mass_spectrum/calc/AutoRecalibration.py +237 -0
- corems/mass_spectrum/calc/Calibration.py +602 -0
- corems/mass_spectrum/calc/CalibrationCalc.py +253 -0
- corems/mass_spectrum/calc/KendrickGroup.py +239 -0
- corems/mass_spectrum/calc/MassErrorPrediction.py +436 -0
- corems/mass_spectrum/calc/MassSpectrumCalc.py +303 -0
- corems/mass_spectrum/calc/MeanResolvingPowerFilter.py +212 -0
- corems/mass_spectrum/calc/NoiseCalc.py +371 -0
- corems/mass_spectrum/calc/NoiseCalc_Bayes.py +93 -0
- corems/mass_spectrum/calc/PeakPicking.py +994 -0
- corems/mass_spectrum/calc/__init__.py +0 -0
- corems/mass_spectrum/factory/MassSpectrumClasses.py +1753 -0
- corems/mass_spectrum/factory/__init__.py +0 -0
- corems/mass_spectrum/input/__init__.py +0 -0
- corems/mass_spectrum/input/baseClass.py +531 -0
- corems/mass_spectrum/input/boosterHDF5.py +161 -0
- corems/mass_spectrum/input/coremsHDF5.py +475 -0
- corems/mass_spectrum/input/massList.py +402 -0
- corems/mass_spectrum/input/numpyArray.py +133 -0
- corems/mass_spectrum/output/__init__.py +0 -0
- corems/mass_spectrum/output/export.py +841 -0
- corems/molecular_formula/__init__.py +0 -0
- corems/molecular_formula/calc/MolecularFormulaCalc.py +885 -0
- corems/molecular_formula/calc/__init__.py +0 -0
- corems/molecular_formula/factory/MolecularFormulaFactory.py +895 -0
- corems/molecular_formula/factory/__init__.py +0 -0
- corems/molecular_formula/input/__init__.py +0 -0
- corems/molecular_formula/input/masslist_ref.py +355 -0
- corems/molecular_id/__init__.py +0 -0
- corems/molecular_id/calc/ClusterFilter.py +251 -0
- corems/molecular_id/calc/MolecularFilter.py +122 -0
- corems/molecular_id/calc/SpectralSimilarity.py +632 -0
- corems/molecular_id/calc/__init__.py +0 -0
- corems/molecular_id/calc/math_distance.py +1637 -0
- corems/molecular_id/data/FAMES_REF.msp +980 -0
- corems/molecular_id/data/PNNLMetV20191015.msp +157267 -0
- corems/molecular_id/factory/EI_SQL.py +650 -0
- corems/molecular_id/factory/MolecularLookupTable.py +914 -0
- corems/molecular_id/factory/__init__.py +0 -0
- corems/molecular_id/factory/classification.py +884 -0
- corems/molecular_id/factory/lipid_molecular_metadata.py +50 -0
- corems/molecular_id/factory/molecularSQL.py +827 -0
- corems/molecular_id/factory/spectrum_search_results.py +119 -0
- corems/molecular_id/input/__init__.py +0 -0
- corems/molecular_id/input/nistMSI.py +148 -0
- corems/molecular_id/search/__init__.py +0 -0
- corems/molecular_id/search/compoundSearch.py +214 -0
- corems/molecular_id/search/database_interfaces.py +1527 -0
- corems/molecular_id/search/findOxygenPeaks.py +330 -0
- corems/molecular_id/search/lcms_spectral_search.py +348 -0
- corems/molecular_id/search/molecularFormulaSearch.py +1117 -0
- corems/molecular_id/search/priorityAssignment.py +723 -0
- corems/ms_peak/__init__.py +0 -0
- corems/ms_peak/calc/MSPeakCalc.py +1010 -0
- corems/ms_peak/calc/__init__.py +0 -0
- corems/ms_peak/factory/MSPeakClasses.py +542 -0
- corems/ms_peak/factory/__init__.py +0 -0
- corems/transient/__init__.py +0 -0
- corems/transient/calc/TransientCalc.py +362 -0
- corems/transient/calc/__init__.py +0 -0
- corems/transient/factory/TransientClasses.py +457 -0
- corems/transient/factory/__init__.py +0 -0
- corems/transient/input/__init__.py +0 -0
- corems/transient/input/brukerSolarix.py +461 -0
- corems/transient/input/midasDatFile.py +172 -0
- corems-4.0.0.dist-info/METADATA +475 -0
- corems-4.0.0.dist-info/RECORD +171 -0
- corems-4.0.0.dist-info/WHEEL +5 -0
- corems-4.0.0.dist-info/licenses/LICENSE +22 -0
- corems-4.0.0.dist-info/top_level.txt +4 -0
- examples/archive/scripts/CoreMS_tutorial.py +94 -0
- examples/archive/scripts/DI HR-MS Halogens Bruker.py +196 -0
- examples/archive/scripts/DI HR-MS MassList.py +385 -0
- examples/archive/scripts/GC-MS MetabRef.py +213 -0
- examples/archive/scripts/GC-MS NetCDF.py +217 -0
- examples/archive/scripts/HR-MS Thermo Raw 21T.py +136 -0
- examples/archive/scripts/LC-ICPMS_metal_peaks.py +297 -0
- examples/archive/scripts/LCMS-Thermo.py +460 -0
- examples/archive/scripts/LCMS_isotopes.py +283 -0
- examples/archive/scripts/MSParams_example.py +21 -0
- examples/archive/scripts/Molecular Formula Data Aggreation.py +84 -0
- examples/archive/scripts/Single Mz Search.py +69 -0
- examples/test_notebooks.py +145 -0
- ext_lib/ChemstationMSFileReader.dll +0 -0
- ext_lib/ChemstationMSFileReader.xml +126 -0
- ext_lib/RawFileReaderLicense.doc +0 -0
- ext_lib/ThermoFisher.CommonCore.BackgroundSubtraction.dll +0 -0
- ext_lib/ThermoFisher.CommonCore.BackgroundSubtraction.xml +2307 -0
- ext_lib/ThermoFisher.CommonCore.Data.dll +0 -0
- ext_lib/ThermoFisher.CommonCore.Data.xml +28974 -0
- ext_lib/ThermoFisher.CommonCore.MassPrecisionEstimator.dll +0 -0
- ext_lib/ThermoFisher.CommonCore.MassPrecisionEstimator.xml +241 -0
- ext_lib/ThermoFisher.CommonCore.RawFileReader.dll +0 -0
- ext_lib/ThermoFisher.CommonCore.RawFileReader.xml +31174 -0
- ext_lib/__init__.py +0 -0
- ext_lib/dotnet/OpenMcdf.Extensions.dll +0 -0
- ext_lib/dotnet/OpenMcdf.dll +0 -0
- ext_lib/dotnet/OpenMcdf.xml +1154 -0
- ext_lib/dotnet/System.IO.FileSystem.AccessControl.dll +0 -0
- ext_lib/dotnet/System.IO.FileSystem.AccessControl.xml +506 -0
- ext_lib/dotnet/System.Security.AccessControl.dll +0 -0
- ext_lib/dotnet/System.Security.AccessControl.xml +2043 -0
- ext_lib/dotnet/System.Security.Principal.Windows.dll +0 -0
- ext_lib/dotnet/System.Security.Principal.Windows.xml +1011 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.BackgroundSubtraction.dll +0 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.BackgroundSubtraction.xml +2307 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.Data.dll +0 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.Data.xml +29148 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.MassPrecisionEstimator.dll +0 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.MassPrecisionEstimator.xml +241 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.RawFileReader.dll +0 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.RawFileReader.xml +31492 -0
- ext_lib/version +18 -0
- support_code/atom_parsers/AtomsDescription.py +359 -0
- support_code/atom_parsers/CreateAtomsDescription.py +56 -0
- support_code/nmdc/filefinder.py +90 -0
- support_code/nmdc/lipidomics/lipidomics_workflow.py +748 -0
- support_code/nmdc/lipidomics/manifest_examples.py +49 -0
- support_code/nmdc/metabolomics/gcms_workflow.py +158 -0
- support_code/nmdc/metabolomics/lcms_metabolomics_targeted_search.py +59 -0
- support_code/nmdc/metabolomics/lcms_metabolomics_workflow.py +248 -0
- support_code/nmdc/metabolomics/metabolomics_collection.py +628 -0
- support_code/nmdc/metadata/dms_api.py +42 -0
- support_code/nmdc/nom/archived_scripts/nmdc_metadata_gen.py +288 -0
- support_code/nmdc/nom/archived_scripts/nom_grow_workflow.py +209 -0
- support_code/nmdc/nom/nom_workflow.py +312 -0
- support_code/windows_only_importers/BrukerCompassXtract.py +180 -0
- support_code/windows_only_importers/ThermoMSFileReader.py +405 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
from dataclasses import dataclass, field, asdict
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
import hashlib
|
|
4
|
+
from json import dumps
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import List
|
|
7
|
+
import yaml
|
|
8
|
+
|
|
9
|
+
from linkml_runtime.dumpers import json_dumper
|
|
10
|
+
import nmdc_schema.nmdc as nmdc
|
|
11
|
+
import oauthlib
|
|
12
|
+
import requests_oauthlib
|
|
13
|
+
|
|
14
|
+
from support_code.nmdc.nom.nom_grow_workflow import EMSL_Metadata
|
|
15
|
+
|
|
16
|
+
env_mediums = {'ENVO_00002042': 'surface water',
|
|
17
|
+
'ENVO_00002007': 'sediment',
|
|
18
|
+
'ENVO:00001998': 'soil'
|
|
19
|
+
}
|
|
20
|
+
env_local_scales = {'ENVO_00000022': 'river',
|
|
21
|
+
'ENVO:01000861': 'area of dwarf scrub',
|
|
22
|
+
'ENVO:00000516': 'hummock',
|
|
23
|
+
'ENVO:01000869': 'area of scrub',
|
|
24
|
+
'ENVO:01000887': 'area of sedge- and forb-dominated herbaceous vegetation',
|
|
25
|
+
'ENVO:01001370': 'tundra ecosystem'
|
|
26
|
+
}
|
|
27
|
+
env_broad_scales = {'ENVO_01000253': 'freshwater river biome',
|
|
28
|
+
'ENVO:00000446': 'terrestrial biome'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass
|
|
33
|
+
class NomAnalysisActivity:
|
|
34
|
+
codebase_url:str = "https://github.com/microbiomedata/enviroMS"
|
|
35
|
+
cluster_name:str = "EMSL-RZR"
|
|
36
|
+
nom_21T_instrument_name: str = "21T_Agilent"
|
|
37
|
+
nom_12T_instrument_name: str = "12T_FTICR_B"
|
|
38
|
+
nom_7T_instrument_name: str = "7T_FT_ICR_MS"
|
|
39
|
+
|
|
40
|
+
@dataclass
|
|
41
|
+
class OmicsProcessing:
|
|
42
|
+
nom_omics_processing_type:str = "Organic Matter Characterization"
|
|
43
|
+
nom_omics_processing_description:str = "High resolution MS spectra only"
|
|
44
|
+
nom_21T_instrument_name: str = "21T Agilent"
|
|
45
|
+
nom_12T_instrument_name: str = "12T_FTICR_B"
|
|
46
|
+
nom_7T_instrument_name: str = "7T_FT_ICR_MS"
|
|
47
|
+
|
|
48
|
+
@dataclass
|
|
49
|
+
class DataObject:
|
|
50
|
+
nom_raw_data_object_type:str = "Direct Infusion FT ICR-MS Raw Data"
|
|
51
|
+
nom_raw_data_object_description:str = "Raw 21T Direct Infusion Data"
|
|
52
|
+
nom_dp_data_object_type:str = "FT ICR-MS Analysis Results"
|
|
53
|
+
nom_dp_data_object_description:str = "EnviroMS FT ICR-MS natural organic matter workflow molecular formula assignment output details"
|
|
54
|
+
|
|
55
|
+
@dataclass
|
|
56
|
+
class Biosample:
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
@dataclass
|
|
60
|
+
class NMDC_Types:
|
|
61
|
+
|
|
62
|
+
Biosample:str = "nmdc:Biosample"
|
|
63
|
+
OmicsProcessing:str = "nmdc:OmicsProcessing"
|
|
64
|
+
NomAnalysisActivity:str = "nmdc:NomAnalysisActivity"
|
|
65
|
+
DataObject:str = "nmdc:DataObject"
|
|
66
|
+
|
|
67
|
+
@dataclass
|
|
68
|
+
class NMDC_Mint:
|
|
69
|
+
|
|
70
|
+
schema_class: dict = field(default_factory= lambda: {
|
|
71
|
+
'schema': None,
|
|
72
|
+
})
|
|
73
|
+
how_many:int = 1
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def __dict__(self):
|
|
77
|
+
return asdict(self)
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def json(self):
|
|
81
|
+
return dumps(self.__dict__)
|
|
82
|
+
|
|
83
|
+
def mint_nmdc_id(type:NMDC_Types, how_many:int = 1) -> List[str]:
|
|
84
|
+
|
|
85
|
+
config = yaml.safe_load(open('./config.yaml','r'))
|
|
86
|
+
client = oauthlib.oauth2.BackendApplicationClient(client_id=config['client_id'])
|
|
87
|
+
oauth = requests_oauthlib.OAuth2Session(client=client)
|
|
88
|
+
|
|
89
|
+
token = oauth.fetch_token(token_url='https://api.microbiomedata.org/token',
|
|
90
|
+
client_id=config['client_id'],
|
|
91
|
+
client_secret=config['client_secret'])
|
|
92
|
+
|
|
93
|
+
nmdc_mint_url = "https://api.microbiomedata.org/pids/mint"
|
|
94
|
+
|
|
95
|
+
payload = NMDC_Mint(type, how_many)
|
|
96
|
+
|
|
97
|
+
#response = s.post(nmdc_mint_url, data=payload.json, )
|
|
98
|
+
#list_ids = response.json()
|
|
99
|
+
print(payload.json)
|
|
100
|
+
response = oauth.post(nmdc_mint_url, data=payload.json)
|
|
101
|
+
list_ids = response.json()
|
|
102
|
+
print(list_ids)
|
|
103
|
+
return list_ids
|
|
104
|
+
|
|
105
|
+
def get_biosample_object(emsl_metadata:EMSL_Metadata) -> nmdc.Biosample:
|
|
106
|
+
|
|
107
|
+
nmdc_id = mint_nmdc_id({'id': NMDC_Types.Biosample})[0]
|
|
108
|
+
|
|
109
|
+
env_medium = {
|
|
110
|
+
'has_raw_value': emsl_metadata.env_medium,
|
|
111
|
+
'term':{'id': emsl_metadata.env_medium,
|
|
112
|
+
'name': env_mediums.get(emsl_metadata.env_medium)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
env_local_scale = {
|
|
117
|
+
'has_raw_value': emsl_metadata.env_local_scale,
|
|
118
|
+
'term':{'id': emsl_metadata.env_local_scale,
|
|
119
|
+
'name': env_local_scales.get(emsl_metadata.env_local_scale)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
env_broad_scale = {
|
|
124
|
+
'has_raw_value': emsl_metadata.env_broad_scale,
|
|
125
|
+
'term':{'id': emsl_metadata.env_broad_scale,
|
|
126
|
+
'name': env_local_scales.get(emsl_metadata.env_broad_scale)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
lat_lon = {
|
|
130
|
+
"has_raw_value": emsl_metadata.lat_long,
|
|
131
|
+
"latitude": emsl_metadata.latitude,
|
|
132
|
+
"longitude": emsl_metadata.longitude,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
collection_date = {'has_raw_value': emsl_metadata.collection_date}
|
|
136
|
+
|
|
137
|
+
geo_loc_name = {'has_raw_value': emsl_metadata.geo_loc_name}
|
|
138
|
+
|
|
139
|
+
data_dict = {'id': nmdc_id,
|
|
140
|
+
'env_medium' : env_medium,
|
|
141
|
+
'env_local_scale' : env_local_scale,
|
|
142
|
+
'env_broad_scale' : env_broad_scale,
|
|
143
|
+
'lat_lon': lat_lon,
|
|
144
|
+
'location': emsl_metadata.location,
|
|
145
|
+
'ecosystem_type': emsl_metadata.ecosystem_type,
|
|
146
|
+
'ecosystem': emsl_metadata.ecosystem,
|
|
147
|
+
'sample_collection_site': emsl_metadata.sample_collection_site,
|
|
148
|
+
'part_of': [emsl_metadata.nmdc_study],
|
|
149
|
+
'samp_name': emsl_metadata.samp_name,
|
|
150
|
+
'ecosystem_subtype': emsl_metadata.ecosystem_subtype,
|
|
151
|
+
'habitat': emsl_metadata.habitat,
|
|
152
|
+
'ecosystem_category': emsl_metadata.ecosystem_category,
|
|
153
|
+
'name': emsl_metadata.name,
|
|
154
|
+
'geo_loc_name': geo_loc_name,
|
|
155
|
+
'collection_date': collection_date,
|
|
156
|
+
"description": emsl_metadata.description,
|
|
157
|
+
"type": "nmdc:Biosample"
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
biosample_object = nmdc.Biosample(**data_dict)
|
|
161
|
+
|
|
162
|
+
return biosample_object
|
|
163
|
+
|
|
164
|
+
def get_data_object(file_path:Path, base_url:str, was_generated_by:str,
|
|
165
|
+
data_object_type:str, description:str) -> nmdc.DataObject:
|
|
166
|
+
|
|
167
|
+
nmdc_id = mint_nmdc_id({'id': NMDC_Types.DataObject})[0]
|
|
168
|
+
|
|
169
|
+
data_dict = {
|
|
170
|
+
'id': nmdc_id,
|
|
171
|
+
"name": file_path.name,
|
|
172
|
+
"file_size_bytes": file_path.stat().st_size,
|
|
173
|
+
"md5_checksum": hashlib.md5(file_path.open('rb').read()).hexdigest(),
|
|
174
|
+
"url": base_url + str(file_path.name),
|
|
175
|
+
"was_generated_by": was_generated_by,
|
|
176
|
+
"data_object_type": data_object_type,
|
|
177
|
+
"description": description,
|
|
178
|
+
"type": "nmdc:DataObject"
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
data_object = nmdc.DataObject(**data_dict)
|
|
182
|
+
|
|
183
|
+
return data_object
|
|
184
|
+
|
|
185
|
+
def get_omics_processing(file_path:Path, instrument_name:str, sample_id:str,
|
|
186
|
+
raw_data_id:str, omics_type:str,
|
|
187
|
+
description:str, project_id:str) -> nmdc.OmicsProcessing:
|
|
188
|
+
|
|
189
|
+
nmdc_id = mint_nmdc_id({'id': NMDC_Types.OmicsProcessing})[0]
|
|
190
|
+
|
|
191
|
+
data_dict = {
|
|
192
|
+
'id': nmdc_id,
|
|
193
|
+
"name": file_path.stem,
|
|
194
|
+
"instrument_name": instrument_name,
|
|
195
|
+
"has_input": [sample_id],
|
|
196
|
+
"has_output": [raw_data_id],
|
|
197
|
+
"omics_type": {"has_raw_value": omics_type},
|
|
198
|
+
"part_of": project_id,
|
|
199
|
+
"processing_institution": "EMSL",
|
|
200
|
+
"description": description,
|
|
201
|
+
"type": "nmdc:OmicsProcessing"
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
omicsProcessing = nmdc.OmicsProcessing(**data_dict)
|
|
205
|
+
|
|
206
|
+
return omicsProcessing
|
|
207
|
+
|
|
208
|
+
def get_nom_analysis_activity(cluster_name:str, code_repository_url:str,
|
|
209
|
+
raw_data_id:str, data_product_id:str,
|
|
210
|
+
has_calibration:bool, omics_processing_id:str,
|
|
211
|
+
instrument_name:str) -> nmdc.NomAnalysisActivity:
|
|
212
|
+
|
|
213
|
+
nmdc_id = mint_nmdc_id({'id': NMDC_Types.NomAnalysisActivity})[0]
|
|
214
|
+
|
|
215
|
+
data_dict = {
|
|
216
|
+
'id': nmdc_id,
|
|
217
|
+
"execution_resource": cluster_name,
|
|
218
|
+
"git_url": code_repository_url,
|
|
219
|
+
"has_input": [raw_data_id],
|
|
220
|
+
"has_output": [data_product_id],
|
|
221
|
+
"has_calibration": has_calibration,
|
|
222
|
+
"ended_at_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
223
|
+
"started_at_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
224
|
+
"used": instrument_name,
|
|
225
|
+
"was_informed_by": omics_processing_id,
|
|
226
|
+
"type": "nmdc:NomAnalysisActivity"
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
nomAnalysisActivity = nmdc.NomAnalysisActivity(**data_dict)
|
|
230
|
+
|
|
231
|
+
return nomAnalysisActivity
|
|
232
|
+
|
|
233
|
+
def start_nmdc_database() -> nmdc.Database:
|
|
234
|
+
return nmdc.Database()
|
|
235
|
+
|
|
236
|
+
def create_nmdc_metadata(raw_data_path:Path, data_product_path:Path, base_url:str,
|
|
237
|
+
nom_metadata_db:nmdc.Database,
|
|
238
|
+
emsl_metadata:EMSL_Metadata, biosample_id=None):
|
|
239
|
+
|
|
240
|
+
if not biosample_id:
|
|
241
|
+
|
|
242
|
+
biosample_id = mint_nmdc_id({'id': NMDC_Types.Biosample})[0]
|
|
243
|
+
bioSample = get_biosample_object(emsl_metadata)
|
|
244
|
+
biosample_id = bioSample.id
|
|
245
|
+
|
|
246
|
+
else:
|
|
247
|
+
|
|
248
|
+
''' needs to finish the logic for creating biosamples, this will fail because it is missing some required fields'''
|
|
249
|
+
bioSample = None
|
|
250
|
+
|
|
251
|
+
omicsProcessing = get_omics_processing(raw_data_path,
|
|
252
|
+
OmicsProcessing.nom_7T_instrument_name,
|
|
253
|
+
biosample_id, 'nmdc:placeholder',
|
|
254
|
+
OmicsProcessing.nom_omics_processing_type,
|
|
255
|
+
OmicsProcessing.nom_omics_processing_description,
|
|
256
|
+
emsl_metadata.nmdc_study
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
rawDataObject = get_data_object(raw_data_path, base_url + 'nom/1000soils/raw/',
|
|
260
|
+
was_generated_by=omicsProcessing.id,
|
|
261
|
+
data_object_type =DataObject.nom_raw_data_object_type,
|
|
262
|
+
description =DataObject.nom_raw_data_object_description)
|
|
263
|
+
|
|
264
|
+
nomAnalysisActivity = get_nom_analysis_activity(NomAnalysisActivity.cluster_name,
|
|
265
|
+
NomAnalysisActivity.codebase_url,
|
|
266
|
+
rawDataObject.id, 'nmdc:placeholder', False,
|
|
267
|
+
omicsProcessing.id,
|
|
268
|
+
NomAnalysisActivity.nom_7T_instrument_name)
|
|
269
|
+
|
|
270
|
+
dataProductDataObject = get_data_object(data_product_path, base_url + 'nom/1000soils/results/',
|
|
271
|
+
was_generated_by=nomAnalysisActivity.id,
|
|
272
|
+
data_object_type =DataObject.nom_dp_data_object_type,
|
|
273
|
+
description =DataObject.nom_dp_data_object_description)
|
|
274
|
+
|
|
275
|
+
#circular dependencies : great!
|
|
276
|
+
nomAnalysisActivity.has_output = [dataProductDataObject.id]
|
|
277
|
+
omicsProcessing.has_output = [rawDataObject.id]
|
|
278
|
+
|
|
279
|
+
if bioSample:
|
|
280
|
+
nom_metadata_db.biosample_set.append(bioSample)
|
|
281
|
+
nom_metadata_db.data_object_set.append(rawDataObject)
|
|
282
|
+
nom_metadata_db.nom_analysis_activity_set.append(nomAnalysisActivity)
|
|
283
|
+
nom_metadata_db.omics_processing_set.append(omicsProcessing)
|
|
284
|
+
nom_metadata_db.data_object_set.append(dataProductDataObject)
|
|
285
|
+
|
|
286
|
+
def dump_nmdc_database(ndmc_database:nmdc.Database, output_filepath:str):
|
|
287
|
+
|
|
288
|
+
json_dumper.dump(ndmc_database, output_filepath)
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import shutil
|
|
6
|
+
import argparse
|
|
7
|
+
from zipfile import ZipFile
|
|
8
|
+
|
|
9
|
+
from openpyxl import load_workbook
|
|
10
|
+
|
|
11
|
+
from nom_workflow import run_nmdc_workflow
|
|
12
|
+
import nmdc_metadata_gen
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class EMSL_Metadata:
|
|
16
|
+
data_path: str
|
|
17
|
+
dms_dataset_id: str
|
|
18
|
+
myemsl_link: str
|
|
19
|
+
sample_name: str
|
|
20
|
+
sample_type: str
|
|
21
|
+
env_medium: str
|
|
22
|
+
habitat: str
|
|
23
|
+
ecosystem_category: str
|
|
24
|
+
name: str
|
|
25
|
+
geo_loc_name: str
|
|
26
|
+
lat_long: str
|
|
27
|
+
latitude: float
|
|
28
|
+
longitude: float
|
|
29
|
+
location: str
|
|
30
|
+
ecosystem_type: str
|
|
31
|
+
ecosystem: str
|
|
32
|
+
env_broad_scale: str
|
|
33
|
+
env_local_scale: str
|
|
34
|
+
sample_collection_site: str
|
|
35
|
+
samp_name: str
|
|
36
|
+
ecosystem_subtype: str
|
|
37
|
+
description: str
|
|
38
|
+
collection_date: str
|
|
39
|
+
nmdc_study: str
|
|
40
|
+
biosample_id: str
|
|
41
|
+
|
|
42
|
+
def parse_metadata(metadata_file_path:Path) -> EMSL_Metadata:
|
|
43
|
+
|
|
44
|
+
wb = load_workbook(filename=metadata_file_path)
|
|
45
|
+
|
|
46
|
+
first_sheet = wb.sheetnames[0]
|
|
47
|
+
|
|
48
|
+
full_list_worksheet = wb[first_sheet]
|
|
49
|
+
|
|
50
|
+
data_name = full_list_worksheet['A']
|
|
51
|
+
dms_dataset_id = full_list_worksheet['B']
|
|
52
|
+
myemsl_link = full_list_worksheet['C']
|
|
53
|
+
sample_name = full_list_worksheet['D']
|
|
54
|
+
sample_type = full_list_worksheet['E']
|
|
55
|
+
env_medium = full_list_worksheet['F']
|
|
56
|
+
habitat = full_list_worksheet['G']
|
|
57
|
+
ecosystem_category = full_list_worksheet['H']
|
|
58
|
+
name = full_list_worksheet['J']
|
|
59
|
+
geo_loc_name = full_list_worksheet['K']
|
|
60
|
+
lat_long = full_list_worksheet['L']
|
|
61
|
+
latitude = full_list_worksheet['M']
|
|
62
|
+
longitude = full_list_worksheet['N']
|
|
63
|
+
env_local_scale = full_list_worksheet['O']
|
|
64
|
+
location = full_list_worksheet['P']
|
|
65
|
+
ecosystem_type = full_list_worksheet['Q']
|
|
66
|
+
ecosystem = full_list_worksheet['S']
|
|
67
|
+
env_broad_scale = full_list_worksheet['T']
|
|
68
|
+
sample_collection_site = full_list_worksheet['V']
|
|
69
|
+
samp_name = full_list_worksheet['W']
|
|
70
|
+
ecosystem_subtype = full_list_worksheet['X']
|
|
71
|
+
description = full_list_worksheet['Z']
|
|
72
|
+
collection_date = full_list_worksheet['AA']
|
|
73
|
+
nmdc_study = full_list_worksheet['AB']
|
|
74
|
+
biosample_id = full_list_worksheet['AC']
|
|
75
|
+
|
|
76
|
+
for x in range(1, len(full_list_worksheet['A'])):
|
|
77
|
+
|
|
78
|
+
metadata = EMSL_Metadata(data_path = Path(data_name[x].value),
|
|
79
|
+
dms_dataset_id = dms_dataset_id[x].value,
|
|
80
|
+
myemsl_link = myemsl_link[x].value,
|
|
81
|
+
sample_name = sample_name[x].value,
|
|
82
|
+
sample_type = sample_type[x].value,
|
|
83
|
+
env_medium = env_medium[x].value,
|
|
84
|
+
habitat = habitat[x].value,
|
|
85
|
+
ecosystem_category = ecosystem_category[x].value,
|
|
86
|
+
name = name[x].value,
|
|
87
|
+
geo_loc_name = geo_loc_name[x].value,
|
|
88
|
+
lat_long = lat_long[x].value,
|
|
89
|
+
latitude = latitude[x].value,
|
|
90
|
+
longitude = longitude[x].value,
|
|
91
|
+
env_local_scale = env_local_scale[x].value,
|
|
92
|
+
location = location[x].value,
|
|
93
|
+
ecosystem_type = ecosystem_type[x].value,
|
|
94
|
+
ecosystem = ecosystem[x].value,
|
|
95
|
+
env_broad_scale = env_broad_scale[x].value,
|
|
96
|
+
sample_collection_site = sample_collection_site[x].value,
|
|
97
|
+
samp_name = samp_name[x].value,
|
|
98
|
+
ecosystem_subtype = ecosystem_subtype[x].value,
|
|
99
|
+
description = description[x].value,
|
|
100
|
+
collection_date = collection_date[x].value,
|
|
101
|
+
nmdc_study = nmdc_study[x].value,
|
|
102
|
+
biosample_id = biosample_id[x].value
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
yield metadata
|
|
106
|
+
|
|
107
|
+
def run_nom_nmdc_data_processing():
|
|
108
|
+
|
|
109
|
+
# set command line arguments
|
|
110
|
+
parser = argparse.ArgumentParser(description="A program to run the nmdc nom workflow and create the corresponding metadata objects.")
|
|
111
|
+
parser.add_argument('--data_dir',
|
|
112
|
+
'-d',
|
|
113
|
+
type=str,
|
|
114
|
+
help="The directory path where the raw data lives.")
|
|
115
|
+
parser.add_argument('--metadata_path',
|
|
116
|
+
'-m',
|
|
117
|
+
type=str,
|
|
118
|
+
help="The .xlsx file path where the biosample metadata lives (include .xlsx).")
|
|
119
|
+
parser.add_argument('--registration_file_name',
|
|
120
|
+
'-rf',
|
|
121
|
+
type=str,
|
|
122
|
+
help="The desired name of the registration file (include .json). E.g. emsl_only_grow.json")
|
|
123
|
+
parser.add_argument("--ref_calibration_path",
|
|
124
|
+
'-r',
|
|
125
|
+
type=str,
|
|
126
|
+
help="The .ref path where the reference calibration data lives (include .ref).")
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
args = parser.parse_args()
|
|
130
|
+
|
|
131
|
+
file_ext = '.d'
|
|
132
|
+
data_dir = Path(args.data_dir)
|
|
133
|
+
metadata_file_path = Path(args.metadata_path)
|
|
134
|
+
|
|
135
|
+
raw_dir_zip = data_dir / Path("raw_zip/")
|
|
136
|
+
raw_dir_zip.mkdir(parents=True, exist_ok=True)
|
|
137
|
+
|
|
138
|
+
results_dir = data_dir / Path("results/")
|
|
139
|
+
results_dir.mkdir(parents=True, exist_ok=True)
|
|
140
|
+
|
|
141
|
+
failed_files = results_dir / "nom_failed_files.json"
|
|
142
|
+
|
|
143
|
+
registration_dir = data_dir / 'registration'
|
|
144
|
+
registration_dir.mkdir(parents=True, exist_ok=True)
|
|
145
|
+
registration_file = registration_dir / args.registration_file_name
|
|
146
|
+
|
|
147
|
+
field_strength = 7
|
|
148
|
+
|
|
149
|
+
ref_calibration_path = Path(args.ref_calibration_path)
|
|
150
|
+
failed_list = []
|
|
151
|
+
|
|
152
|
+
nmdc_database = nmdc_metadata_gen.start_nmdc_database()
|
|
153
|
+
|
|
154
|
+
for each_data in parse_metadata(metadata_file_path):
|
|
155
|
+
|
|
156
|
+
raw_file_path = data_dir / each_data.data_path.with_suffix(file_ext)
|
|
157
|
+
|
|
158
|
+
print(raw_file_path)
|
|
159
|
+
|
|
160
|
+
issue, ms = run_nmdc_workflow((raw_file_path, ref_calibration_path, field_strength))
|
|
161
|
+
|
|
162
|
+
try:
|
|
163
|
+
if ms:
|
|
164
|
+
|
|
165
|
+
if raw_file_path.suffix =='.d':
|
|
166
|
+
#raw_file_to_upload_path = zip_d_folder(raw_file_path)
|
|
167
|
+
raw_file_to_upload_path = Path(raw_dir_zip / raw_file_path.stem)
|
|
168
|
+
shutil.make_archive(raw_file_to_upload_path , 'zip', raw_file_path)
|
|
169
|
+
else:
|
|
170
|
+
raw_file_to_upload_path = raw_file_path
|
|
171
|
+
|
|
172
|
+
result_file_name = Path(raw_file_path.name)
|
|
173
|
+
output_file_path = results_dir / result_file_name.with_suffix('.csv')
|
|
174
|
+
ms.to_csv(output_file_path, write_metadata=False)
|
|
175
|
+
|
|
176
|
+
nmdc_metadata_gen.create_nmdc_metadata(raw_file_to_upload_path.with_suffix('.zip'),
|
|
177
|
+
output_file_path,
|
|
178
|
+
"https://nmdcdemo.emsl.pnnl.gov/",
|
|
179
|
+
nmdc_database,
|
|
180
|
+
each_data, biosample_id=each_data.biosample_id)
|
|
181
|
+
|
|
182
|
+
else:
|
|
183
|
+
|
|
184
|
+
print(issue)
|
|
185
|
+
failed_list.append(str(raw_file_path))
|
|
186
|
+
|
|
187
|
+
except Exception as inst:
|
|
188
|
+
|
|
189
|
+
print(type(inst)) # the exception instance
|
|
190
|
+
print(inst.args) # arguments stored in .args
|
|
191
|
+
print(inst)
|
|
192
|
+
failed_list.append(str(raw_file_path))
|
|
193
|
+
|
|
194
|
+
nmdc_metadata_gen.dump_nmdc_database(nmdc_database, registration_file)
|
|
195
|
+
|
|
196
|
+
with failed_files.open('w+') as json_file:
|
|
197
|
+
|
|
198
|
+
json_file.write(json.dumps(failed_list, indent=1))
|
|
199
|
+
|
|
200
|
+
if __name__ == "__main__":
|
|
201
|
+
|
|
202
|
+
# run_multiprocess()
|
|
203
|
+
# cpu_percents = monitor(target=run_multiprocess)
|
|
204
|
+
# print(cpu_percents)
|
|
205
|
+
run_nom_nmdc_data_processing()
|
|
206
|
+
# file_location = get_filename()
|
|
207
|
+
# if file_location:
|
|
208
|
+
# run_assignment(file_location)
|
|
209
|
+
|