@transform( (runNubiscanVDR, runNubiscanNR),
            suffix( ".nubiscan.rxrvdr" ),
            "_nubiscan.import" )
def importNubiscan( infile, outfile ):

    tablename = outfile[:-len(".import")]
    track = tablename[:-len("_nubiscan")]

    tmpfile = P.getTempFile()
    first = True

    for line in fileinput.input( glob.glob("%s.nubiscan.*" % (track))):
        if fileinput.filename().endswith(".log"):
            fileinput.nextfile()
            continue

        if line.startswith("#"): continue

        if re.match("id\t", line):

            base, motif = os.path.splitext(fileinput.filename())

            if motif == ".shuffled":
                base, motif = os.path.splitext(base)
                motif += "_shuffled"
            elif motif == ".shifted":
                base, motif = os.path.splitext(base)
                motif += "_shifted"

            motif = motif[1:]

            if first:
                tmpfile.write("motif\t%s" % line )
                first = False
            continue

        line = re.sub( "run\S+_", "", line)
        # patch for fixing ids
        data = line.split("\t")
        data[0] = re.sub(" ", "", data[0])
        line = "\t".join(data)

        tmpfile.write("%s\t%s" % (motif, line))
    tmpfile.close()
    tmpfilename = tmpfile.name

    statement = '''
   python %(scriptsdir)s/csv2db.py %(csv2db_options)s \
    --allow-empty \
    -b sqlite \
    --index=id \
    --index=motif \
    --index=id,motif \
    --table=%(tablename)s \
    < %(tmpfilename)s > %(outfile)s
    '''

    P.run( **dict( locals().items() + PARAMS.items() ) )

    os.unlink( tmpfilename )

############################################################
############################################################
############################################################
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_vitaminD.py/importNubiscan/original