Ask Your Question

magviana's profile - activity

2023-06-28 13:14:26 +0200 received badge  Notable Question (source)
2023-06-28 13:14:26 +0200 received badge  Popular Question (source)
2022-03-31 14:15:06 +0200 received badge  Popular Question (source)
2020-07-29 20:50:27 +0200 commented answer How to LaTeX the graph of a permutation?

It would be nice to be able to adapt it to specific representations such as

Permutation([3,1,2]).show(representation = "braid")
2020-07-26 22:29:28 +0200 commented answer How to remove EOL characters from imported literal strings?
2020-07-26 22:00:02 +0200 commented answer How to remove EOL characters from imported literal strings?

With your suggestion I can now work directly with DNA files in the FASTA format, of the form

>NC_014373.1 Bundibugyo ebolavirus, complete genome
GACACACAAAAAGAATGAAGGATTTTGAATCTTTATTGTGTGCGAGTA...

To extract its header use

def header(xseq):  
    with open(xseq, 'r') as f:
        s = f.read()
        print(Word(s.replace('\n',''))[1:s.index('\n')])

To remove the header and all subsequent newlines use

def fastaseq(xseq):  
    with open(xseq, 'r') as f:
        s = f.read()
        return Word(s.replace('\n',''))[s.index('\n')+1:len(s)]

Example:

header('ebola.fasta')

returns

 NC_014373.1 Bundibugyo ebolavirus, complete genome

and

  len(fastaseq('ebola.fasta'))

returns

18939
2020-07-26 00:54:54 +0200 asked a question How to remove EOL characters from imported literal strings?
seq=Word("TCAATAAAGCTTGCCTTGAGTGCTTCAAGTAGTGTGTGCCCGTCTGTTGTGTGACTCTGGTAACTAGAGA
TCCCTCAGACCCTTTTAGTCAGTGTGGAAAATCTCTAGCAGTGGCGCCCGAACAGGGACTTGAAAGCGAA
AGGGAAACCAGAGGAGCTCTCTCGACGCAGGACTCGGCTTGCTGAAGCGCGCACGGCAAGAGGCGAGGGG
AGGCGACTGGTGAGTACGCCAAAAATTTTGACTAGCGGAGGCTAGAAGGAGAGAGATGGGTGCGAGAGCG")

returns

File "<ipython-input-4-036a51caf660>", line 1
    seq=Word("TCAATAAAGCTTGCCTTGAGTGCTTCAAGTAGTGTGTGCCCGTCTGTTGTGTGACTCTGGTAACTAGAGA
                                                                                   ^
SyntaxError: EOL while scanning string literal

Of course one could remove the EOLs manually in this case, but when dealing with common DNA sequences this is hardly practical.

2020-07-26 00:03:27 +0200 commented answer How to LaTeX the graph of a permutation?

I implemented the graph of a permutation function amenable to TeX as:

def pgraph(perm):  
      return DiGraph([(i+1, perm[i]) for i in range(len(perm))], loops=True)
2020-07-25 23:58:06 +0200 received badge  Supporter (source)
2020-07-25 00:31:36 +0200 commented answer How to LaTeX the graph of a permutation?

Not specifically as the graphs are just for illustration in a larger text document, so I just cut/paste the LaTeX output. I implemented it as def pgraph(perm): ## permutation graph amenable to latex return DiGraph([(i+1, perm[i]) for i in range(len(perm))], loops=True)

2020-07-25 00:26:08 +0200 commented answer How to LaTeX the graph of a permutation?

Thanks --- I implemented the graph viewer as def pgraph(perm): ## permutation graph amenable to latex return DiGraph([(i+1, perm[i]) for i in range(len(perm))], loops=True)

2020-07-24 15:04:17 +0200 asked a question How to LaTeX the graph of a permutation?

Trying to LaTeX the graph generated by something like
Permutation([3,1,2]).show() The command latex(Permutation([3,1,2]).show())
returns the graph followed by \mathrm{None}

2020-07-23 00:29:40 +0200 commented question Why is Words('ab',50).random_element().count('aa') always incorrect ???

This query was motivated by implementing a counter for occurrences of words on a given or random symbolic sequence e.g. counting the occurrences of ACTs on a fixed or random DNA sequence. It is now implemented as

def fcount(factor,word):  
    return Word(word).parent()(Word(factor)).nb_factor_occurrences_in(Word(word))

so that

fcount('ACT','ACTTCATTTCCCTTCTTTACTTTCT') ## =2

which with the added function

def syse(sym,pos):
    return [w.string_rep() for w in FiniteWords(sym).iterate_by_length(pos)]

can generate all counts for that class, for example

table([(x,fcount(x,'yyyyyyuuuy')) for x in syse('yu',1)])

retuns

y   7
u   3

and

table([(x,fcount(x,'yyyyyyuuuy')) for x in syse('yu',2)])

returns

yy  5
yu  1
uy  1
uu  2
2020-07-21 09:43:27 +0200 received badge  Student (source)
2020-07-20 23:25:46 +0200 commented answer Why is Words('ab',50).random_element().count('aa') always incorrect ???

What prompted my query is the fact that Word('abbaabababbbb').count('ab') works as I expected, including when the word is an output of the form Words('ab', 20).random_element(). I only wanted to avoid the copy/paste of long random words into the former.

2020-07-14 19:10:27 +0200 asked a question Why is Words('ab',50).random_element().count('aa') always incorrect ???

On the other hand, Words('ab',50).random_element().count('a')
or Words('ab',50).random_element().count('b') are always correct, and so are