Mercurial > repos > recetox > ramclustr_define_experiment
comparison ramclustr_define_experiment_wrapper.py @ 0:42c2a25ff197 draft
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/ramclustr commit c321421a07bfdcc9ed423e9ed2ee794157984ba1
| author | recetox | 
|---|---|
| date | Wed, 29 Jun 2022 10:00:43 +0000 | 
| parents | |
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| -1:000000000000 | 0:42c2a25ff197 | 
|---|---|
| 1 import argparse | |
| 2 import csv | |
| 3 import sys | |
| 4 | |
| 5 | |
| 6 ARGUMENTS = { | |
| 7 "Experiment": {"help": "Experiment name, no spaces.", "type": str}, | |
| 8 "Species": {"help": "Genus species from which samples are derived.", "type": str}, | |
| 9 "Sample": {"help": "Type of sample (e.g., serum, leaf).", "type": str}, | |
| 10 "Contributer": {"help": "Your or your PI's name.", "type": str}, | |
| 11 "platform": {"help": "Either GC-MS or LC-MS.", "type": str}, | |
| 12 "chrominst": {"help": "Model of LC/GC instrument.", "type": str}, | |
| 13 "msinst": {"help": "Model of MS instrument.", "type": str}, | |
| 14 "column": {"help": "Column description.", "type": str}, | |
| 15 "InletTemp": {"help": "Temperature of inlet.", "type": str}, | |
| 16 "TransferTemp": {"help": "Temperature of GC to MS transfer line.", "type": str}, | |
| 17 "mstype": {"help": "Type of mass spectrometer (one of QQQ, TOF, QTOF, Orbi, Q).", "type": str}, | |
| 18 "msmode": {"help": "Positive or negative ion mode.", "type": str}, | |
| 19 "ionization": {"help": "Ionization (EI, AP, or CI).", "type": str}, | |
| 20 "msscanrange": {"help": "Scan range used for acquisition.", "type": str}, | |
| 21 "scantime": {"help": "Time for each full scan spectrum (e.g. 0.2 seconds).", "type": float}, | |
| 22 "deriv": {"help": "Derivitization (TMS, TBDMS, or None).", "type": str}, | |
| 23 "MSlevs": {"help": "Number of levels of energy acquired - 1 typically.", "type": float}, | |
| 24 "solvA": {"help": "Solvent A composition.", "type": str}, | |
| 25 "solvB": {"help": "Solvent B composition.", "type": str}, | |
| 26 "CE1": {"help": "Collision energy of acquisition of MS data.", "type": str}, | |
| 27 "CE2": {"help": "Collision energy of acquisition for MSe/idMSMS data (when applicable).", "type": str}, | |
| 28 "colgas": {"help": "Gas used for collisional dissociation.", "type": str}, | |
| 29 "conevol": {"help": "Cone voltage used for acquisition.", "type": str} | |
| 30 } | |
| 31 | |
| 32 | |
| 33 def get_value(args, value, fill=True): | |
| 34 if fill: | |
| 35 return args[value] | |
| 36 return "fill" | |
| 37 | |
| 38 | |
| 39 def write_gcms(csv_writer, args, fill=True): | |
| 40 csv_writer.writerow(["", "", ""]) | |
| 41 csv_writer.writerow(["GC-MS", "", ""]) | |
| 42 | |
| 43 gcms = ["chrominst", "msinst", "column", "InletTemp", "TransferTemp", "mstype", "msmode", "ionization", | |
| 44 "msscanrange", "scantime", "deriv", "MSlevs"] | |
| 45 for arg in gcms: | |
| 46 csv_writer.writerow([arg, get_value(args, arg, fill=fill), ARGUMENTS[arg]["help"]]) | |
| 47 | |
| 48 | |
| 49 def write_lcms(csv_writer, args, fill=True): | |
| 50 csv_writer.writerow(["", "", ""]) | |
| 51 csv_writer.writerow(["LC-MS", "", ""]) | |
| 52 | |
| 53 lcms = ["chrominst", "msinst", "column", "solvA", "solvB", "CE1", "CE2", "mstype", "msmode", "ionization", "colgas", | |
| 54 "msscanrange", "conevol", "MSlevs"] | |
| 55 for arg in lcms: | |
| 56 csv_writer.writerow([arg, get_value(args, arg, fill=fill), ARGUMENTS[arg]["help"]]) | |
| 57 | |
| 58 | |
| 59 def main(argv): | |
| 60 parser = argparse.ArgumentParser(description="RAMClustR define experiment.") | |
| 61 | |
| 62 for arg in ARGUMENTS.keys(): | |
| 63 parser.add_argument(f"--{arg}", type=ARGUMENTS[arg]["type"], help=ARGUMENTS[arg]["help"]) | |
| 64 | |
| 65 parser.add_argument("--output_file", type=str, help="Path to output csv file.") | |
| 66 args = vars(parser.parse_args()) | |
| 67 | |
| 68 with open(args["output_file"], "w") as csvfile: | |
| 69 csv_writer = csv.writer(csvfile, delimiter=',') | |
| 70 | |
| 71 csv_writer.writerow(["parameter", "Value", "Description"]) | |
| 72 csv_writer.writerow(["", "", ""]) | |
| 73 csv_writer.writerow(["Experimental Design", "", ""]) | |
| 74 | |
| 75 general = ["Experiment", "Species", "Sample", "Contributer", "platform"] | |
| 76 for arg in general: | |
| 77 csv_writer.writerow([arg, args[arg], ARGUMENTS[arg]["help"]]) | |
| 78 | |
| 79 if args["platform"] == "GC-MS": | |
| 80 write_gcms(csv_writer, args) | |
| 81 write_lcms(csv_writer, args, fill=False) | |
| 82 elif args["platform"] == "LC-MS": | |
| 83 write_gcms(csv_writer, args, fill=False) | |
| 84 write_lcms(csv_writer, args) | |
| 85 else: | |
| 86 raise ValueError("Platform value incorrect, choose either GC-MS or LC-MS.") | |
| 87 | |
| 88 | |
| 89 if __name__ == "__main__": | |
| 90 main(argv=sys.argv[1:]) | 
