예제 #1
0
def getGroupMap(groups,taxonomy):
    """
    Return map from all indicated taxids to True
    input may be a taxid, taxon name, or file listing taxids
    """
    if groups is None or len(groups)==0:
        return None
    taxidmap={}
    for group in groups:
        if os.path.isfile(group):
            taxidmap.update(parseListToMap(group,keyType=int))
        else:
            taxon = getTaxonFromArg(taxonomy, group)
            taxidmap.update( createTaxMap(taxon) )

    return taxidmap
예제 #2
0
def screenRecords(stream, separatorRE, idRE=None, keep=False, screenMap=None, screenFile=None):
    """
    uses recordIterator(strean, separatorRE, idRE) to parse input into records
    uses screenMap (can be read from screenFile) to identify records 
    identified records are kept or skipped based on the value of keep
    """

    if screenMap is None:
        if screenFile is None:
            raise Exception("Please supply a hash(Python map) or file of record keys")
        else:
            screenMap=parseListToMap(screenFile)

    for (recordId, recordLines) in recordIterator(stream,separatorRE,idRE=idRE):
        screened = recordId in screenMap
        if screened == keep:
            for line in recordLines:
                yield line