scripts/support/fasta2rfamseq.py
def create_rfamseq_metadata_for_genome_project(fasta_input, upid_list, upid_gca_tax_file):
    """
    This is the main function of the fasta2rfamseq script, which converts a
    fasta file to rfamseq table dumps (e.g. filename.rfamseq) for easy import
    to rfam_live upon release

    fasta_input: This can be a single fasta file or a genome project directory
    as orgnised by the genome download pipeline
    upid_list: This is a plain txt file listing all the upids in the genome
    project directory for which to generate the rfamseq files. It defaults to None,
    for single fasta files
    upid_gca_tax_file: This a json file mapping each upid to its corresponding
    taxid. In the case of Zasha or RNAcentral input, this will be a mapping of
    the sequence accession in the fasta file to its associated taxid
    
    return: void
    """

    fp = open(upid_gca_tax_file, 'r')
    upid_gca_tax_dict = json.load(fp)
    fp.close()

    if os.path.isfile(upid_list):
        project_dir = fasta_input
        fp = open(upid_list, 'r')
        upids = [x.strip() for x in fp]
        fp.close()

        for upid in upids:
            print upid
            subdir = os.path.join(project_dir, upid[-3:])
            updir = os.path.join(subdir, upid)
            upfasta = os.path.join(updir, upid+'.fa')

            # do some sanity checks
            if os.path.exists(upfasta):
                    # defining the source of the sequences according to assembly accession
                    source = "UNIPROT; ENA"
                    if upid in upid_gca_tax_dict:
                        if upid_gca_tax_dict[upid]["GCA"] != -1:
                            if upid_gca_tax_dict[upid]["GCA"][0:3] == "GCF":
                                source = "NIH; NCBI"
                            else:
                                source = "UNIPROT; ENA"
            else:
                print ("%s not in the current Uniprot release" % upid)
                continue

            extract_metadata_from_fasta(upfasta, upid_gca_tax_dict[upid]["TAX"],
                                        source, filename=None, to_file=True)

    else:
        project_dir = fasta_input
        upid = upid_list
        subdir = os.path.join(project_dir, upid[-3:])
        updir = os.path.join(subdir, upid)
        upfasta = os.path.join(updir, upid+'.fa')

        source = "UNIPROT; ENA"
        if upid in upid_gca_tax_dict:
            if upid_gca_tax_dict[upid]["GCA"] != -1:
                if upid_gca_tax_dict[upid]["GCA"][0:3] == "GCF":
                    source = "NIH; NCBI"
            else:
                source = "UNIPROT; ENA"
        else:
            print ("%s not in the current Uniprot release" % upid)
            sys.exit()

            extract_metadata_from_fasta(upfasta, upid_gca_tax_dict[upid]["TAX"],
                                        source, filename=None, to_file=True)

    This is the main function of the fasta2rfamseq script, which converts a
    fasta file to rfamseq table dumps (e.g. filename.rfamseq) for easy import
    to rfam_live upon release

    fasta_input: This can be a single fasta file or a genome project directory
    as orgnised by the genome download pipeline
    upid_list: This is a plain txt file listing all the upids in the genome
    project directory for which to generate the rfamseq files. It defaults to None,
    for single fasta files
    upid_gca_tax_file: This a json file mapping each upid to its corresponding
    taxid. In the case of Zasha or RNAcentral input, this will be a mapping of
    the sequence accession in the fasta file to its associated taxid
    
    return: void
    
This is the main function of the fasta2rfamseq script, which converts a
fasta file to rfamseq table dumps  for easy import
to rfam_live upon release

This can be a single fasta file or a genome project directory
as orgnised by the genome download pipeline
upid_list: This is a plain txt file listing all the upids in the genome
project directory for which to generate the rfamseq files. It defaults to None,
for single fasta files
upid_gca_tax_file: This a json file mapping each upid to its corresponding
taxid. In the case of Zasha or RNAcentral input, this will be a mapping of
the sequence accession in the fasta file to its associated taxid

void
This is the main function of the fasta2rfamseq script which converts a fasta file to rfamseq table dumps for easy import to rfam_live upon release This can be a single fasta file or a genome project directory as orgnised by the genome download pipeline upid_list : This is a plain txt file listing all the upids in the genome project directory for which to generate the rfamseq files . It defaults to None for single fasta files upid_gca_tax_file : This a json file mapping each upid to its corresponding taxid . In the case of Zasha or RNAcentral input this will be a mapping of the sequence accession in the fasta file to its associated taxid void
def create_rfamseq_metadata_for_genome_project(fasta_input, upid_list, upid_gca_tax_file):
    fp = open(upid_gca_tax_file, 'r')
    upid_gca_tax_dict = json.load(fp)
    fp.close()
    if os.path.isfile(upid_list):
        project_dir = fasta_input
        fp = open(upid_list, 'r')
        upids = [x.strip() for x in fp]
        fp.close()
        for upid in upids:
            print upid
            subdir = os.path.join(project_dir, upid[-3:])
            updir = os.path.join(subdir, upid)
            upfasta = os.path.join(updir, upid+'.fa')
            if os.path.exists(upfasta):
                    source = "UNIPROT; ENA"
                    if upid in upid_gca_tax_dict:
                        if upid_gca_tax_dict[upid]["GCA"] != -1:
                            if upid_gca_tax_dict[upid]["GCA"][0:3] == "GCF":
                                source = "NIH; NCBI"
                            else:
                                source = "UNIPROT; ENA"
            else:
                print ("%s not in the current Uniprot release" % upid)
                continue
            extract_metadata_from_fasta(upfasta, upid_gca_tax_dict[upid]["TAX"],
                                        source, filename=None, to_file=True)
    else:
        project_dir = fasta_input
        upid = upid_list
        subdir = os.path.join(project_dir, upid[-3:])
        updir = os.path.join(subdir, upid)
        upfasta = os.path.join(updir, upid+'.fa')
        source = "UNIPROT; ENA"
        if upid in upid_gca_tax_dict:
            if upid_gca_tax_dict[upid]["GCA"] != -1:
                if upid_gca_tax_dict[upid]["GCA"][0:3] == "GCF":
                    source = "NIH; NCBI"
            else:
                source = "UNIPROT; ENA"
        else:
            print ("%s not in the current Uniprot release" % upid)
            sys.exit()
            extract_metadata_from_fasta(upfasta, upid_gca_tax_dict[upid]["TAX"],
                                        source, filename=None, to_file=True)
def create_rfamseq_metadata_for_genome_project ( fasta_input , upid_list , upid_gca_tax_file ) : fp = open ( upid_gca_tax_file , 'r' ) upid_gca_tax_dict = json . load ( fp ) fp . close ( ) if os . path . isfile ( upid_list ) : project_dir = fasta_input fp = open ( upid_list , 'r' ) upids = [ x . strip ( ) for x in fp ] fp . close ( ) for upid in upids : print upid subdir = os . path . join ( project_dir , upid [ - 3 : ] ) updir = os . path . join ( subdir , upid ) upfasta = os . path . join ( updir , upid + '.fa' ) if os . path . exists ( upfasta ) : source = "UNIPROT; ENA" if upid in upid_gca_tax_dict : if upid_gca_tax_dict [ upid ] [ "GCA" ] != - 1 : if upid_gca_tax_dict [ upid ] [ "GCA" ] [ 0 : 3 ] == "GCF" : source = "NIH; NCBI" else : source = "UNIPROT; ENA" else : print ( "%s not in the current Uniprot release" % upid ) continue extract_metadata_from_fasta ( upfasta , upid_gca_tax_dict [ upid ] [ "TAX" ] , source , filename = None , to_file = True ) else : project_dir = fasta_input upid = upid_list subdir = os . path . join ( project_dir , upid [ - 3 : ] ) updir = os . path . join ( subdir , upid ) upfasta = os . path . join ( updir , upid + '.fa' ) source = "UNIPROT; ENA" if upid in upid_gca_tax_dict : if upid_gca_tax_dict [ upid ] [ "GCA" ] != - 1 : if upid_gca_tax_dict [ upid ] [ "GCA" ] [ 0 : 3 ] == "GCF" : source = "NIH; NCBI" else : source = "UNIPROT; ENA" else : print ( "%s not in the current Uniprot release" % upid ) sys . exit ( ) extract_metadata_from_fasta ( upfasta , upid_gca_tax_dict [ upid ] [ "TAX" ] , source , filename = None , to_file = True )
This is the main function of the fasta2rfamseq script, which converts a
fasta file to rfamseq table dumps (e.g.
This is the main function of the fasta2rfamseq script which converts a fasta file to rfamseq table dumps ( e . g .
"""
    This is the main function of the fasta2rfamseq script, which converts a
    fasta file to rfamseq table dumps (e.g. filename.rfamseq) for easy import
    to rfam_live upon release

    fasta_input: This can be a single fasta file or a genome project directory
    as orgnised by the genome download pipeline
    upid_list: This is a plain txt file listing all the upids in the genome
    project directory for which to generate the rfamseq files. It defaults to None,
    for single fasta files
    upid_gca_tax_file: This a json file mapping each upid to its corresponding
    taxid. In the case of Zasha or RNAcentral input, this will be a mapping of
    the sequence accession in the fasta file to its associated taxid
    
    return: void
    """ # do some sanity checks # defining the source of the sequences according to assembly accession
fasta_input
upid_list
upid_gca_tax_file