Skip to content
TheChatArchiveThe Chat Archive
Qwenqwen3-30b-a3b· Alibaba (Qwen)Hugging Face LMArena Human Preference 140K

I don't know what you just did, but it is NOT working correctly for the negative strand.

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash-preview-04-17’s answer.
  1. User

    I don't know what you just did, but it is NOT working correctly for the negative strand.

  2. Qwen Assistant

    You're absolutely right — the negative strand handling in the previous code was incorrect. The core issue is that the code was searching the reverse complement of the genome for the promoter, but this approach doesn't account for the correct mapping of positions and the uppercase letter.


    🔍 What Went Wrong

    The original logic:

    seq_to_search = str(Seq(genome_seq).reverse_complement())
    

    This creates a new string (reverse complement of the genome), then searches for the promoter in this string. This is not biologically correct. Instead, to find a match on the negative strand, you should:

    • Search the original genome for the reverse complement of the promoter, not the reverse complement of the genome.

    This is because:

    • The negative strand is the reverse complement of the positive strand.
    • So, to find a match on the negative strand, you should look for the reverse complement of the promoter in the original genome.

    ✅ Corrected Approach

    1. Positive Strand:
      Search the original genome for the promoter sequence.

    2. Negative Strand:
      Search the original genome for the reverse complement of the promoter.


    🧠 Why This Works

    • The reverse complement of the promoter is what would match the negative strand of the genome.
    • Once found, the start and end positions in the original genome are correct.
    • The uppercase letter position is calculated relative to the original promoter sequence, not the reverse complement.

    🛠️ Corrected Code

    Here’s the fixed version of the code with proper negative strand alignment:

    import pandas as pd
    from Bio import SeqIO
    from Bio.Seq import Seq
    import numpy as np
    
    # Assume `data` is already loaded as a NumPy array of coverage values
    
    # Load promoter data
    promoter_df = pd.read_csv("sigma70-promoters-filtered.csv", sep=";")
    record = SeqIO.read("sega007.gb", "genbank")
    genome_seq = str(record.seq).lower()  # Lowercase for matching
    genome_length = len(genome_seq)
    
    output_rows = []
    
    for idx, row in promoter_df.iterrows():
        name = row["promoter_name"]
        seq = row["promoter_sequence"]
    
        # Find uppercase letter position in the original promoter
        upper_idx = next((i for i, c in enumerate(seq) if c.isupper()), None)
        if upper_idx is None:
            print(f"No uppercase found in {name}. Skipping.")
            continue
    
        promoter_seq = seq.lower()
        promoter_len = len(promoter_seq)
    
        found = False
    
        # Try positive strand
        pos = genome_seq.find(promoter_seq)
        if pos != -1:
            start = pos
            end = pos + promoter_len - 1
            upper_pos = start + upper_idx
            try:
                start_cov = data[start]
                end_cov = data[end]
                up_cov = data[upper_pos]
                output_rows.append({
                    "promoter_name": name,
                    "promoter_sequence": seq,
                    "start_coverage": start_cov,
                    "end_coverage": end_cov,
                    "up_coverage": up_cov,
                    "strand": "+"
                })
                found = True
            except IndexError:
                print(f"Index error for {name} on + strand")
    
        # Try negative strand
        if not found:
            rev_complement_promoter = str(Seq(promoter_seq).reverse_complement())
            pos = genome_seq.find(rev_complement_promoter)
            if pos != -1:
                start = pos
                end = pos + promoter_len - 1
                upper_pos = start + (promoter_len - 1 - upper_idx)
                try:
                    start_cov = data[start]
                    end_cov = data[end]
                    up_cov = data[upper_pos]
                    output_rows.append({
                        "promoter_name": name,
                        "promoter_sequence": seq,
                        "start_coverage": start_cov,
                        "end_coverage": end_cov,
                        "up_coverage": up_cov,
                        "strand": "-"
                    })
                    found = True
                except IndexError:
                    print(f"Index error for {name} on - strand")
    
        if not found:
            print(f"Promoter {name} not found in genome.")
    
    # Save output
    output_df = pd.DataFrame(output_rows)
    output_df.to_csv("sigma70-promoter-diff.csv", sep=";", index=False)
    print("Done. Results saved to sigma70-promoter-diff.csv")
    

    ✅ Key Fixes

    IssueFix
    Negative strand logicSearch the original genome for the reverse complement of the promoter.
    Uppercase positionFor negative strand: upper_pos = start + (promoter_len - 1 - upper_idx)
    No need to reverse the genomeDirectly search the original genome for the reverse complement of the promoter.

    🧪 Example

    For a promoter like:

    spyp;acactttcattgttttaccgttgctctgattaattgacgctaaagtcagtaaagttaatcTcgtcaacacggcacgctact
    
    • The uppercase 'T' is at index 80 in the original sequence.
    • On the negative strand, we search for the reverse complement of the promoter.
    • If found, the upper_pos is calculated as:
      start + (promoter_len - 1 - upper_idx)

    ✅ Final Notes

    This version ensures:

    • Correct alignment on both strands.
    • Accurate mapping of the uppercase letter in the genome.
    • No off-by-one errors in position calculations.

    Let me know if you want to extend this to handle multiple matches or ambiguous hits.

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