Created
          June 29, 2021 03:32 
        
      - 
      
- 
        Save yuifu/2623ee20d2b51de50d7d922ad3e65409 to your computer and use it in GitHub Desktop. 
    ushuffle python example
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # ref: https://github.com/guma44/ushuffle | |
| # ref: https://www.python.org/dev/peps/pep-3112/ | |
| # ref: https://pypi.org/project/ushuffle/ | |
| from ushuffle import shuffle, Shuffler, set_seed | |
| set_seed(12345) | |
| seq = bytes('ATTTTCTTTTTTTTTTA', 'ascii') | |
| # Note: '2' indicates that the shuffled sequence preserves 2-mer frequency | |
| print(shuffle(seq, 2)) | |
| # Repeat shuffling | |
| shuffler = Shuffler(seq, 2) | |
| for i in range(10): | |
| seqres = shuffler.shuffle() | |
| print("results:", seqres) | 
      
      
  Author
  
  
        
      
            yuifu
  
      
      
      commented 
        Jun 29, 2021 
      
    
  
>>> seq = bytes('KTTTTCTTTTTTTTTTA', 'ascii')
>>>
>>> # Note: '2' indicates that the shuffled sequence preserves 2-mer frequency
... print(shuffle(seq, 2))
b'KTTTTTTTTTTCTTTTA'
>>>
>>>
>>>
>>> # Repeat shuffling
... shuffler = Shuffler(seq, 2)
>>> for i in range(10):
...     seqres = shuffler.shuffle()
...     print("results:", seqres)
...
results: b'KTTTTTTTCTTTTTTTA'
results: b'KTTTTTTTTTTTCTTTA'
results: b'KTTTTTTTTTTTTCTTA'
results: b'KTTCTTTTTTTTTTTTA'
results: b'KTTTTTTTTTTTTCTTA'
results: b'KTTCTTTTTTTTTTTTA'
results: b'KTTTTTTTTTTTCTTTA'
results: b'KTTTTTTTTCTTTTTTA'
results: b'KTTTTTTTTTTTTTCTA'
results: b'KTTTTTTTTTTCTTTTA'
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment