def onstart(**k): #_gnps_list = utils.load_GNPS(library_names=["GNPS-LIBRARY"]) _gnps_list = utils.load_GNPS() _gnps_list = utils.gnps_format_libraries(_gnps_list) gnps_df = pd.DataFrame(_gnps_list) gnps_df.to_feather("gnps_list.feather")
def test_filtered_spectra(): import utils spectra_list = utils.load_GNPS(library_names=["GNPS-LIBRARY"]) spectra_list = utils.gnps_format_libraries(spectra_list) with open("output_enriched_list.json", "w") as output_file: output_file.write(json.dumps(spectra_list, indent=4)) filtered_list = utils.gnps_filter_for_key(spectra_list) with open("output_filtered_list.json", "w") as output_file: output_file.write(json.dumps(filtered_list, indent=4)) print(len(filtered_list))
def generate_gnps_data(): # Loading all GNPS Library Spectra, without peaks gnps_libraries = utils.load_GNPS() print("Got all Libraries") with open("/output/gnpslibraries.json", "w") as output_file: output_file.write(json.dumps(gnps_libraries)) encriched_gnps_libraries = utils.gnps_format_libraries(gnps_libraries) print("Enriched Libraries") with open("/output/gnpslibraries_enriched_all.json", "w") as output_file: output_file.write( json.dumps( utils.gnps_filter_for_key(encriched_gnps_libraries, filterKeysOut=False))) #Outputting for NPAtlas with open("/output/gnpslibraries_npatlas.json", "w") as output_file: output_file.write( json.dumps( utils.gnps_filter_for_key(encriched_gnps_libraries, filterKeysOut=True))) pd.DataFrame(utils.gnps_filter_for_key(encriched_gnps_libraries)).to_csv( "/output/gnpslibraries_npatlas.tsv", sep="\t", index=False) print("NPAtlas Export") # Getting spectrum peaks for each library spectrum print("Individual Library Export") encriched_gnps_libraries_with_peaks = utils.output_all_gnps_individual_libraries( encriched_gnps_libraries, "/output/") with open("/output/ALL_GNPS.json", "w") as output_file: output_file.write(json.dumps(encriched_gnps_libraries_with_peaks)) print("MGF Library Export") # Generating the MGF versions of it mgf_string = utils.get_full_mgf_string(encriched_gnps_libraries_with_peaks) with open("/output/ALL_GNPS.mgf", "wb") as output_file: output_file.write(mgf_string.encode("ascii", "ignore")) print("MSP Library Export") # TODO: Generating the MSP versions of it msp_string = utils.get_full_msp_string(encriched_gnps_libraries_with_peaks) with open("/output/ALL_GNPS.msp", "wb") as output_file: output_file.write(msp_string.encode("ascii", "ignore"))
def test_get_library_peaks_full(): import utils output_folder = "." spectra_list = utils.load_GNPS() spectra_list = utils.gnps_format_libraries(spectra_list) spectra_list_with_peaks = utils.output_all_gnps_individual_libraries( spectra_list, ".") with open("ALL_GNPS.json", "w") as output_file: output_file.write(json.dumps(spectra_list_with_peaks, indent=4)) mgf_string = utils.get_full_mgf_string(spectra_list_with_peaks) with open("ALL_GNPS.mgf", "wb") as output_file: output_file.write(mgf_string.encode("ascii", "ignore")) msp_string = utils.get_full_msp_string(spectra_list_with_peaks) with open("ALL_GNPS.msp", "wb") as output_file: output_file.write(msp_string.encode("ascii", "ignore"))
def test_get_library_peaks(): import utils spectra_list = utils.load_GNPS(library_names=["GNPS-LIBRARY"])[:100] spectra_list = utils.gnps_format_libraries(spectra_list) spectra_list_with_peaks = utils.output_all_gnps_individual_libraries( spectra_list, ".") print(len(spectra_list_with_peaks)) with open("ALL_GNPS.json", "w") as output_file: output_file.write(json.dumps(spectra_list_with_peaks, indent=4)) mgf_string = utils.get_full_mgf_string(spectra_list_with_peaks) with open("ALL_GNPS.mgf", "wb") as output_file: output_file.write(mgf_string.encode("ascii", "ignore")) msp_string = utils.get_full_msp_string(spectra_list_with_peaks) with open("ALL_GNPS.msp", "wb") as output_file: output_file.write(msp_string.encode("ascii", "ignore"))
library_name = "ALL_GNPS" library_dict = {} library_dict["libraryname"] = library_name library_dict["mgflink"] = "/gnpslibrary/{}.mgf".format(library_name) library_dict["msplink"] = "/gnpslibrary/{}.msp".format(library_name) library_dict["jsonlink"] = "/gnpslibrary/{}.json".format(library_name) library_list.append(library_dict) return render_template('gnpslibrarylist.html', library_list=library_list) @app.route('/gnpslibrary/<library>.mgf', methods=['GET']) def mgf_download(library): return send_from_directory("/output", "{}.mgf".format(library)) @app.route('/gnpslibrary/<library>.msp', methods=['GET']) def msp_download(library): return send_from_directory("/output", "{}.msp".format(library)) @app.route('/gnpslibrary/<library>.json', methods=['GET']) def json_download(library): return send_from_directory("/output", "{}.json".format(library)) npatlas_list = utils.load_NPAtlas("data/npatlas.json") mibig_list = utils.load_mibig("data/mibig.csv") gnps_list = utils.load_GNPS() gnps_list = utils.gnps_format_libraries(gnps_list)