scripts/export/rfam_svn_file_export.py
def export_rfam_family_files(f_types, out_dir):
    """
    Fetches all Rfam family accessions from rfam_live, checks out each
    family and copies the files in f_types in their corresponding
    directories

    f_types: A list of file type keywords we need to
             export (e.g. ["SEED", "CM"])
    out_dir: The path to the output directory. If it does not exist it will
             be created
    """

    # Create the output directory if it does not exist
    if (not os.path.exists(out_dir)):
        os.mkdir(out_dir)

    # if current working directory isn't out_dir, change directory
    if (string.find(os.getcwd(), out_dir) == -1):
        os.chdir(out_dir)

    # generate specific output directories for each file type
    file_path = ''
    for f_type in f_types:
        file_path = os.path.join(out_dir, f_type)
        if (not os.path.exists(file_path)):
            os.mkdir(file_path)
        file_path = ''

    # get DB connection handle
    cnx = RfamDB.connect()

    # get mysql cursor
    cursor = cnx.cursor(buffered=True)

    # execute query
    cursor.execute("SELECT rfam_acc FROM family")

    cmd = ''

    # fetch files for all Rfam family accessions
    for rfam_acc in cursor:

        rfam_acc = str(rfam_acc[0])
        cmd = SVN_CHECKOUT % rfam_acc

        # Check out family in out_dir using rfco on lsf
        subprocess.call(cmd, shell=True)

        # path to
        fam_dir = os.path.join(out_dir, rfam_acc)

        # copy files and rename
        for f_type in f_types:
            filename = rfam_acc + '.' + f_type.lower()
            """
            if (f_type == "SEED"):
                # 1. open out file handler
                seed_out_fp = open(
                    os.path.join(os.path.join(out_dir, f_type), filename), 'w')
                # 2. open desc handler
                desc_fp = open(os.path.join(fam_dir, "DESC"), 'r')
                # 3. write desc to outfile
                seed_out_fp.writelines(desc_fp.readlines())
                seed_out_fp.write('\n')
                desc_fp.close()
                # 4. open seed and write in outfile

                continue
            """
            shutil.copyfile(os.path.join(fam_dir, f_type),
                            os.path.join(os.path.join(out_dir, f_type), filename))

        # delete family dir
        shutil.rmtree(fam_dir)

        filename = ''
        fam_dir = ''
        cmd = ''

    # close DB connection
    cursor.close()
    RfamDB.disconnect(cnx)

    Fetches all Rfam family accessions from rfam_live, checks out each
    family and copies the files in f_types in their corresponding
    directories

    f_types: A list of file type keywords we need to
             export (e.g. ["SEED", "CM"])
    out_dir: The path to the output directory. If it does not exist it will
             be created
    
Fetches all Rfam family accessions from rfam_live, checks out each
family and copies the files in f_types in their corresponding
directories

A list of file type keywords we need to
export
out_dir: The path to the output directory. If it does not exist it will
be created
Fetches all Rfam family accessions from rfam_live checks out each family and copies the files in f_types in their corresponding directories A list of file type keywords we need to export out_dir : The path to the output directory . If it does not exist it will be created
def export_rfam_family_files(f_types, out_dir):
    if (not os.path.exists(out_dir)):
        os.mkdir(out_dir)
    if (string.find(os.getcwd(), out_dir) == -1):
        os.chdir(out_dir)
    file_path = ''
    for f_type in f_types:
        file_path = os.path.join(out_dir, f_type)
        if (not os.path.exists(file_path)):
            os.mkdir(file_path)
        file_path = ''
    cnx = RfamDB.connect()
    cursor = cnx.cursor(buffered=True)
    cursor.execute("SELECT rfam_acc FROM family")
    cmd = ''
    for rfam_acc in cursor:
        rfam_acc = str(rfam_acc[0])
        cmd = SVN_CHECKOUT % rfam_acc
        subprocess.call(cmd, shell=True)
        fam_dir = os.path.join(out_dir, rfam_acc)
        for f_type in f_types:
            filename = rfam_acc + '.' + f_type.lower()
            shutil.copyfile(os.path.join(fam_dir, f_type),
                            os.path.join(os.path.join(out_dir, f_type), filename))
        shutil.rmtree(fam_dir)
        filename = ''
        fam_dir = ''
        cmd = ''
    cursor.close()
    RfamDB.disconnect(cnx)
def export_rfam_family_files ( f_types , out_dir ) : if ( not os . path . exists ( out_dir ) ) : os . mkdir ( out_dir ) if ( string . find ( os . getcwd ( ) , out_dir ) == - 1 ) : os . chdir ( out_dir ) file_path = '' for f_type in f_types : file_path = os . path . join ( out_dir , f_type ) if ( not os . path . exists ( file_path ) ) : os . mkdir ( file_path ) file_path = '' cnx = RfamDB . connect ( ) cursor = cnx . cursor ( buffered = True ) cursor . execute ( "SELECT rfam_acc FROM family" ) cmd = '' for rfam_acc in cursor : rfam_acc = str ( rfam_acc [ 0 ] ) cmd = SVN_CHECKOUT % rfam_acc subprocess . call ( cmd , shell = True ) fam_dir = os . path . join ( out_dir , rfam_acc ) for f_type in f_types : filename = rfam_acc + '.' + f_type . lower ( ) """
            if (f_type == "SEED"):
                # 1. open out file handler
                seed_out_fp = open(
                    os.path.join(os.path.join(out_dir, f_type), filename), 'w')
                # 2. open desc handler
                desc_fp = open(os.path.join(fam_dir, "DESC"), 'r')
                # 3. write desc to outfile
                seed_out_fp.writelines(desc_fp.readlines())
                seed_out_fp.write('\n')
                desc_fp.close()
                # 4. open seed and write in outfile

                continue
            """ shutil . copyfile ( os . path . join ( fam_dir , f_type ) , os . path . join ( os . path . join ( out_dir , f_type ) , filename ) ) shutil . rmtree ( fam_dir ) filename = '' fam_dir = '' cmd = '' cursor . close ( ) RfamDB . disconnect ( cnx )
Fetches all Rfam family accessions from rfam_live, checks out each
family and copies the files in f_types in their corresponding
directories
Fetches all Rfam family accessions from rfam_live checks out each family and copies the files in f_types in their corresponding directories
"""
    Fetches all Rfam family accessions from rfam_live, checks out each
    family and copies the files in f_types in their corresponding
    directories

    f_types: A list of file type keywords we need to
             export (e.g. ["SEED", "CM"])
    out_dir: The path to the output directory. If it does not exist it will
             be created
    """ # Create the output directory if it does not exist # if current working directory isn't out_dir, change directory # generate specific output directories for each file type # get DB connection handle # get mysql cursor # execute query # fetch files for all Rfam family accessions # Check out family in out_dir using rfco on lsf # path to # copy files and rename """
            if (f_type == "SEED"):
                # 1. open out file handler
                seed_out_fp = open(
                    os.path.join(os.path.join(out_dir, f_type), filename), 'w')
                # 2. open desc handler
                desc_fp = open(os.path.join(fam_dir, "DESC"), 'r')
                # 3. write desc to outfile
                seed_out_fp.writelines(desc_fp.readlines())
                seed_out_fp.write('\n')
                desc_fp.close()
                # 4. open seed and write in outfile

                continue
            """ # delete family dir # close DB connection
f_types
out_dir