import pysam
# Read in a BAM file
bamfile = pysam.AlignmentFile("outputFile.bam","rb")
for line in bamfile:
print(line)
# Read in a SAM file
samfile = pysam.AlignmentFile("outputFile.sam","r")
for line in samfile:
print(line)
#Read in a CRAM file.
CRAMfile = pysam.AlignmentFile("outputfile.cram", "rc")
#Create the iterable and print the first line
it = iter(bamfile)
print(next(it))
#itt = iter(samfile)
print(next(itt))
# A different way to open the mpileup file.
f = open("/Users/m.o.l.s/outputFile.mpileup","rt")
line_1 = f.readline()
print(line_1)
# Split up the strings based on tabs
individuals = line_1.split("\t")
print(individuals)
# The value we are interested in is in the 3rd index position
The_Coverage = individuals[3]
print(The_Coverage)
# If this number is less than 10, the row needs to be displayed
if The_Coverage <= "10":
print(The_Coverage)
else:
print("The Coverage is not less than or equal to 10")
FYI, it's considered good practice to close file handles when not needed anymore. It's not important in your code above, but just in case you plan getting serious with this
import pysam
samfile = pysam.AlignmentFile("ex1.bam", "rb")
for read in samfile.fetch('chr1', 100, 120):
print read
samfile.close() # note the close operation
that's not clear. Explain what you're doing. Show us the code.