filter_ids.py 788 Bytes
import argparse
from os.path import isfile
#from volia.data_io import read_lst

import volia
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Filter ids of the given file to only keep a subset")
    parser.add_argument("file", type=str, help="")
    parser.add_argument("--filter", default=None, type=str, help="")
    parser.add_argument("--outfile", default="out.txt", type=str, help="")

    args = parser.parse_args()

    assert args.filter is not None
    assert isfile(args.file)

    list_ = read_lst(args.file)
    filter_ = read_lst(args.filter)
    
    with open(args.outfile, "w") as of:
        for key in filter_.keys():
            of.write(key + " " + " ".join(list_[key]) + "\n")
    
    print("File filtered and written in: ", args.outfile)