Blame view

scripts/data-management/filter_ids.py 774 Bytes
ef2588651   Mathias   Filter the given ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  import argparse
  from os.path import isfile
  from volia.data_io import read_lst
  
  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]) + "
  ")
      
      print("File filtered and written in: ", args.outfile)