In [1]:
"Hello, world"
Out[1]:
'Hello, world'
In [2]:
print("Hello, world")
Hello, world
In [3]:
%pwd
Out[3]:
'/home/explorer/BMS270/Notebooks'
In [4]:
%cd ~/BMS270/data/
/home/explorer/BMS270/data
In [5]:
%ls
sample_table.csv  SRR7541452.6M.fastq.gz
In [6]:
!ls
sample_table.csv  SRR7541452.6M.fastq.gz
In [8]:
!head -c 64 sample_table.csv | hexdump -C
00000000  52 75 6e 2c 64 65 73 63  2c 63 6f 6e 64 69 74 69  |Run,desc,conditi|
00000010  6f 6e 2c 6d 75 63 6f 72  2c 62 61 74 63 68 2c 72  |on,mucor,batch,r|
00000020  65 70 0a 53 52 52 37 35  34 31 34 33 35 2c 22 4d  |ep.SRR7541435,"M|
00000030  75 63 6f 72 20 61 74 66  31 20 6d 75 74 61 6e 74  |ucor atf1 mutant|
00000040
In [9]:
!head -c 64 SRR7541452.6M.fastq.gz | hexdump -C
00000000  1f 8b 08 00 c9 cc aa 5c  00 03 ac fd db ae ec b8  |.......\........|
00000010  12 2d 88 bd 9f af 68 e0  3c 36 ec 12 75 57 22 37  |.-....h.<6..uW"7|
00000020  52 9c 94 44 25 0c ec 87  b6 60 f7 0f 34 ec 07 c3  |R..D%....`..4...|
00000030  4f fe 7f 98 11 23 a8 4c  86 72 4a b3 92 3d ab 6a  |O....#.L.rJ..=.j|
00000040
In [10]:
import gzip
In [11]:
fp = gzip.open("SRR7541452.6M.fastq.gz")
In [12]:
fp 
Out[12]:
<gzip _io.BufferedReader name='SRR7541452.6M.fastq.gz' 0x7f6a3c3aff28>
In [13]:
fp2 = fp
In [14]:
fp2
Out[14]:
<gzip _io.BufferedReader name='SRR7541452.6M.fastq.gz' 0x7f6a3c3aff28>
In [15]:
fp.close()
In [16]:
fp = gzip.open("SRR7541452.6M.fastq.gz","rt")
In [17]:
fp
Out[17]:
<_io.TextIOWrapper name='SRR7541452.6M.fastq.gz' encoding='UTF-8'>
In [18]:
fp.readline()
Out[18]:
'@SRR7541452.22752346 HWI-D00148:479:HVK5NBCXX:2:2105:2570:87783 length=51\n'
In [19]:
dir(fp)
Out[19]:
['_CHUNK_SIZE',
 '__class__',
 '__del__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__enter__',
 '__eq__',
 '__exit__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getstate__',
 '__gt__',
 '__hash__',
 '__init__',
 '__iter__',
 '__le__',
 '__lt__',
 '__ne__',
 '__new__',
 '__next__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '_checkClosed',
 '_checkReadable',
 '_checkSeekable',
 '_checkWritable',
 '_finalizing',
 'buffer',
 'close',
 'closed',
 'detach',
 'encoding',
 'errors',
 'fileno',
 'flush',
 'isatty',
 'line_buffering',
 'name',
 'newlines',
 'read',
 'readable',
 'readline',
 'readlines',
 'seek',
 'seekable',
 'tell',
 'truncate',
 'writable',
 'write',
 'writelines']
In [20]:
help(fp)
Help on TextIOWrapper object:

class TextIOWrapper(_TextIOBase)
 |  Character and line based layer over a BufferedIOBase object, buffer.
 |  
 |  encoding gives the name of the encoding that the stream will be
 |  decoded or encoded with. It defaults to locale.getpreferredencoding(False).
 |  
 |  errors determines the strictness of encoding and decoding (see
 |  help(codecs.Codec) or the documentation for codecs.register) and
 |  defaults to "strict".
 |  
 |  newline controls how line endings are handled. It can be None, '',
 |  '\n', '\r', and '\r\n'.  It works as follows:
 |  
 |  * On input, if newline is None, universal newlines mode is
 |    enabled. Lines in the input can end in '\n', '\r', or '\r\n', and
 |    these are translated into '\n' before being returned to the
 |    caller. If it is '', universal newline mode is enabled, but line
 |    endings are returned to the caller untranslated. If it has any of
 |    the other legal values, input lines are only terminated by the given
 |    string, and the line ending is returned to the caller untranslated.
 |  
 |  * On output, if newline is None, any '\n' characters written are
 |    translated to the system default line separator, os.linesep. If
 |    newline is '' or '\n', no translation takes place. If newline is any
 |    of the other legal values, any '\n' characters written are translated
 |    to the given string.
 |  
 |  If line_buffering is True, a call to flush is implied when a call to
 |  write contains a newline character.
 |  
 |  Method resolution order:
 |      TextIOWrapper
 |      _TextIOBase
 |      _IOBase
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  __getstate__(...)
 |  
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  __next__(self, /)
 |      Implement next(self).
 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  close(self, /)
 |      Flush and close the IO object.
 |      
 |      This method has no effect if the file is already closed.
 |  
 |  detach(self, /)
 |      Separate the underlying buffer from the TextIOBase and return it.
 |      
 |      After the underlying buffer has been detached, the TextIO is in an
 |      unusable state.
 |  
 |  fileno(self, /)
 |      Returns underlying file descriptor if one exists.
 |      
 |      OSError is raised if the IO object does not use a file descriptor.
 |  
 |  flush(self, /)
 |      Flush write buffers, if applicable.
 |      
 |      This is not implemented for read-only and non-blocking streams.
 |  
 |  isatty(self, /)
 |      Return whether this is an 'interactive' stream.
 |      
 |      Return False if it can't be determined.
 |  
 |  read(self, size=-1, /)
 |      Read at most n characters from stream.
 |      
 |      Read from underlying buffer until we have n characters or we hit EOF.
 |      If n is negative or omitted, read until EOF.
 |  
 |  readable(self, /)
 |      Return whether object was opened for reading.
 |      
 |      If False, read() will raise OSError.
 |  
 |  readline(self, size=-1, /)
 |      Read until newline or EOF.
 |      
 |      Returns an empty string if EOF is hit immediately.
 |  
 |  seek(self, cookie, whence=0, /)
 |      Change stream position.
 |      
 |      Change the stream position to the given byte offset. The offset is
 |      interpreted relative to the position indicated by whence.  Values
 |      for whence are:
 |      
 |      * 0 -- start of stream (the default); offset should be zero or positive
 |      * 1 -- current stream position; offset may be negative
 |      * 2 -- end of stream; offset is usually negative
 |      
 |      Return the new absolute position.
 |  
 |  seekable(self, /)
 |      Return whether object supports random access.
 |      
 |      If False, seek(), tell() and truncate() will raise OSError.
 |      This method may need to do a test seek().
 |  
 |  tell(self, /)
 |      Return current stream position.
 |  
 |  truncate(self, pos=None, /)
 |      Truncate file to size bytes.
 |      
 |      File pointer is left unchanged.  Size defaults to the current IO
 |      position as reported by tell().  Returns the new size.
 |  
 |  writable(self, /)
 |      Return whether object was opened for writing.
 |      
 |      If False, write() will raise OSError.
 |  
 |  write(self, text, /)
 |      Write string to stream.
 |      Returns the number of characters written (which is always equal to
 |      the length of the string).
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  buffer
 |  
 |  closed
 |  
 |  encoding
 |      Encoding of the text stream.
 |      
 |      Subclasses should override.
 |  
 |  errors
 |      The error setting of the decoder or encoder.
 |      
 |      Subclasses should override.
 |  
 |  line_buffering
 |  
 |  name
 |  
 |  newlines
 |      Line endings translated so far.
 |      
 |      Only line endings translated during reading are considered.
 |      
 |      Subclasses should override.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from _IOBase:
 |  
 |  __del__(...)
 |  
 |  __enter__(...)
 |  
 |  __exit__(...)
 |  
 |  __iter__(self, /)
 |      Implement iter(self).
 |  
 |  readlines(self, hint=-1, /)
 |      Return a list of lines from the stream.
 |      
 |      hint can be specified to control the number of lines read: no more
 |      lines will be read if the total size (in bytes/characters) of all
 |      lines so far exceeds hint.
 |  
 |  writelines(self, lines, /)
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from _IOBase:
 |  
 |  __dict__

In [21]:
fp?
In [22]:
fp??
In [23]:
!ls
sample_table.csv  SRR7541452.6M.fastq.gz
In [24]:
text = open("sample_table.csv")
In [25]:
text.readline()
Out[25]:
'Run,desc,condition,mucor,batch,rep\n'
In [26]:
text.readline()
Out[26]:
'SRR7541435,"Mucor atf1 mutants cocultured with mouse macrophages (cell line J774A.1) for 5 hours, replicate b",mac,atf1,2,b\n'
In [27]:
text.seek(0)
Out[27]:
0
In [ ]: