New command: obi export
This commit is contained in:
@ -1,107 +1,65 @@
|
|||||||
# from obitools3.apps.progress cimport ProgressBar # @UnresolvedImport
|
#cython: language_level=3
|
||||||
# from obitools3.dms.dms import OBIDMS # TODO cimport doesn't work
|
|
||||||
# from obitools3.utils cimport bytes2str
|
from obitools3.apps.progress cimport ProgressBar # @UnresolvedImport
|
||||||
#
|
from obitools3.uri.decode import open_uri
|
||||||
# import time
|
from obitools3.apps.config import logger
|
||||||
# import re
|
from obitools3.dms import DMS
|
||||||
#
|
from obitools3.dms.obiseq import Nuc_Seq
|
||||||
#
|
|
||||||
# __title__="Export a NUC_SEQS view to a fasta or fastq file"
|
from obitools3.apps.optiongroups import addMinimalInputOption, \
|
||||||
#
|
addExportOutputOption
|
||||||
#
|
|
||||||
# default_config = { 'inputview' : None,
|
|
||||||
# }
|
__title__="Export a view to a different file format"
|
||||||
#
|
|
||||||
# def addOptions(parser):
|
|
||||||
#
|
def addOptions(parser):
|
||||||
# # TODO put this common group somewhere else but I don't know where
|
|
||||||
# group=parser.add_argument_group('DMS and view options')
|
addMinimalInputOption(parser)
|
||||||
#
|
addExportOutputOption(parser)
|
||||||
# group.add_argument('--default-dms','-d',
|
|
||||||
# action="store", dest="obi:defaultdms",
|
|
||||||
# metavar='<DMS NAME>',
|
|
||||||
# default=None,
|
|
||||||
# type=str,
|
|
||||||
# help="Name of the default DMS for reading and writing data.")
|
|
||||||
#
|
|
||||||
# group.add_argument('--input-view','-i',
|
|
||||||
# action="store", dest="obi:inputview",
|
|
||||||
# metavar='<INPUT VIEW NAME>',
|
|
||||||
# default=None,
|
|
||||||
# type=str,
|
|
||||||
# help="Name of the input view, either raw if the view is in the default DMS,"
|
|
||||||
# " or in the form 'dms:view' if it is in another DMS.")
|
|
||||||
#
|
|
||||||
# group=parser.add_argument_group('obi export specific options')
|
|
||||||
#
|
|
||||||
# group.add_argument('--format','-f',
|
|
||||||
# action="store", dest="export:format",
|
|
||||||
# metavar='<FORMAT>',
|
|
||||||
# default="fasta",
|
|
||||||
# type=str,
|
|
||||||
# help="Export in the format <FORMAT>, 'fasta' or 'fastq'. Default: 'fasta'.") # TODO export in csv
|
|
||||||
#
|
|
||||||
def run(config):
|
def run(config):
|
||||||
pass
|
|
||||||
#
|
DMS.obi_atexit()
|
||||||
# # TODO import doesn't work
|
|
||||||
# NUC_SEQUENCE_COLUMN = "NUC_SEQ"
|
logger("info", "obi export : exports a view to a different file format")
|
||||||
# ID_COLUMN = "ID"
|
|
||||||
# DEFINITION_COLUMN = "DEFINITION"
|
# Open the input
|
||||||
# QUALITY_COLUMN = "QUALITY"
|
input = open_uri(config['obi']['inputURI'])
|
||||||
#
|
if input is None:
|
||||||
# special_columns = [NUC_SEQUENCE_COLUMN, ID_COLUMN, DEFINITION_COLUMN, QUALITY_COLUMN]
|
raise Exception("Could not read input")
|
||||||
#
|
iview = input[1]
|
||||||
# # Open DMS
|
|
||||||
# d = OBIDMS(config['obi']['defaultdms'])
|
# Open the output
|
||||||
#
|
output = open_uri(config['obi']['outputURI'],
|
||||||
# # Open input view
|
input=False)
|
||||||
# iview = d.open_view(config['obi']['inputview'])
|
if output is None:
|
||||||
#
|
raise Exception("Could not open output URI")
|
||||||
# print(iview.type)
|
|
||||||
#
|
output_object = output[0]
|
||||||
# # TODO check that the view has the type NUC_SEQS
|
writer = output[1]
|
||||||
# if ((config['export']['format'] == "fasta") or (config['export']['format'] == "fastq")) and (iview.type != "NUC_SEQS_VIEW") : # TODO find a way to import those macros
|
|
||||||
# raise Exception("Error: the view to export in fasta or fastq format is not a NUC_SEQS view")
|
# Check that the input view has the type NUC_SEQS if needed # TODO discuss, maybe bool property
|
||||||
#
|
if (output[2] == Nuc_Seq) and (iview.type != b"NUC_SEQS_VIEW") : # Nuc_Seq_Stored? TODO
|
||||||
# # Initialize the progress bar
|
raise Exception("Error: the view to export in fasta or fastq format is not a NUC_SEQS view")
|
||||||
# pb = ProgressBar(len(iview), config, seconde=5)
|
|
||||||
#
|
# Initialize the progress bar
|
||||||
# i=0
|
pb = ProgressBar(len(iview), config, seconde=5)
|
||||||
# for seq in iview :
|
|
||||||
# pb(i)
|
i=0
|
||||||
#
|
for seq in iview :
|
||||||
# toprint = ">"+seq.id+" "
|
pb(i)
|
||||||
#
|
try:
|
||||||
# for col_name in seq :
|
writer(seq)
|
||||||
# if col_name not in special_columns :
|
except StopIteration:
|
||||||
# toprint = toprint + col_name + "=" + str(seq[col_name]) + "; "
|
break
|
||||||
#
|
i+=1
|
||||||
# if DEFINITION_COLUMN in seq :
|
|
||||||
# toprint = toprint + seq.definition
|
# TODO save command in input dms?
|
||||||
#
|
|
||||||
# nucseq = bytes2str(seq.nuc_seq)
|
output_object.close()
|
||||||
#
|
iview.close()
|
||||||
# if config['export']['format'] == "fasta" :
|
input[0].close()
|
||||||
# nucseq = re.sub("(.{60})", "\\1\n", nucseq, 0, re.DOTALL)
|
|
||||||
#
|
logger("info", "obi export: Done")
|
||||||
# toprint = toprint + "\n" + nucseq
|
|
||||||
#
|
|
||||||
# if config['export']['format'] == "fastq" :
|
|
||||||
# toprint = toprint + "\n" + "+" + "\n" + seq.get_str_quality()
|
|
||||||
#
|
|
||||||
# print(toprint)
|
|
||||||
# i+=1
|
|
||||||
#
|
|
||||||
# iview.close()
|
|
||||||
# d.close()
|
|
||||||
#
|
|
||||||
# print("Done.")
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
Reference in New Issue
Block a user