Blame view

volia/filter_ids.py 788 Bytes
ef2588651   Mathias   Filter the given ...
1
2
  import argparse
  from os.path import isfile
e7d811503   Quillot Mathias   New file architec...
3
  #from volia.data_io import read_lst
ef2588651   Mathias   Filter the given ...
4

e7d811503   Quillot Mathias   New file architec...
5
  import volia
ef2588651   Mathias   Filter the given ...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  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)