Thanks for the guidance. My question is why are you creating a second string (s1), and running the pattern and replacing in that string? I'm still working my way around understanding regex's.
Mark
User Profile
Collapse
-
String Replacement
Hello everyone, I've got a simple one today. I have a string and I want to remove all carriage returns ('\n') between the characters [ACGU] and [ACGU] and preserve the other ones. For example:
'Musmusculuslet-7gstem-loop\nCCAGGCUGA GGUAGUAGUUUGUAC AGUUUGAGGGUCUAU GAUACCACCCGGUAC AGGAGA\nUAACUGU ACAGGCCACUGCCUU GCCAGG\n
Musmusculuslet-7istem-loop\nCUGGCUGAG GUAGUAGUUUGUGCU GUUGGUCGGGUUGUG ACAUUGCCCGCUGUG GAGAUA\nACUGCGC AAGCUACUGCCUUGC UAG\n'... -
That has done the trick! Thanks for all of the help, I didn't even know about Python having a regex module. Still wondering why the triple quotes, but I will go to python.org and read up on it.
MarkLeave a comment:
-
I re-copied and re-pasted the code, and it is working much better now. The program is no longer splitting the keys, but it is pasting multiple values back-to-back instead of next to the key for multiple matches:
browser details MusmusculusmiR-450b1 AUUGGGAACAUUUUG CAUGCAU AUUGGGAACAUUUUG CAUGCAU 20 1 22 22 95.5% Un.003.104 - 440337 440358 22
browser details MusmusculusmiR-450b1 20 1 22 ...Leave a comment:
-
Okay, now I am getting a new error:
Traceback (most recent call last):
File "<pyshell#2 8>", line 1, in <module>
newfile = EditFile ( data, mouse )
File "BatchEditor.py ", line 45, in EditFile
patt = re.compile(r''' \bMusmusculusle t-[0-9a-z]+\b+|\bMusmuscu lusmiR-[0-9a-z\-]+\b''', re.VERBOSE)
File "C:\Python25\li b\re.py", line 180, in compile...Leave a comment:
-
The code I am currently using and still getting the same problem:
Code:def EditFile ( s1, dd ): print dd import re patt = re.compile(r'''\bMusmusculuslet-[0-9a-z]+\b+|\bMusmusculusmiR-[0-9a-z\-]+\b''', re.VERBOSE) strList = patt.findall(s1) s2 = s1 for item in strList: if dd.has_key(item): s2List = s2.split(' ')
Leave a comment:
-
I tried your suggestion but recieved the same result. Is there a statement I could write that checks each line for capital A,T,C, or G? If I could put that into an 'if' statement then maybe it wouldn't re-format a line that has already been formatted. Of course then there would be the problem of did it replace it with Mus..R-1, or with Mus..R-106a, etc. Is there an order, or is it random because I am using a dictionary?
MarkLeave a comment:
-
Thanks for the help ilikepython and bvdet. I'm running into only one problem. I am getting multiple matches for certain strings, e.g. the key
MusmusculusmiR-1 also matches with MusmusculusmiR-146b, so I get the following output:
browser details MusmusculusmiR-1 UGGAAUGUAAAGAAG UAUGUA46b UGAGAACUGAAUUCC AUAGGCU 22 1 22 22 100.0% 26 - 20924724 20924745 22
when the original string is:
...Leave a comment:
-
Iterating over a string
Hi everybody,
Does anyone know if the adict.has_key(k ) command can be used to match a string against a dictionary key? I'm trying to append a value from my dictionary to a string when it is found.
String example:
browser details Musmusculuslet-7g 21 1 21 21 100.0% 22 + 46884872 46884892 21
browser details Musmusculuslet-7i 21 1 21 21 100.0% 5 + 50605174... -
-
Thanks for the replies.
My thinking was that when there is no data left in the string I am reading (which I read in from a file), then start would equal -1.
The sample data I am working with is:
>Musmusculusl et-7g
UGAGGUAGUAGUUUG UACAGU
>Musmusculusl et-7i
UGAGGUAGUAGUUUG UGCUGU
>Musmusculusm iR-1
UGGAAUGUAAAGAAG UAUGUA
I also practiced by using this:
...Leave a comment:
-
string loop
Hello everyone,
I have a bit of code that I want to repeat for a string. I keep getting infinite while loops when I try it though. Any thoughts on where I am going wrong?
Thanks,
Mark
original code:
Code:tvshow = {} start = data.find( '>') end = data.find( '\n', start+1) firstname = data[start:end] start2 = data.find ( '\n', start) end2 = data.find(
-
Matching strings with a dictionary built from a flat file
Hello again,
I am still working on my same project and have run into another little problem. I have created a flat file with data from a server, each line looks like this:
BLAT Search Results
ACTIONS QUERY SCORE START END QSIZE IDENTITY CHRO STRAND START END SPAN
---------------------------------------------------------------------------------------------------
browser... -
-
Iterating over a file in python
Hello everyone, I wrote a post awhile ago about automating a local client to access a BLAT webserver, but today I have a much easier one. I want to take a batch file and delete every odd line. See below:
Sample File:
>Musmusculusm iR-344
UGAUCUAGCCAAAGC CUGACUGU
>Musmusculusm iR-345
UGCUGACCCCUAGUC CAGUGC
>Musmusculusm iR-346
UGUCUGCCCGAGUGC CUGCCUCU
>Musmusculusm iR-350
... -
I have also modified my code and tried to send as a cookie, but getting error messages. Here is the code:
Code:#!/usr/bin/env python # written 7/22/2007 # by Mark O'Connor import urllib import urllib2 import Cookie def ReadSite(): # First, encode the data. infile = open ('mouseguts1', 'r') data = infile.read()
Leave a comment:
-
Thanks for the help. I have dropped the cgi module, and I was playing with the urllib and have come up with the following code:
Code:#!/usr/bin/env python # written 7/22/2007 # by Mark O'Connor import urllib def ReadSite(): # First, encode the data. infile = open ('mouseguts1', 'r') data = infile.read() #print "Here is your
Leave a comment:
-
hello again, and thanks for the swift replies!
Actually I am studying at George Mason University in Virginia, but yes the website I am using is located in Santa Cruz. I'm studying for a Masters in Bioinformatics there. I originally had the url as:
url = "http://genome-test.cse.ucsc.e du/cgi-bin/hgBlat?command= start"
But then I tried some modifications with no success and yes, I have been leaving...Leave a comment:
-
urllib and urlleb2 modules in Python
Hello, I am attempting to write a Python module to access a website and upload batched files I have created, but I'm not getting it to work properly. I want to be able to upload my file, and then capture the reply in a simple text file within Python. Here is the code that I have, which so far just copies the content of the webpage. I am using Python version 2.5.
Code:#!/usr/bin/env python import urllib import
No activity results to display
Show More
Leave a comment: