args = parser.parse_args()


     if args.infile:
          asf = HiriseAssembly()
          asf.load_assembly(args.infile)


#     asf = HiriseAssembly()
#     asf.load_playout(args.infile)

     breaks=[]
     scores={}
     for l in open(args.breaks):
          if l[0]=="#": continue
#Scaffold102239 741 1379 5097 -5.421961663655971
          scaffold,a,b,slen,score = l.strip().split()
          a=int(a) #start
          b=int(b) #end
#          c=int(c) #lowpoint
          score=float(score)
          c=int((a+b)/2)
          breaks.append((scaffold,a,b,c))
          scores[scaffold,a,b,c]=score

#     asf.add_breakpoints_ranges(breaks,debug=args.debug,scores=scores)
     asf.add_breakpoints_ranges(breaks,debug=args.debug)
     asf.validate()

     if args.outfile: asf.save_assembly( args.outfile )
          for tf,header in tfs_headers:
               orgfile.write("""* Break {label}

\\includegraphics[width=70em]{{{pdffile}}}


""".format(pdffile=tf,label=header).encode())
          orgfile.flush()
          
          cmd = "emacs {} --batch -f org-export-as-pdf  --kill ".format(orgfile.name)
          print(cmd)
          output,error = subprocess.Popen(shlex.split(cmd),stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr = subprocess.PIPE).communicate()
          if args.debug:
               print(output)
               print(error)

          of=re.sub(".org",".pdf",orgfile.name)
          cmd = "mv {} {}".format(of,args.report)
          output,error = subprocess.Popen(shlex.split(cmd),stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr = subprocess.PIPE).communicate()
          if args.debug:
               print(output)
               print(error)
          

     if args.outfile:
          asf.add_breakpoints_ranges(breaks,debug=args.debug,scores=scores,unlink_threshold=args.threshold, contig_break_threshold=args.contig_break_threshold,score_types=stype)
          asf.validate()
          asf.dump_layout( open(args.outfile,"wt") )