actg_coordinate.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. from falcon_kit.FastaReader import open_fasta_reader
  2. import sys
  3. def main(argv=sys.argv):
  4. p_ctg_coor_map = {}
  5. with open("p_ctg_tiling_path") as f:
  6. for row in f:
  7. row = row.strip().split()
  8. ctg_id, v, w, edge_rid, b, e = row[:6]
  9. if ctg_id not in p_ctg_coor_map:
  10. coor = 0 # the p_ctg_tiling_path should be sorted by contig the order of the edges in the tiling path
  11. p_ctg_coor_map[ctg_id] = {}
  12. p_ctg_coor_map[ctg_id][v] = 0
  13. coor += abs(int(b) - int(e))
  14. p_ctg_coor_map[ctg_id][w] = coor
  15. continue
  16. else:
  17. coor += abs(int(b) - int(e))
  18. p_ctg_coor_map[ctg_id][w] = coor
  19. with open_fasta_reader("a_ctg.fa") as a_ctg_fasta:
  20. for r in a_ctg_fasta:
  21. rid = r.name.split()
  22. rid, v, w = rid[:3]
  23. pid = rid.split("-")[0]
  24. print(rid, p_ctg_coor_map[pid][v], p_ctg_coor_map[pid][w])
  25. if __name__ == "__main__":
  26. main(sys.argv)