Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3940564
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:26:02+00:00 2026-05-20T00:26:02+00:00

I have some problem with sequence generator. I have a file where each line

  • 0

I have some problem with sequence generator. I have a file where each line contain one fragment (8 letters). I load it from file in to list, where each element is one fragment. It is DNA so it should go that way:

1. Takes first 8-letter element
2. Check for element in which first 7 letters is the same as last 7 letters in first.
3. Add 8th letter from second element in to sequence.

It should look like this:

ATTGCCAT
 TTGCCATA
  TGCAATAC

So sequence: ATTGCCATAC

Unfortunately it only add one element. 🙁 First element is given (we knew it). I do it that way its first in file (first line).

Here is the code:

from os import sys
import random

def frag_get(seqfile):
    frags = []
    f_in = open(seqfile, "r")
    for i in f_in.readlines():
        frags.append(i.strip())
    f_in.close()
    return frags

def frag_list_shuffle(frags):
    random.shuffle(frags)
    return frags

def seq_build(first, frags):
    seq = first
    for f in frags:
        if seq[-7:] == f[:7]:
            seq += f[-1:]
    return seq

def errors():
    pass



if  __name__ == "__main__":
    frags = frag_get(sys.argv[1])
    first = frags[0]
    frags.remove(first)
    frags = frag_list_shuffle(frags)
    seq = seq_build(first, frags)
    check(sys.argv[2], seq)
    spectrum(sys.argv[2], sys.argv[3])

I have deleted check and spectrum functions because it’s simple calculations e.g. length comparison, so it is not what cause a problem as I think.

I will be very thankfully for help!

Regards,
Mateusz

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:26:03+00:00Added an answer on May 20, 2026 at 12:26 am

    Because your fragments are shuffled, your algorithm needs to take that into account; currently, you’re just looping through the fragments once, which is unlikely to include more than a few fragments if they’re not in the right order. For example, say you have 5 fragments, which I’m going to refer to by their order in your sequence. Now the fragments are slightly out of order:

    1 – 3 – 2 – 4 – 5

    Your algorithm will start with 1, skip 3, then match on 2, adding a base at the end. Then it’ll check against 4 and 5, and then finish, never reaching fragment 3.

    You could easily fix this by starting your loop again each time you add a base, however, this will scale very badly for a large number of bases. Instead, I’d recommend loading your fragments into a trie, and then searching the trie for the next fragment each time you add a base, until you’ve added one base for each fragment or you can no longer find a matching fragment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: We have a web app that calls some web services asynchronously (from the
I discovered to have some problem to fully understand callbacks scoping when trying to
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
So I have run up against this problem a few times: I have some
I have problem in some JavaScript that I am writing where the Switch statement
I've some CSS problem in Firefox 3. I have several image buttons on my
I have an intermittent problem with some code that writes to a Windows Event
I have run into a bit of a tricky problem in some C++ code,
I have problem when I try insert some data to Informix TEXT column via
I have a very strange problem. Under some elusive circumstances I fail to apply

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.