Skip to content
TheChatArchiveThe Chat Archive
Googlegemma-3-27b-it· GoogleHugging Face LMArena Human Preference 140K

Remove locus tag, extract /label of the gene instead

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-5-haiku-20241022’s answer.
  1. User

    Remove locus tag, extract /label of the gene instead

  2. Google Assistant

    Okay, here's the modified Python script that removes the locus_tag and extracts the /label qualifier of the gene instead. If a /label is not present, it will default to "N/A".

    from Bio import SeqIO
    import os
    
    # --- Configuration ---
    # Input GenBank file
    genbank_file = "sega007.gb"
    # Output TSV file
    output_tsv_file = "sega007_genes.tsv"
    # --- End Configuration ---
    
    # Check if the input file exists
    if not os.path.exists(genbank_file):
        print(f"Error: The input file '{genbank_file}' was not found.")
        exit()
    
    # Open the output file for writing
    with open(output_tsv_file, 'w') as f_out:
        # Write the header row for the TSV file
        header = "Gene_Label\tStart\tEnd\tStrand\n"
        f_out.write(header)
    
        # Parse the GenBank file
        for record in SeqIO.parse(genbank_file, "genbank"):
            print(f"Processing record: {record.id}")
    
            # Iterate through all the features in the record
            for feature in record.features:
                # We are only interested in features of type 'gene'
                if feature.type == 'gene':
                    # Extract information from the feature's qualifiers
                    gene_label = feature.qualifiers.get('label', ['N/A'])[0]
    
                    # Extract location information
                    start_pos = feature.location.start + 1
                    end_pos = feature.location.end
    
                    # Determine the strand
                    if feature.location.strand == 1:
                        strand = '+'
                    elif feature.location.strand == -1:
                        strand = '-'
                    else:
                        strand = 'N/A'
    
                    # Format the data as a tab-separated string and write to file
                    output_line = f"{gene_label}\t{start_pos}\t{end_pos}\t{strand}\n"
                    f_out.write(output_line)
    
    print(f"\nSuccess! Gene data has been exported to '{output_tsv_file}'")
    

    Key Changes:

    • Header: The header row in the TSV file is now Gene_Label\tStart\tEnd\tStrand.
    • gene_label = feature.qualifiers.get('label', ['N/A'])[0]: This line now retrieves the value associated with the label qualifier. If the label qualifier is not found, it defaults to "N/A".
    • Output Line: The output line now uses gene_label instead of locus_tag.

    How to Use:

    1. Save the script as export_genes.py.
    2. Make sure sega007.gb is in the same directory.
    3. Run the script from your terminal: python export_genes.py

    The resulting sega007_genes.tsv file will now contain the gene label (if available), start position, end position, and strand for each gene in your GenBank file. If a gene doesn't have a /label qualifier, "N/A" will be used in its place.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.