PYTHON   54
batch big 2 tabix import
Guest on 18th September 2023 12:13:09 PM


  1. #!/usr/bin/python
  2. # programmer : Daofeng
  3. # usage:
  4.  
  5. from batch_big_2_tabix import *
  6. import sys
  7. #chr     start   end     length  summit  tags    -10*log10(pvalue)       fold_enrichment FDR(%)
  8. #chr1    887607  888881  1275    940     110     89.97   4.17    88.94
  9. #chr1    968170  970743  2574    1243    256     291.17  5.1     100
  10. # peak
  11. #chr9    95326322        95326374        merge_4074-0_peak_1226  150     .       6.31835 15.07557        -1.00000        23
  12. #chr5    64735232        64735586        merge_4074-0_peak_894   108     .       6.25611 10.87670        -1.00000        169
  13.  
  14. def main():
  15.     inf = sys.argv[1]
  16.     outf = '{}.bed'.format(inf)
  17.     i = 0
  18.     try:
  19.         with open(inf,"rU") as infile:
  20.             next(infile)
  21.             with open(outf,'w') as outfile:
  22.                 for line in infile:
  23.                     i += 1
  24.                     t = line.strip().split('\t')
  25.                     #outfile.write('{0[0]}\t{0[1]}\t{0[2]}\tscorelst:[{0[5]},{0[6]},{0[7]},{0[8]}],id:{1},name:"{1}",sbstroke:[{0[4]}]\n'.format(t, i))
  26.                     #for peak
  27.                     outfile.write('{0[0]}\t{0[1]}\t{0[2]}\tscorelst:[{0[4]},{0[6]},{0[7]},{0[8]}],id:{1},name:"{0[3]}",sbstroke:[{0[9]}]\n'.format(t, i))
  28.     except IOError,message:
  29.         print >> sys.stderr, "cannot open file",message
  30.         sys.exit(1)
  31.  
  32.     toTabix(outf)
  33.  
  34. if __name__=="__main__":
  35.     main()

Raw Paste

Login or Register to edit or fork this paste. It's free.