Why are these two IMAP Search results different from one another? - email

I'm using imaplib, and trying to fetch emails with a certain subject header value.
My code:
res, tmp = self.mail.uid('search', None, 'HEADER Subject "SUBJECT_HERE"')
print(tmp)
print(res)
print("test 2 goes:")
rr, tt = self.mail.search(None, 'HEADER Subject "SUBJECT_HERE"')
print(tt)
print(rr)
Result:
[b'225 232 323 324 346 366 382 419 420 425 450 463 517 607 670 751 833
911 1043 1129 1133 1134 1287 1350 1799 1854 1957 1960 1962 1991 2005
2040 2071 2110 2119 2121 2153 2158 2182 2188 2189 2228 2230 2239 2249
2334 2335 2372 2378 2396 2435 2497 2567 2568 2573 2574 2575 2632 2633
2634 2648 2649 2709 2785 2819 2821 2828 2829 2868 2885 2895 2902 2906
2920 2993 2997 2998 3000 3001 3009'] OK test 2 goes:
[b'220 227 318 319 340 360 376 413 414 419 444 457 511 601 664 745 827
905 1037 1123 1127 1128 1281 1344 1793 1848 1951 1954 1956 1985 1999
2034 2065 2104 2113 2115 2147 2152 2176 2182 2183 2222 2224 2233 2243
2328 2329 2366 2372 2390 2429 2491 2561 2562 2567 2568 2569 2625 2626
2627 2641 2642 2702 2778 2812 2814 2821 2822 2861 2878 2888 2895 2899
2913 2986 2990 2991 2993 2994 3002'] OK
I thought that those two commands result in the same results.
But as shown above, those two fetch different emails.
What is the difference??

One (SEARCH) returns message sequence numbers (MSN), which are numbered from 1 to N and change as messages are added and deleted. A message that is number 5 now could be number 4 tomorrow if you delete a message before it.
The other (UID SEARCH) returns UIDs, which do not change as messages are deleted. They're two completely different set of identifiers. A message with UID 5 will remain UID 5 until it is deleted it (or moved, etc.).
The UID will never reused in that incarnation of a folder. If the folder is deleted and recreated, or the mail server is rebuilt, the folder's UIDVALIDITY should change so you can detect that your cache is no longer valid.

Related

GIMP get current image reference number to operate on current image

I have more than one image open, and I'd like to run scrip-fu functions on the currently selected image. How can I get the image reference number to the currently selected image so I can use the reference in other functions (e.g. (gimp-image-width 7))? I'm using GIMP 2.10.12.
Using (gimp-image-list) lists all the image references:
> (gimp-image-list)
(12 #(12 11 10 9 8 7 6 5 4 3 2 1))
I've been using (gimp-image-latest) for this, which should work for the general case
(define (gimp-image-list-items)
(cadr (gimp-image-list)))
(define (gimp-image-latest)
(aref (gimp-image-list-items) 0))
(define img (gimp-image-latest))
Then it's in img. E.g.:
> (gimp-image-get-layers img)
(283 #(770 769 768 767 766 765 764 763 762 761 760 759 758 757 756 755 754 753 752 751 750 749 748 747 746 745 744 743 742 741 740 739 738 737 736 735 734 733 732 731 730 729 728 727 726 725 724 723 722 721 720 719 718 717 716 715 714 713 712 711 710 709 708 707 706 705 704 703 702 701 700 699 698 697 696 695 694 693 692 691 690 689 688 687 686 685 684 683 682 681 680 679 678 677 676 675 674 673 672 671 670 669 668 667 666 665 664 663 662 661 660 659 658 657 656 655 654 653 652 651 650 649 648 647 646 645 644 643 642 641 640 639 638 637 636 635 634 633 632 631 630 629 628 627 626 625 624 623 622 621 620 619 618 617 616 615 614 613 612 611 610 609 608 607 606 605 604 603 602 601 600 599 598 597 596 595 594 593 592 591 590 589 588 587 586 585 584 583 582 581 580 579 578 577 576 575 574 573 572 571 570 569 568 567 566 565 564 563 562 561 560 559 558 557 556 555 554 553 552 551 550 549 548 547 546 545 544 543 542 541 540 539 538 537 536 535 534 533 532 531 530 529 528 527 526 525 524 523 522 521 520 519 518 517 516 515 514 513 512 511 510 509 508 507 506 505 504 503 502 501 500 499 498 497 496 495 494 493 492 491 490 489 488))

RMarkdown: Creating two side-by-side heatmaps with full figure borders using the pheatmap package

I am writing my first report in RMarkdown and struggling with specific figure alignments.
I have some data that I am manipulating into a format friendly for the package pheatmap such that it produces heatmap HTML output. The code that produces one of these looks like:
cleaned_mayo<- cleaned_mayo[which(cleaned_mayo$Source=="MayoBrainBank_Dickson"),]
# Segregate data
ad<- cleaned_mayo[which(cleaned_mayo$Diagnosis== "AD"),-c(1:13)]
control<- cleaned_mayo[which(cleaned_mayo$Diagnosis== "Control"),-c(1:13)]
# Average data across patients and assign diagnoses
ad<- as.data.frame(t(apply(ad,2, mean)))
control<- as.data.frame(t(apply(control,2, mean)))
ad$Diagnosis<- "AD"
control$Diagnosis<- "Control"
# Combine
avg_heat<- rbind(ad, control)
# Rearrange columns
avg_heat<- avg_heat[,c(32, 1:31)]
# Mean shift all expression values
avg_heat[,2:32]<- apply(avg_heat[,2:32], 2, function(x){x-mean(x)})
#################################
# CREATE HEAT MAP
#################################
# Plot average heat map
pheatmap(t(avg_heat[,2:32]), cluster_col= F, labels_col= c("AD", "Control"),gaps_col = c(1), labels_row = colnames(avg_heat)[2:32],
main= "Mayo Differential Expression for Genes of Interest: Averaged Across \n Patients within a Diagnosis",
show_colnames = T)
Where the numeric columns of cleaned_mayo look like:
C1QA C1QC C1QB LAPTM5 CTSS FCER1G PLEK CSF1R CD74 LY86 AIF1 FGD2 TREM2 PTK2B LYN UNC93B1 CTSC NCKAP1L TMEM119 ALOX5AP LCP1
1924_TCX 1101 1392 1687 1380 380 279 198 1889 6286 127 252 771 338 5795 409 494 337 352 476 170 441
1926_TCX 881 770 950 1064 239 130 132 1241 3188 76 137 434 212 5634 327 419 292 217 464 124 373
1935_TCX 3636 4106 5196 5206 1226 583 476 5588 27650 384 1139 1086 756 14219 1269 869 868 1378 1270 428 1216
1925_TCX 3050 4392 5357 3585 788 472 350 4662 11811 340 865 1051 468 13446 638 420 1047 850 756 616 1008
1963_TCX 3169 2874 4182 2737 828 551 208 2560 10103 204 719 585 499 9158 546 335 598 593 606 418 707
7098_TCX 1354 1803 2369 2134 634 354 245 1829 8322 227 593 371 411 10637 504 294 750 458 367 490 779
ITGAM LPCAT2 LGALS9 GRN MAN2B1 TYROBP CD37 LAIR1 CTSZ CYTH4
1924_TCX 376 649 699 1605 618 392 328 628 1774 484
1926_TCX 225 381 473 1444 597 242 290 321 1110 303
1935_TCX 737 1887 998 2563 856 949 713 1060 2670 569
1925_TCX 634 1323 575 1661 594 562 421 1197 1796 595
1963_TCX 508 696 429 1030 355 556 365 585 1591 360
7098_TCX 418 1011 318 1574 354 353 179 471 1471 321
All of this code is wrapped around the following header in the RMarkdown environment: {r heatmaps, echo=FALSE, results="asis", message=FALSE}.
What I would like to achieve is the two heatmaps side-by-side with black boxes around each individual heat map (i.e. containing the title and legend of the heatmap as well).
If anyone could tell me how to do this, or either one individually it would be greatly appreciated.
Thanks!

Connecting points in qqplot in MATLAB

I am trying to plot a qqplot graph for different data samples. I am able to draw it for individual data samples. How can I draw a qqplot graph for multiple data samples? Also, I want to connect all the points with a line and color for each data set to differentiate them. How can I achieve this in MATLAB?
I am getting the output as below:
I am trying to get the output in the below format(qqlplot for 4 samples).
I am loading the data from csv file into matlab.
Next, drawing the graph using the function qqplot(1mb);
Data Set1:(variable size: 1mb)
379
398
474
541
656
673
684
712
749
751
770
782
788
829
837
864
886
919
935
946
991
993
995
1000
DataSet2: (variable size: 512kb)
313
406
443
534
558
561
613
645
649
699
705
732
737
748
752
755
766
774
780
795
796
802
806
823
842
846
872
873
889
904
915
936
966
983
993

Saving text matrix in a directory: MATLAB

I have a matrix, say A =
11084 2009 572 277 1095 685 636 365 545 697 518 490 747 1648;
11084 2010 1000 533 340 212 635 254 399 759 110 248 490 214;
11084 2011 587 410 481 146 99 499 547 118 706 20 174 526;
12813 2009 216 486 1443 207 730 369 518 625 816 767 382 1352;
12813 2010 673 544 517 204 704 504 219 1033 633 168 473 272;
12813 2011 348 238 458 107 90 394 1014 196 1109 34 365 250;
The column 1 indicates Station ID, I want to save the output in a separate directory in the name of station ID; such as in this case a text file will be created named 11084.txt which will contain foll. data:
2009 572;2009 277;2009 1095;2009 685;2009 636;2009 365;2009 545;2009 697;2009 518;2009 490;2009 747;2009 1648;2010 1000;2010 533;2010 340;2010 212;2010 635;2010 254;2010 399;2010 759;2010 110;2010 248;2010 490;2010 214;2011 587;2011 410;2011 481;2011 146;2011 99;2011 499;2011 547;2011 118;2011 706;2011 20;2011 174;2011 526;
similarly, next 12813.txt which will contain
2009 216;2009 486;2009 1443;2009 207;2009 730;2009 369;2009 18;2009 625;2009 816;2009 767;2009 382;2009 1352;2010 673;2010 44;2010 517;2010 204;2010 704;2010 504;2010 219;2010 1033;2010 633;2010 168;2010 473;2010 272;2011 348;2011 238;2011 458;2011 107;2011 90;2011 394;2011 1014;2011 196;2011 1109;2011 34;2011 365;
2011 250;
Please let me know how to do so. Thanks,
A straight forward solution is just:
d = unique(A(:,1));
for i = 1:length(d)
fid = fopen([num2str(d(i)) '.txt'],'w');
aux = find(A(:,1)==d(i))';
for j = aux
for k = 3:size(A,2)
fprintf(fid,'%d %d;', A(j,2), A(j,k));
end
end
fclose(fid);
end

Multidimensional scaling matrix error

I'm trying to use multidimensional scaling in Matlab. The goal is to convert a similarity matrix to scatter plot (in order to use k-means).
I've got the following test set:
London Stockholm Lisboa Madrid Paris Amsterdam Berlin Prague Rome Dublin
0 569 667 530 141 140 357 396 570 190
569 0 1212 1043 617 446 325 423 787 648
667 1212 0 201 596 768 923 882 714 714
530 1043 201 0 431 608 740 690 516 622
141 617 596 431 0 177 340 337 436 320
140 446 768 608 177 0 218 272 519 302
357 325 923 740 340 218 0 114 472 514
396 423 882 690 337 272 114 0 364 573
569 787 714 516 436 519 472 364 0 755
190 648 714 622 320 302 514 573 755 0
I got this dataset from the book Modern Multidimensional Scaling (Borg & Groenen, 2005). Tested it in SPSS using the PROXSCAL MDS method and I get the same result as stated in the book.
But I need to use MDS in Matlab in order to speed up the process. The tutorial on the site: http://www.mathworks.nl/help/stats/multidimensional-scaling.html#briu08r-4 looks the same as what I'm using above. When I change the data set as what is displayed above and run the code I get the following error: "Not a valid dissimilarity or distance matrix.".
I'm not sure what I'm doing wrong, and if classical MDS is the right choice. I also miss the possibility to say that I want the result in three dimensions (this will be needed in a later stage).
Your matrix is not symetric, check the indices (9,1) and (1,9). To quickly find asymetric indices use [x,y]=find(~(D'==D))