Beispiel #1
0
def main01():
    #config = Config(open(os.path.normpath('/Users/ivan/Documents/work/binning/tests/CowRumen/01/config.cfg')), 'pPPS')
    #config = Config(open(os.path.normpath('/net/metagenomics/projects/PPSmg/tests/V35/config.cfg')), 'pPPS')
    #configMl = Config2(config, 'MLTreeMap')
    #configPPS = Config2(config, 'PPS')

    #read sequences
    #sequences = Sequences(config)

    #write ids file
    #sequences.writeSequences(config.get('inputIdsFastaFile'))

    #taxonomy = Taxonomy(config.get('databaseFile'), config.get('taxonomicRanks').split(','))

    taxonomicRanks = 'superkingdom,phylum,class,order,family,genus,species'.split(',')
    taxonomy = Taxonomy('/Users/ivan/Documents/work/binning/taxonomy/20120828/ncbitax_sqlite.db', taxonomicRanks)

    #ppsOut2ppOut('D:\\VM\\tmp\\simMC_AMD\\AMD.Arachne.genus', 'D:\\VM\\tmp\\simMC_AMD\\AMD.Arachne.genus.PP.out', taxonomy, config.get('taxonomicRanks').split(','))

    #ppsOut2ppOut('/Users/ivan/Documents/work/binning/data/CowRumen/cowRumenOrderNcbids.txt',
    #             '/Users/ivan/Documents/work/binning/data/CowRumen/cowRumenOrderNcbids.PP.txt', taxonomy, config.get('taxonomicRanks').split(','))

    #ppsOut2ppOut('/net/metagenomics/projects/PPSmg/data/V35/contigsMappedBlast1000LabelsSpecies.txt',
    #             '/net/metagenomics/projects/PPSmg/data/V35/contigsMappedBlast1000LabelsSpecies.PP.txt', taxonomy, config.get('taxonomicRanks').split(','))

    ppsOut2ppOut('/Users/ivan/Documents/work/binning/data/simMC/fromJohannes/contigs.genus.tax',
                 '/Users/ivan/Documents/work/binning/data/simMC/fromJohannes/contigs.genus.PP.tax', taxonomy, taxonomicRanks)


    #readPPSOutput(sequences, taxonomy, config.get('inputIdsFastaFile'))

    #sequences.writePlacements(str(config.get('inputIdsFastaFile') + '.pOUT'), config.get('taxonomicRanks').split(','))

    #toRealNames(config, sequences)
    taxonomy.close()
Beispiel #2
0
def ppsOut2ppOut(inFile, outFile, taxonomicRanks, databaseFile):
    """
        Transforms a PPS output file into a file in the PP format.

        @param inFile: input file in the PPS format (first column: seq name, last column: ncbi taxon id)
        @param outFile: output file in the PP format
        @param taxonomicRanks: taxonomic ranks (starting from superkingdom)
        @param databaseFile: database file in the sqlite3 format
    """
    taxonomy = Taxonomy(databaseFile, taxonomicRanks)
    outBuff = csv.OutFileBuffer(outFile)
    namesList = csv.getColumnAsList(inFile,
                                    entryModifyFunction=None,
                                    colNum=0,
                                    sep='\t',
                                    comment='#')
    valCol = 1
    ncbidsList = csv.getColumnAsList(inFile,
                                     entryModifyFunction=None,
                                     colNum=valCol,
                                     sep='\t',
                                     comment='#')

    while True:  # this is not efficient!
        valCol += 1
        tmpList = csv.getColumnAsList(inFile,
                                      entryModifyFunction=None,
                                      colNum=valCol,
                                      sep='\t',
                                      comment='#')
        if len(tmpList) == len(namesList):
            ncbidsList = tmpList
        else:
            break

    header = str('#PPS file transformed to PP format, input file: ' +
                 str(inFile) + '\n#ID' + '\t' + 'root')
    for rank in taxonomicRanks:
        header += str('\t' + rank)
    outBuff.writeText(str(header + '\n'))

    for i in range(len(namesList)):
        name = namesList[i]
        ncbid = ncbidsList[i]
        taxPathDict = taxonomy.getPathToRoot(int(ncbid))
        buff = str(name)
        if taxPathDict is None:
            buff += str('\t')
        else:
            buff += str('\t' + 'root')

        for rank in taxonomicRanks:
            if (taxPathDict is not None) and (rank in taxPathDict) and (
                    not taxPathDict[rank].isCopy()):
                buff += str('\t' + taxPathDict[rank].name)
            else:
                buff += '\t'
        outBuff.writeText(str(buff + '\n'))
    outBuff.close()
    taxonomy.close()
Beispiel #3
0
def ppsOut2ppOut(inFile, outFile, taxonomicRanks, databaseFile):
    """
        Transforms a PPS output file into a file in the PP format.

        @param inFile: input file in the PPS format (first column: seq name, last column: ncbi taxon id)
        @param outFile: output file in the PP format
        @param taxonomicRanks: taxonomic ranks (starting from superkingdom)
        @param databaseFile: database file in the sqlite3 format
    """
    taxonomy = Taxonomy(databaseFile, taxonomicRanks)
    outBuff = csv.OutFileBuffer(outFile)
    namesList = csv.getColumnAsList(inFile, entryModifyFunction=None, colNum=0, sep='\t', comment='#')
    valCol = 1
    ncbidsList = csv.getColumnAsList(inFile, entryModifyFunction=None, colNum=valCol, sep='\t', comment='#')

    while True:  # this is not efficient!
        valCol += 1
        tmpList = csv.getColumnAsList(inFile, entryModifyFunction=None, colNum=valCol, sep='\t', comment='#')
        if len(tmpList) == len(namesList):
            ncbidsList = tmpList
        else:
            break

    header = str('#PPS file transformed to PP format, input file: ' + str(inFile) + '\n#ID' + '\t' + 'root')
    for rank in taxonomicRanks:
        header += str('\t' + rank)
    outBuff.writeText(str(header + '\n'))

    for i in range(len(namesList)):
        name = namesList[i]
        ncbid = ncbidsList[i]
        taxPathDict = taxonomy.getPathToRoot(int(ncbid))
        buff = str(name)
        if taxPathDict is None:
            buff += str('\t')
        else:
            buff += str('\t' + 'root')

        for rank in taxonomicRanks:
            if (taxPathDict is not None) and (rank in taxPathDict) and (not taxPathDict[rank].isCopy()):
                buff += str('\t' + taxPathDict[rank].name)
            else:
                buff += '\t'
        outBuff.writeText(str(buff + '\n'))
    outBuff.close()
    taxonomy.close()
Beispiel #4
0
def main01():
    #config = Config(open(os.path.normpath('/Users/ivan/Documents/work/binning/tests/CowRumen/01/config.cfg')), 'pPPS')
    #config = Config(open(os.path.normpath('/net/metagenomics/projects/PPSmg/tests/V35/config.cfg')), 'pPPS')
    #configMl = Config2(config, 'MLTreeMap')
    #configPPS = Config2(config, 'PPS')

    #read sequences
    #sequences = Sequences(config)

    #write ids file
    #sequences.writeSequences(config.get('inputIdsFastaFile'))

    #taxonomy = Taxonomy(config.get('databaseFile'), config.get('taxonomicRanks').split(','))

    taxonomicRanks = 'superkingdom,phylum,class,order,family,genus,species'.split(
        ',')
    taxonomy = Taxonomy(
        '/Users/ivan/Documents/work/binning/taxonomy/20120828/ncbitax_sqlite.db',
        taxonomicRanks)

    #ppsOut2ppOut('D:\\VM\\tmp\\simMC_AMD\\AMD.Arachne.genus', 'D:\\VM\\tmp\\simMC_AMD\\AMD.Arachne.genus.PP.out', taxonomy, config.get('taxonomicRanks').split(','))

    #ppsOut2ppOut('/Users/ivan/Documents/work/binning/data/CowRumen/cowRumenOrderNcbids.txt',
    #             '/Users/ivan/Documents/work/binning/data/CowRumen/cowRumenOrderNcbids.PP.txt', taxonomy, config.get('taxonomicRanks').split(','))

    #ppsOut2ppOut('/net/metagenomics/projects/PPSmg/data/V35/contigsMappedBlast1000LabelsSpecies.txt',
    #             '/net/metagenomics/projects/PPSmg/data/V35/contigsMappedBlast1000LabelsSpecies.PP.txt', taxonomy, config.get('taxonomicRanks').split(','))

    ppsOut2ppOut(
        '/Users/ivan/Documents/work/binning/data/simMC/fromJohannes/contigs.genus.tax',
        '/Users/ivan/Documents/work/binning/data/simMC/fromJohannes/contigs.genus.PP.tax',
        taxonomy, taxonomicRanks)

    #readPPSOutput(sequences, taxonomy, config.get('inputIdsFastaFile'))

    #sequences.writePlacements(str(config.get('inputIdsFastaFile') + '.pOUT'), config.get('taxonomicRanks').split(','))

    #toRealNames(config, sequences)
    taxonomy.close()