old_contents: import os
  import argparse
  import subprocess
  
  from scripts.support.mirnas.update_mirnas_helpers import UPDATE_DIR, MEMORY, CPU, LSF_GROUP
  
  
  def check_in(rfam_acc):
      family_dir = os.path.join(UPDATE_DIR, rfam_acc)
      lsf_err_file = os.path.join(family_dir, "auto_rfci.err")
      lsf_out_file = os.path.join(family_dir, "auto_rfci.out")
      job_name = rfam_acc
      cmd = ("bsub -M {mem} -o {out_file} -e {err_file} -n {cpu} -g {lsf_group} -J {job_name} "
             "\"cd {update_dir} && rfci.pl -m 'Update using miRBase seed' {rfam_acc}\"")
      subprocess.call(
          cmd.format(
              mem=MEMORY, out_file=lsf_out_file, err_file=lsf_err_file, cpu=CPU, lsf_group=LSF_GROUP,
              job_name=job_name, update_dir=UPDATE_DIR, rfam_acc=rfam_acc), shell=True)
  
  
  def parse_arguments():
      parser = argparse.ArgumentParser()
      parser.add_argument("--input", help="list of families to check in", action="store")
  
      return parser.parse_args()
  
  
  if __name__ == '__main__':
      args = parse_arguments()
      families_to_check_in = args.input
      for family in families_to_check_in:
          check_in(family)
  
  
new_contents: import os
  import argparse
  import subprocess
  import time
  
  from scripts.support.mirnas.update_mirnas_helpers import UPDATE_DIR, MEMORY, CPU, LSF_GROUP
  
  
  def check_error_file(family):
      family_dir = os.path.join(UPDATE_DIR, family)
      err_file = os.path.join(family_dir, "auto_rfci.err")
      if "Filesystem has no item: '/trunk/Families/{0}/SEEDTBLOUT'".format(family) in err_file:
          os.chdir(family_dir)
          subprocess.call('svn add SEEDSCORES SEEDTBLOUT', shell=True)
          return True
  
      return False
  
  
  def check_successful(rfam_acc):
      family_dir = os.path.join(UPDATE_DIR, rfam_acc)
      lsf_err_file = os.path.join(family_dir, "auto_rfci.err")
  
      with open(lsf_err_file) as rqc_output:
          read_output = rqc_output.read()
          if "Successfully checked family in" in read_output:
              return True
  
      return False
  
  
  def check_in(rfam_acc):
      family_dir = os.path.join(UPDATE_DIR, rfam_acc)
      lsf_err_file = os.path.join(family_dir, "auto_rfci.err")
      lsf_out_file = os.path.join(family_dir, "auto_rfci.out")
      job_name = rfam_acc
      cmd = ("bsub -M {mem} -o {out_file} -e {err_file} -n {cpu} -g {lsf_group} -J {job_name} "
             "\"cd {update_dir} && rfci.pl -m \'Update using miRBase seed\' {rfam_acc}\"")
      subprocess.call(
          cmd.format(
              mem=MEMORY, out_file=lsf_out_file, err_file=lsf_err_file, cpu=CPU, lsf_group=LSF_GROUP,
              job_name=job_name, update_dir=UPDATE_DIR, rfam_acc=rfam_acc), shell=True)
  
  
  def check_in_all_families(families):
      checked_in = []
      not_checked_in = []
      with open(families) as infile:
          for family in infile:
              check_in(family.strip())
              time.sleep(120)
              if check_successful(family):
                  print('{0} has been checked in'.format(family))
                  checked_in.append(family)
              else:
                  svn_add = check_error_file(family)
                  if svn_add:
                      check_in(family)
                  else:
                      not_checked_in.append(family)
                      print('{0} HAS NOT been checked in. Please check manually {1}'.format(
                          family, os.path.join(UPDATE_DIR, family, "auto_rfci.err")))
  
      with open(os.path.join(UPDATE_DIR, 'checked_in.txt'), 'w') as outfile:
          for family in checked_in:
              outfile.write(family)
      with open(os.path.join(UPDATE_DIR, 'not_checked_in.txt'), 'w') as outfile:
          for family in not_checked_in:
              outfile.write(family)
      if len(not_checked_in) > 0:
          print('The following families could not be checked in and require manual intervention: {0}'.format(
              not_checked_in))
  
  
  def parse_arguments():
      parser = argparse.ArgumentParser()
      parser.add_argument("--input", help="list of families to check in/ passed QC", action="store")
  
      return parser.parse_args()
  
  
  if __name__ == '__main__':
      args = parse_arguments()
      check_in_all_families(args.input)
  
subject: Update auto_rfci.py