annotate src/breadcrumbs/scripts/scriptConvertBetweenBIOMAndPCL.py @ 5:cb7b4786434d

Updated call to Micropita
author george-weingart
date Tue, 06 May 2014 17:20:23 -0400
parents d589875b8125
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
1 #!/usr/bin/env python
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
2 """
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
3 Author: Timothy Tickle
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
4 Description: Converts between BIOM and PCL files. If a PCL file is read, an equivalent BIOM file will be written; if a BIOM file is read, an equivalent pcl file will be written.
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
5 """
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
6
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
7 __author__ = "Timothy Tickle"
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
8 __copyright__ = "Copyright 2013"
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
9 __credits__ = ["Timothy Tickle","George Weingart"]
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
10 __license__ = ""
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
11 __version__ = ""
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
12 __maintainer__ = "Timothy Tickle"
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
13 __email__ = "ttickle@hsph.harvard.edu"
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
14 __status__ = "Development"
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
15
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
16 from AbundanceTable import AbundanceTable
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
17 import argparse
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
18 from ConstantsBreadCrumbs import ConstantsBreadCrumbs
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
19 import os
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
20 import sys
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
21
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
22
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
23 #Set up arguments reader
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
24 argp = argparse.ArgumentParser( prog = "convertBetweenBIOMAndPCL.py",
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
25 description = """Converts a PCL file to a BIOM file and visa versa.""" )
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
26
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
27 #Arguments
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
28 #For table
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
29 argp.add_argument("-i","--id", dest="sID", default = None, metavar= "Sample ID", help="The metadata indicating the sample ID.")
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
30 argp.add_argument("-l","--meta", dest = "sLastMetadataName", default = None, metavar= "Last Metadata Name", help="The last listed metadata before the first data measurement in the pcl file or to be in the pcl file.")
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
31 argp.add_argument("-r","--rowMetadataID", dest = "sLastMetadataRow", default = None, metavar = "Last Row Metadata Column", help = "If row metadata is present in a PCL file, what is the id of the last row metadata column (most right column that contains row metadata). PCL file only.")
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
32 argp.add_argument("-f","--delim", dest = "cFileDelimiter", action= "store", metavar="File Delimiter", default="\t", help="File delimiter, default tab")
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
33 argp.add_argument("strFileAbund", metavar = "Abundance file", help ="Input data file")
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
34 argp.add_argument("strOutputFile", default = "", nargs="?", metavar = "Selection Output File", help ="Output file")
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
35
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
36 args = argp.parse_args( )
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
37
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
38 # Make the output file name (if not given) and get the type of output file name
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
39 # Change the extension from BIOM to pcl
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
40 lsFilePieces = os.path.splitext(args.strFileAbund)
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
41 strOutputFileType = ConstantsBreadCrumbs.c_strPCLFile if lsFilePieces[-1]=="."+ConstantsBreadCrumbs.c_strBiomFile else ConstantsBreadCrumbs.c_strBiomFile
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
42
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
43 if not args.strOutputFile:
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
44 args.strOutputFile = lsFilePieces[0] + "." + strOutputFileType
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
45
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
46 # Set the last metadata to the id if not given.
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
47 if not args.sLastMetadataName:
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
48 args.sLastMetadataName = args.sID
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
49
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
50 # Read in abundance table
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
51 abndTable = AbundanceTable.funcMakeFromFile(args.strFileAbund, cDelimiter=args.cFileDelimiter, sMetadataID=args.sID, sLastMetadataRow = args.sLastMetadataRow, sLastMetadata=args.sLastMetadataName, xOutputFile=args.strOutputFile)
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
52 if not abndTable:
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
53 print("Could not create an abundance table from the given file and settings.")
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
54 else:
d589875b8125 First version of micropita in this repository
george-weingart
parents:
diff changeset
55 abndTable.funcWriteToFile(args.strOutputFile, cDelimiter=args.cFileDelimiter, cFileType=strOutputFileType)