Using Python In Bioinformatics
Feel free to interrupt & ask during the session.
General purpose, high-level programming language.
>>> 2 2 >>> 2 + 2 4 >>> name = 'anand' >>> name 'anand' >>> print(name) anand
>>> 21 / 5 4 >>> 21 / 5.0 4.2 >>> 2 * 3 6 >>> 2 ** 3 8 >>> 2 + 3 * 2 8 >>> (2 + 3) * 2 10
>>> 'dna' 'dna' >>> "dna" 'dna' >>> """ ... long ... dna ... seq ... """ '\nlong \ndna\nseq\n'
>>> sequence = 'actgaaattaaa' >>> sequence.upper() 'ACTGAAATTAAA' >>> sequence.count('a') 7 >>> sequence.replace('a', 'c') 'cctgcccttccc' >>> len(sequence) 12
>>> sequence.find('aaa') 4 >>> sequence[3] 'g' >>> sequence[3:5] 'ga' >>> sequence[-1] 'a' >>> sequence[-3:-2] 'a'
>>> seq1 = 'atc' >>> seq2 = 'atc' >>> seq1 == seq2 True >>> if seq1 == seq2: ... print('both are equal') ... both are equal
>>> data = ['homosapiens', 2015, 03, 'life exists'] >>> data[0] 'homosapiens' >>> len(data) 4 >>> data[-1] 'life exists' >>> print(data) ['homosapiens', 2015, 3, 'life exists'] >>> more_data = [data, 'valid data'] >>> print(more_data) [['homosapiens', 2015, 3, 'life exists'], 'valid data']
for loop can be used against anything which is iterable
>>> for i in "bioinformatics": ... print(i) >>> for i in ['sequence', 12, 'ggta', 'actgc']: ... print(i) ... sequence 12 ggta actgc
Open the sequence file.
Loop over the file to read.
Close the file.
>>> f = open('sample.fasta') >>> for line in f: ... print(line) >>> f.close()
Open a fasta file & count nucleotides.
http://learnpythonthehardway.org/
Bioinformatics Programming By Mitchell L Model