This demonstrates a regex pattern that may help with replacements:
$ echo "foo;bar:baz,bing\$beep*bop;bloop" | sed -e 's/[;|:|,]/_/g'
foo_bar_baz_bing$beep*bop_bloop
That [;|:|,]
is a pattern specifying matches on those characters. The underscore character is what sed
replaces them with when there is a match, or "hit". The g
specifier does a global replacement, where there are multiple hits. Without it, sed
will replace the first hit and leave the rest untouched, e.g., see the following result and compare it with the first result:
$ echo "foo;bar:baz,bing\$beep*bop;bloop" | sed -e 's/[;|:|,]/_/'
foo_bar:baz,bing$beep*bop;bloop
If you are using Python, take a look at the re
library:
>>> import re
>>> str = "foo;bar:baz,bing\$beep*bop;bloop"
>>> re.sub('[;|:|,]', '_', str)
'foo_bar_baz_bing$beep*bop_bloop'
Thanks Alex much appreciated
Could use this to look at an entire directory as well? @Alex or am I not understanding how to use the sed command?
Perhaps combine a
for
loop withwalk
, to loop over all files in a directory: https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directoryInside the loop, you could perhaps run a function to modify the alignments:
subprocess.check_call
in Python).with open("reads.sam", "r") as in, open("readsModified.sam", "w") as out:
etc.).readsModified.sam
file.The biostars search engine can help with how to convert BAM->SAM and back again. Stack Overflow and the answer above for the rest.