[Biopython] shuffle sequences

Iddo Friedberg idoerg at gmail.com
Tue Jun 7 15:11:05 UTC 2011


probably a good solution wouls be to convert to  a list and then back to a
string (or a Seq object).

To shuffle w:
w="KVYGRCELAAAMKRHGLDKYQGYSLGNWVCAAKFE"
wl=list(w)
random.shuffle(wl)
w=''.join(wl)

And with a Seq object:
myseq=Seq('KVFGRCELAAAMKRHGL')
lms = list(myseq)
random.shuffle(lms)
myseq = Seq(''.join(lms))

On Tue, Jun 7, 2011 at 11:01 AM, George Devaniranjan <devaniranjan at gmail.com
> wrote:

> Hello João,
>
> Thanks for the answer but I am confused--"new sequence object with that"
> so I still need to create a seq object?
> I tried this ...
> myseq=Seq('KVFGRCELAAAMKRHGL', my_protein)
>
> I was thinking if it would be possible to have FOR loop and loop throught
> the entire sequence then shuffle it and then write the shuffled list (going
> though it one by one using another FOR loop) to a seq object.
>
> Thank you,
> George
>
> On Tue, Jun 7, 2011 at 10:46 AM, João Rodrigues <anaryin at gmail.com> wrote:
>
> > Hey George,
> >
> > random.shuffle works on lists or other datatypes that support item
> > assignment. Therefore, neither a string nor Seq will work. I would
> extract
> > the sequence out of Seq and build a new sequence object with that.
> >
> > Cheers,
> >
> > João [...] Rodrigues
> > http://nmr.chem.uu.nl/~joao
> >
> >
> >
> > On Tue, Jun 7, 2011 at 3:39 PM, George Devaniranjan <
> > devaniranjan at gmail.com> wrote:
> >
> >> Hello everyone,
> >> I need to 'shuffle' a sequence so that I can calculate the statistical
> >> alignment scores--I tried the random.shuffle opetion but it does not
> seem
> >> to
> >> work
> >>
> >> I defined the sequence as a string like the following
> >>
> >> w="KVYGRCELAAAMKRHGLDKYQGYSLGNWVCAAKFE"
> >> random.shuffle(w)
> >>
> >>
> >> also like this...
> >> my_protein=IUPAC.protein
> >> from Bio.Seq import Seq
> >> myseq=Seq('KVFGRCELAAAMKRHGL', my_protein)
> >>
> >> random.shuffle(myseq)
> >>
> >> Both don't seem to work--where am I going wrong?
> >>
> >> Thanks a lot,
> >> George
> >> _______________________________________________
> >> Biopython mailing list  -  Biopython at lists.open-bio.org
> >> http://lists.open-bio.org/mailman/listinfo/biopython
> >>
> >
> >
>
> _______________________________________________
> Biopython mailing list  -  Biopython at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biopython
>



-- 
Iddo Friedberg
http://iddo-friedberg.net/contact.html




More information about the Biopython mailing list