[Tutor] Help

Abhishek Mishra ideamonk at gmail.com
Fri May 14 21:25:51 CEST 2010


Not sure if I understood the problem exactly, but you could linearize the
text by using something like this  --

>>> foo = '''ACTGTGTTC
... ACGTCGACC
... AVGTTTTTT
... ACGTTaGTC'''
>>> foo
'ACTGTGTTC\nACGTCGACC\nAVGTTTTTT\nACGTTaGTC'
>>> linear1 = ''.join(foo.split('\n'))
>>> linear1
'ACTGTGTTCACGTCGACCAVGTTTTTTACGTTaGTC'
>>>
>>> linear2 = foo.replace('\n','')
>>> linear2
'ACTGTGTTCACGTCGACCAVGTTTTTTACGTTaGTC'
>>>

>>> linear1 = ''.join(foo.split('\n'))
>>> linear2 = foo.replace('\n','')

^^ these are the two ways in which you can linearize the input text by
removing all  '\n'

after that you can grab 7th to 11th character like this -

>>> linear2[6:11]
'TTCAC'

^^ notice that the index is zero based, so 7th character actually 6 as its
index.

2010/5/14 she haohao <einstein_87 at hotmail.com>

>
>
> Hi,
>
>
> I am a beginner in python and I have a problem here and I hope someone can
> help me.
>
> Your help is greatly appreciated.
>
> Question.
>
> Say I have a .fa file and I want to print a subsequence from the file
> without the \n how can i do it.
>
> Example: Inside the test.fa file I have
>
> >chromosome 1
> ACTGTGTTC
> ACGTCGACC
> AVGTTTTTT
> ACGTTaGTC
>
> so if I say i wan the subsequence starting from the 7th character to the
> 11th(i.e when i let p=(7+11)/2=9 and v=2) character.(excluding the first
> line), mean I want TTCAC.
>
> So how should I write the code so that \n does not appear if i want p=10
> and v=3.
>
> Thanks for the help.
>
> Have a wonderful day ahead!
> Angeline
>
>
> ------------------------------
> Hotmail: Powerful Free email with security by Microsoft. Get it now.<https://signup.live.com/signup.+aspx?id=60969>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100515/bf48cfcf/attachment.html>


More information about the Tutor mailing list